Page 1 of 1

Cant get my code to work? Can someone please help.

Posted: Sat Sep 26, 2009 8:40 am
by JDDD92
This code is for a online shop to display all products in a database, iv doen it before but lost the code so iv had to do it again, i just can not remember how i did it. The image, description and price will not show? The url and description and price are all in a mysql database. Would be ace if someone helped me out.

Code: Select all

<?php
mysql_connect("localhost", "********", "******") or die(mysql_error());
mysql_select_db("buttons1_chipboard") or die(mysql_error());
 
$query = "SELECT * FROM chipboard";
$result = mysql_query($query) or die(mysql_error());
    
    while($row = mysql_fetch_array($result)) { 
 
            
echo "      <table> \n"; 
echo "              <tr>\n"; 
echo "                  <td>\n"; 
echo "                  <img src=\"$row ['img']\" width=\"350px\" />\n"; 
echo "                  <br />\n"; 
echo "                  $row ['desc']\n"; 
echo "                  </td>\n"; 
echo "              </tr>\n"; 
echo "          </table>\n"; 
echo "          <table>\n"; 
echo "              <tr>\n"; 
echo "                  <td>\n"; 
echo "                  $row ['price']\n"; 
echo "                  </td>\n"; 
echo "                  <td>\n"; 
echo "                  buy now.\n"; 
echo "                  </td>\n"; 
echo "              </tr>\n"; 
echo "          </table>\n"; 
echo "          \n";
            
 
    }
 
?>
 

thanks

Re: Cant get my code to work? Can someone please help.

Posted: Sat Sep 26, 2009 9:25 am
by JDDD92
someone?

Re: Cant get my code to work? Can someone please help.

Posted: Sat Sep 26, 2009 12:38 pm
by Mirge
Inside the loop, put in a print_r($row) to see what the array contains.

BTW, you shouldn't bump your thread for at least 24 hours after posting it.

Re: Cant get my code to work? Can someone please help.

Posted: Sat Sep 26, 2009 2:47 pm
by Ollie Saunders
Remove the space between the variable name and array subscript. Then wrap both parts with braces. So

Code: Select all

$row ['desc']
becomes:

Code: Select all

{$row['desc']}