Jump to content

Inserting search results into rows


e1seix

Recommended Posts

inquired on another forum about showing search results from mysql in rows, for example: the first 4 results on one row, the next four on the one after etc. etc. to a maximum of 16 before the user has to move on to the "next page to display any remaining results. i was given this code:

 

<table>

<?php

  $rowwidth = 4;

 

  for($i = @$_GET['start'] or 0; $row = mysql_fetch_array($rs) && $i < @$_GET['num'] or 16; ++$i) {

    if($i % $rowwidth === 0) {

      if($i !== @$_GET['start'] or 0) {

?>

  </tr>

      <?php } ?>

  <tr>

    <?php } ?>

    <td><?php echo $row['result']; ?></td>

  <?php } ?>

  </tr>

</table>

 

i need to morph this code into my template already. can anyone help? lol

 

 

<td>

 

$ID = $_GET['ID'];

 

$result = mysql_query("SELECT * FROM fragrances WHERE ID=$ID ORDER BY PRO")

or die(mysql_error());

 

echo "<table border='0' cellpadding='5' cellspacing='0' width='500'>";

while($row = mysql_fetch_array( $result )) {

// Print out the contents of each row into a table

echo "<tr><td align='center' bgcolor='#ffffff' width='125'><p class='brand_div'>";

echo $row['ima_link'];

echo "</p></td></tr><tr><td align='center' bgcolor='#ffffff' width='125'><p class='brand_head'>";

echo $row['PRO'];

echo "</p></td></tr><tr><td align='center' bgcolor='#ffffff' width='125'><p class='brand_cli'>";

echo $row['cli_link'];

echo "</p></td></tr><tr><td align='center' bgcolor='#ffffff' width='500'><hr color='#cccccc' width='125'></td></tr>";

}

 

echo "</table>";

?>

 

</td>

 

thank you in advance!!

Link to comment
https://forums.phpfreaks.com/topic/61273-inserting-search-results-into-rows/
Share on other sites

There's a post here on the first part of your problem:

http://www.phpfreaks.com/forums/index.php/topic,95426.0.html

 

That is to help you get your results in 4 columns. The second part of your question, where you say you want to have multiple pages, is called pagination. There are two tutorials on this site for pagination:

 

http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php

 

I think thats what you need.

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.