I have been working on this for a while now and sorted the whole back end out, i’m just struggling with the mySQL database as this is the first time i’ve used one in a project!
I’m trying to recall some information from a database but from 2 different tables and display it in a loop.
I’m currently getting a T_VARIABLE error whilst trying to recall the information in a loop.
<p><?php
$inttotalcredits=0;
$result = mysql_query("SELECT * FROM site_products");
$set = mysql_fetch_array($result)
$prod_id = $row[0]
echo "<table border='0' width='100%'>
<tr>
<th>Product ID</th>
<th>Part Name</th>
<th>Part Number</th>
<th>Description</th>
<th>Level</th>
</tr>";
while($row = mysql_fetch_array($result)
{
echo "<tr>";
echo "<td>" . "<center> $row[0] </center>" . "</td>";
echo "<td>" . "<center> $row[1] </center>" . "</td>";
echo "<td>" . "<center> $row[2] </center>" . "</td>";
echo "<td>" . "<center> $row[4] </center>" . "</td>";
}
$result1 = mysql_query("SELECT * FROM site_trans WHERE trans_product = $prod_id");
while($row1 = mysql_fetch_array($result1))
{
echo "<td>" . "<center> $row1[6] </center>" . "</td>";
$inttotalcredits += $row1[6];
echo "</tr>";
echo "</center>";
}
echo "<td>" . "" . "</td>";
echo "<td>" . "" . "</td>";
echo "<td>" . "<b>Total Stock Items</b>" . "</td>";
echo "<td>" . "<b><center> $inttotalcredits </center></b>" . "</td>";
echo "</table>";
?></p>
I dont know if this is a straight forward mistake im making or im just not constructing the loop right.
Oliver
Your missing
;here:Should be:
Also as pointed by Lyth you are missing parethesis in while statement:
Should be:
I suggest also to rewrite your code, to not echo HTML elements in PHP code:
and so on… It’s much cleaner and easier to debug.