-1

The below code included in php file and gets data from data base

$sqlUrl = "SELECT *
            FROM $category
            WHERE sub_category = '$subCategory'";

$result = mysqli_query($con,$sqlUrl);

now I need to display those data on the screen and thus I would like to load them on am html file in a specific division

<div id="div6">


</div>

I think that I can do it using JScript but I don't know how to do it

4
  • 1
    add this <?php print_r($result); ?> inside your <div> Commented Jan 17, 2014 at 9:06
  • @Tun Zarni Kyaw This works for testing reasons. But you cant format it properly, so its not the best idea if you want to show it to users. Commented Jan 17, 2014 at 9:08
  • Don't just inject variables into your SQL - if you don't escape them you're opening up for some SERIOUS SQL injection. Use prepared statements and bind variables. Commented Jan 17, 2014 at 9:12
  • yes, i agree @YUNOWORK, at least OP can get the idea. that's why i didn't write it as answer Commented Jan 17, 2014 at 9:13

2 Answers 2

1

What the ... If you just want to print it, you dont need JavaScript:

<div id="div6">
    <?php foreach($result as $r) {
      echo $r;  
    } ?>
</div>
Sign up to request clarification or add additional context in comments.

4 Comments

Actually is a phpBB board and I have tried to write php code inside the html file but it doesn't permit me. That's the reason I am trying to write JScript.
You know that the file still has to be named as file.php in order to actually write PHP into it right?
Yes I know, I have already tried it but it creates trouble to other files on the phpBB board...
Bad phpBB board then. Every normal board is able to do that. Honestly, i have no idea how you want to create dynamic input depending on the output of your database if you cant combine .php and .html
0

why you want to display results with JScript? You can do it like this also:

<div id="div6">
 <?php
   while ($row = mysqli_fetch_assoc($result)) {
    echo $row["Name"]."<br />";
  }
?>

</div>

for more details Plese refer: https://www.php.net/mysqli_fetch_assoc

2 Comments

did you forget <?php ?> tag or doesn't need <?php ?> tag?
Actually is a phpBB board and I have tried to write php code inside the html file but it doesn't permit me. That's the reason I am trying to write JScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.