ginter
ginter

Reputation: 45

JScript within php

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

Upvotes: -1

Views: 59

Answers (2)

user2936213
user2936213

Reputation: 1011

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

Upvotes: 0

Realit&#228;tsverlust
Realit&#228;tsverlust

Reputation: 3953

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

<div id="div6">
    <?php foreach($result as $r) {
      echo $r;  
    } ?>
</div>

Upvotes: 1

Related Questions