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
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?

Link to comment
Share on other sites

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.......

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.