Jump to content

SQL SELECT AND HTML TABLE, HELP!


patheticsam

Recommended Posts

Hi,

 

I'm a little bit new to php and I'm having some issues selecting some data from a mySQL database and fetching it into a fluid html table.....

 

 

Basicly what I want is a table with 4 columns and a X number of rows depending on how much entry is stored in the DB.

 

Here's the SELECT code :

 

<?php 

mysql_connect("host", "user", "pass") or die(mysql_error()); 
mysql_select_db("DB") or die(mysql_error()); 

$id = $_GET['id'];

$data = mysql_query("SELECT * FROM artist_gallery WHERE artist_picid='$id'") 
or die(mysql_error());

while($info = mysql_fetch_array( $data ))

     {

 

Here the part I just can't figure.... what I want is to fetch the x number of picture in the DB into a html table :

 

echo "
<table border=\"1\" cellpadding=\"1\" cellspacing=\"0\">
<tr>
<td><img src=\"".$info['picture']."\" border=\"0\" /></td>
<td><img src=\"".$info['picture']."\" border=\"0\" /></td>
<td><img src=\"".$info['picture']."\" border=\"0\" /></td>
</tr>
</table>
    ";
    }

?> 

 

The pictures are just repeating 3 times at each row...

 

Any help will be greatly appreciated!!!

 

 

Thanks!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/226397-sql-select-and-html-table-help/
Share on other sites

I think I see what's going on here. You'll want to break your html output up just a little bit.

 

This should be before your loop:

echo "<table border=\"1\" cellpadding=\"1\" cellspacing=\"0\">";

 

This should be in your loop.

echo "<tr><td><img src=\"".$info['picture']."\" border=\"0\" /></td></tr>";

 

This should be after your loop.

echo "</table>";

 

Otherwise it will display the same image three times for each row in the database. Make sense?

I can figure out how to make the loop, but the problem is I would have wanted a table with 3 colums and 1 different picture in each column....repeated on a couple of rows depending on the quantity of entries in the DB...

 

I think I have to make a loop and array the results with php or something like that..... but I can't find out how to do it or any tutorials that explains how.......

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.