I am creating a website that is going to allow customer's to view photography on the site and purchase it when selected for download. I have created all the php and mysql to be able to display the data correctly. But... to display the search results or recordset, how do I make it where the display is say maybe four or five records per row on a page.


For an example: I will have on the first row the first five records (displayed as images) with each image containing the option to view details (detail page) and the title of the image as well as the photographer who took it, and the genre. How do I DISPLAY the records in this manner? I have done a dynamic table, but it's not the type of format I am looking for.

Member Avatar for diafol

I assume the search matches keywords from the rows in the DB:

**this isn't tested and it could be tidied up considerably, but it gives you an idea...

$pics_per_row = 5;
$x = 1;
$output = "";
$total = mysql_num_rows($rs);
while($data = mysql_fetch_array($rs)){
  $rem = $x%$pics_per_row; 
  if($rem == $pics_per_row-1)$output .= "<tr>";
  $output .= "<td><img src=\"{$data['pic_url']}\" alt=\"{$data['pic_alt']}\" /></td>";
  if($x==$total && $rem != 0)$output .= "<td colspan=\"$rem\"></td>";
  if($rem == 0)$output .= "</tr>";
  $x++;
}

//EDIT

just read the second part of your post again. Darn. You could place all the data for a pic in one <td>

1.
$pics_per_row = 5;
2.
$x = 1;
3.
$output = "";
4.
$total = mysql_num_rows($rs);
5.
while($data = mysql_fetch_array($rs)){
6.
$rem = $x%$pics_per_row;
7.
if($rem == $pics_per_row-1)$output .= "<tr>";
8.
$output .= "<td><img src=\"{$data}\" alt=\"{$data}\" /></td>";
9.
if($x==$total && $rem != 0)$output .= "<td colspan=\"$rem\"></td>";
10.
if($rem == 0)$output .= "</tr>";
11.
$x++;
12.
}

I hope I understand you correctly, but it sounds like you need the "LIMIT" MySQL function. Example:

By using

"SELECT * FROM database LIMIT 5"

The resultset is only 5 records big.

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.