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
Share on other sites

i don't suppose anyone maybe has an easier way of doing this, not necessarily applying the first bit of code to the second but getting the same result ultimately. i keep getting error messages no matter what i try

Link to comment
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.

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.