Jump to content

How to format and display search results?..


bdrever

Recommended Posts

I need some tips for how to display search results.Querying the database is not the issue I just have no idea how to display the results.I want to display the results in a table, 3 columns of 4 rows, so 12 results per page. I don't know how to do this. Would I make some sort of nested loop?Also, if I have more than 12 results I want to spread them over multiple pages. This I also have no clue how to do.I welcome any and all suggestions.Thanks guys!

Link to comment
Share on other sites

Hi!To keep the result to 12 you need to use LIMIT in your SQL MySQL Manual - Select (search for limit...) (There's alot of page-scripts outhere..)Ex:

$start = (intval($_GET['page']) - 1) * 12$query = "SELECT * FROM tbl LIMIT $start,12";

Here's a short and real example of pagination:

$post_count = ??; //Get the total count in the tablefor( $p = 0; $p < ($post_count / 12); $p++) {	 if ($p == $_GET['page']) {		  $tag1 = '<span class="bold">';		  $tag2 = '</span>';	 } else {		  $tag1 = '<a href="?page='.$p.'">';		  $tag2 = '</a>';	 }	 echo $tag1 . $p . $tag2;}

To output 3 times 4 "cells" you could use something like this:

// Start at zero$count = 0;// Go thru the rowswhile( $row = mysql_fetch_assoc( $res )) {	// If it's a new row, add tr	if ($count == 0)		echo "<tr>\n";	echo "<td>";	....	echo "</td>\n";	// Count cells...	$count++;	// It was the last cell on this row	if ($count == 3) {		 // end tr		 echo "</tr>";		 // Reset count		 $count = 0;	}}// If there was less than 12 (or three on a row)if ($count > 0) [	// Add a spanning "dummy cell"	echo '<td colspan="'.(3-$count).'"> </td>';	echo "</tr>\n";}

Hope that helpedGood Luck and Don't Panic!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...