I wrote query and fetched all the rows now I want to store some of the columns in variables so I could use them in list but it doesn't work. Here is my php code.
There are 20 rows so there should be 20 rows in table! But I think I am missing some points here
<?php
$servername = "localhost";
$username = "Bat";
$password = "IamTheBat";
$database = "SpecsCompare";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->mysqli_connect_error) {
die("Connection failed: " . $conn->mysqli_connect_error);
}
echo "Connected successfully";
$query_test = "
SELECT *
FROM prices p
, items i
, shops s
, categories c
WHERE p.shopid = s.shopid
AND i.categoryid = c.categoryid
AND p.itemid = i.itemid
AND i.categoryid = 1004
AND s.shopid = 5005
";
$result = mysqli_query($conn, $query_test);
$rows = mysqli_fetch_all($result, MYSQLI_BOTH);
$name = $row['itemname'];
$price = $row['price'];
$category = $row['categoryname'];
$shop = $row['shopname'];
$manufacturer = = $row['manufacturername'];
$module = $row['modulename'];
$type = $row['typename'];
/*while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
echo "<br>";
echo $row['itemname'];
}*/
?>
And my table in HTML is as below..
<section class="list">
<div id="galaxyTable">
<table class="table table-hover table-condensed">
<thead>
<tr>
<td>Name</td>
<td>Price</td>
</tr>
</thead>
<tbody>
<tr>
<td><td><?php echo $name ?></td></td>
<td><td><?php echo $price ?></td></td>
<td><a href="#" class="button">Details</a></td>
</tr>
<?php } ?>
</tbody>
</table>
<div id="galaxydetailedTable" class="hidden">
<table class="table table-hover table-condensed">
<thead>
<tr>
<td>Name</td>
<td>Category</td>
<td>Price</td>
<td>Shop</td>
<td>Manufacturer</td>
<td>Module</td>
<td>Type</td>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $name ?></td>
<td><?php echo $category ?></td>
<td><?php echo $price ?></td>
<td><?php echo $shop ?></td>
<td><?php echo $manufacturer ?></td>
<td><?php echo $module ?></td>
<td><?php echo $type ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
you have a typo here you should change this
$rows = mysqli_fetch_all($result, MYSQLI_BOTH);
into this
$row = mysqli_fetch_all($result, MYSQLI_BOTH);
plus you don't need to assign all of those variables you can simply use Extract
and it will change assign the key name into a variable with the value
from the manual
extract — Import variables into the current symbol table from an array