mpsn Posted May 22, 2011 Share Posted May 22, 2011 Hi, here's my problem: I am trying to make a simple online buying website and I want to display a table with all the fields for each item. So I got that part down which is to just use mysql_fetch_assoc("SELECT * FROM myTable") and use the html table tags stuff, but now I want to display my images in the table, so here's my code to display my mysql database table in html's table tag along w/ php: <html> <head> <title>My Online buying website project</title> </head> <body> <?php mysql_connect("localhost","root"); mysql_select_db("myTable"); $imagesArray=array("Apple_iPhone3GS.jpg","Apple_iPhone4.jpg","product3.jpg","product4.jpg","product5.jpg"); $result=mysql_query("SELECT Name, Manufacturer, Price, Description, SimSupport FROM myTable"); if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { print "<table border='border'>"; print "<tr> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>SimSupport</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result)) { extract($row); print "<tr> <td>$Name</td> <td>$Manufacturer</td> <td>$Price</td> <td>$Description</td><td>$SimSupport</td> </tr>"; }//END WHILE }//END IF ?> </table> </body> </html> *So how do I go about adding my images in this table? Link to comment https://forums.phpfreaks.com/topic/237141-how-to-display-my-images-along-with-mysql-database-table/ Share on other sites More sharing options...
rdkd1970 Posted May 22, 2011 Share Posted May 22, 2011 $sql = mysql_query("SELECT [i]things you are trying to query[/i], FROM [i]Your table[/i] WHERE [i]array='array'[/i] ORDER BY id looking_for ASC"); {/PHP] replace where needed for you to complete your query (id, username,firstname[i]this should be replaced with the items you are querying[/i] then put in your table, finally your where should be equal to your array ORDER by ASC) Link to comment https://forums.phpfreaks.com/topic/237141-how-to-display-my-images-along-with-mysql-database-table/#findComment-1218820 Share on other sites More sharing options...
mpsn Posted May 23, 2011 Author Share Posted May 23, 2011 Thanks for replying and this is what I added but I'm still stuck: <table border="border"> <?php mysql_connect("localhost","root"); mysql_select_db("bell"); $bellProductsArray=array("Apple_iPhone3GS.jpg","Apple_iPhone4.jpg", "BB_Bold9780.jpg", "BB_Curve3G.jpg", "BB_PlayBook.jpg","BB_Torch9800.jpg","BB_Pearl3G.jpg","EricssonW35TurboHub.jpg","HTC_DesireZ.jpg", "HTC_HD7.jpg","HTC_IncredibleS.jpg","LG_OptimusChic.jpg","LG_OptimusQUantum.jpg", "LG_RumourPlus.jpg","Mot_Atrix.jpg","Mot_M800.jpg","Nokia_2730.jpg","Nokia_C6_01.jpg". "Palm_Pre.jpg","Samsung_Galaxy551.jpg","Samsung_GalaxyTab.jpg","Samsung_Rugby2.jpg", "Samsung_Entro.jpg","Sanyo_PRO700.jpg","Novatel_MiFi2372.jpg","Novatel_U547.jpg", "MicroSimCard.jpg","SimCard.jpg","ReceiverBasic.jpg","ReceiverHD.jpg","ReceiverHDPVR.jpg"); $result=mysql_query("SELECT Name, Manufacturer, Price, Description, SimSupport FROM bellProducts WHERE array=$bellProductsArray"); $indx=0; //NB: print table headings if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { print "<table border='border'>"; print "<tr> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>SimSupport</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result)) { extract($row); print "<tr> <td><img src='$bellProductsArray[$indx]' /></td>//***NEW CODE ADDED <td>$Name</td> <td>$Manufacturer</td> <td>$Price</td> <td>$Description</td> <td>$SimSupport</td> </tr>"; $indx++; //***NEW CODE ADDED }//END WHILE }//END BIG IF ?> </table> </body> </html> **plz help, thx Link to comment https://forums.phpfreaks.com/topic/237141-how-to-display-my-images-along-with-mysql-database-table/#findComment-1219260 Share on other sites More sharing options...
mpsn Posted May 23, 2011 Author Share Posted May 23, 2011 Hey, I got it to work, maybe my wording was unclear, but I didn't have to use the WHERE array=$myArray, but thx tho. Link to comment https://forums.phpfreaks.com/topic/237141-how-to-display-my-images-along-with-mysql-database-table/#findComment-1219264 Share on other sites More sharing options...
mpsn Posted May 23, 2011 Author Share Posted May 23, 2011 ***I thought I had it working w/o using the WHERE array="$bellProductsArray", so i still need help!!! :'( Link to comment https://forums.phpfreaks.com/topic/237141-how-to-display-my-images-along-with-mysql-database-table/#findComment-1219266 Share on other sites More sharing options...
mpsn Posted May 23, 2011 Author Share Posted May 23, 2011 **No, i got it, it's b/c I forgot to add an extra heading (eg: <th>images</th>) and I didn't have to use WHERE array=$bellProductsArray, thx tho! Link to comment https://forums.phpfreaks.com/topic/237141-how-to-display-my-images-along-with-mysql-database-table/#findComment-1219284 Share on other sites More sharing options...
rdkd1970 Posted May 23, 2011 Share Posted May 23, 2011 Okay you are good got it working. Great. Link to comment https://forums.phpfreaks.com/topic/237141-how-to-display-my-images-along-with-mysql-database-table/#findComment-1219299 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.