Jump to content

[SOLVED] Need With Splitting Query Results Into Table


Recommended Posts

I want to retrieve all the web addresses of the pictures and post the pictures in rows of 3.  I know how to retrieve the results.  I just don't know how to span it over the different table cells.  Also, under each photo, I need to insert a link.  Here's what I have so far:

 

$sql = mysql_query("SELECT * FROM owners_skins WHERE sid = '$sid'")or die(mysql_error());
while ($row = mysql_fetch_assoc($sql)){
$pix = $row['location'];
$pid = $row['pid'];
Echo'<TABLE width="80%" border="4">
<TR>
<TD align="center"><img src=' . $pix . ' border="0"></BR><A HREF="preview.php?pid=' . $pid . '">Preview</A></BR></TD>
<TD align="center"><img src=' . $pix . ' border="0"></BR><A HREF="preview.php?pid=' . $pid . '">Preview</A></BR></TD>
<TD align="center"><img src=' . $pix . ' border="0"></BR><A HREF="preview.php?pid=' . $pid . '">Preview</A></BR></TD>
</TR>';
}

 

Right now, only the first record shows up in all 3 table cells.

First, I will warn you that there are many people on this forum that will give you grief for using tables for non-tabular data.

 

With that out of the way, it mostly looks ok to me, besides the fact that you don't have a table close tag, but that wouldn't make it not work. You really should put your src in quotes, and your line break tags

<br>

shouldn't have slashes at the beginning. That would make it look kinda weird. Fix those things and refresh it.

echo '<TABLE width="80%" border="4">';
$sql = mysql_query("SELECT * FROM owners_skins WHERE sid = '$sid'")or die(mysql_error());
while ($row = mysql_fetch_assoc($sql)){
$pix = $row['location'];
$pid = $row['pid'];
echo '<TR>
<TD align="center"><img src=' . $pix . ' border="0"></BR><A HREF="preview.php?pid=' . $pid . '">Preview</A></TD>
</TR>';
}\
echo '</table>';

 

You only need one table echo in a while loop........

Thanks for the help so far guys...

 

Dezkit,

I don't need them to show up one row at a time.  I need the pictures to show up 3 to a row.  That only produces one. And it's still the same record everytime.

 

F1Fan,

Is there another way to get 3 images per row?  The only way I could think of was a table.  I'm open to all suggestions.  Page just started about 50 lines ago.  Can scrap it and start from scratch if necessary.  Easier to do it now then later.  Thanks again for the input guys

As far as the 3 per line, you'll have to do some counting. Here's a very simple example:

 

<?php
$count = 0;
echo '<table><tr>';
while (whatever){
  if ($count==3){
    echo '</tr><tr>';
    $count = 0;
  }
  echo '<td>Blah...</td>';
  $count++;
}
// this next part just closes up the table if there aren't three cells in the last row
while ($count<3){
  echo '<td> </td>';
  $count++;
}
echo '</tr></table>';
?>

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.