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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JDDD92
Forum Newbie
Posts: 2
Joined: Sat Sep 26, 2009 8:35 am

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

Post 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
JDDD92
Forum Newbie
Posts: 2
Joined: Sat Sep 26, 2009 8:35 am

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

Post by JDDD92 »

someone?
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

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

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

Post 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']}
Post Reply