For the Life of Me I can't Make this work
Posted: Tue Sep 24, 2002 6:30 pm
I'm querying a table of products and listing them by title and price. The title is an HTML link to a page called "title.php" and a variable (x) is set equal to the product id ($id) and passed in the URL (title.php?x=$id).
Here's the code that works:
The title.php page is supposed to display info about the product.
When I click on the title it takes me to "title.php?x=1" (its the only test data I have in the table so far) but this code doesn't work in title.php:
"title.php?x=1" appears in the address bar, as expected, but the info from the table does not display.
Any help would be appreciated. I'm stumped.
Here's the code that works:
Code: Select all
$sql="SELECT * FROM products ORDER BY title ASC";
$result = @mysql_query($sql);
$num = @mysql_num_rows($result);
$i=0;
echo "<table><tr bgcolor="black"><td width="400"><b><font color="white">Title</font></b></td><td width="25"><b><font color="white">Price</font></b></td><td><b><font color="white">Add to Cart</font></b></td></tr>";
while($num > $i)
{
$id = @mysql_result($result,$i,"id");
$title = @mysql_result($result,$i,"title");
$cost = @mysql_result($result,$i,"cost");
$price = $cost * 1.2;
$price = number_format($price, 2, '.', '');
if($i % 2)
{
echo "<tr bgcolor="#757575"><td width="400" height="20"><a href="title.php?x=$pid">$title</a></td><td width="25" height="20">$price</td><td height="20">";When I click on the title it takes me to "title.php?x=1" (its the only test data I have in the table so far) but this code doesn't work in title.php:
Code: Select all
$x = $_GETї'x'];
$sql="SELECT * FROM products WHERE id = $x";
$result = @mysql_query($sql);
$title = @mysql_result($result,$prod,"title");
$cost = @mysql_result($result,$prod,"cost");
$price = $cost * 1.2;
$price = number_format($price, 2, '.', '');
$developer = @mysql_result($result,$prod,"developer");
$description = @mysql_result($result,$prod,"description");
$rating = @mysql_result($result,$prod,"rating");
echo "<table border="1">";
echo "<tr><td colspan="3">";
echo "<h3>Title: $title</h3>";
echo "</td>";
echo "<td><img src="$x.jpg"></td>";
echo "<td><table><tr><td>$price</td></tr><tr><td><img src="theme/addtocart.gif"></td></tr></table></td>";
echo "<td><img src="$rating.gif"></td>";
echo "</tr><tr>";
echo "<td colspan="3">$description</td>";
echo "</tr></table>";Any help would be appreciated. I'm stumped.