Welcome to WebmasterWorld Guest from 54.145.166.247

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Numbering Search Query Results : (PHP, MySQL)

How can I number my search query results?

   
12:54 am on Jan 8, 2005 (gmt 0)

10+ Year Member



Hello,

Continued from my previous post: [webmasterworld.com...]

How do I number my search results (1,2,3)?

Search_Results.php

1. Result A

2. Result B

3. Result C

Search_Results.php Code

<?

include("*****.php");

if ($search) // perform search only if a string was entered.
{
mysql_connect() or die ("Problem connecting to Database");

$sql= mysql_query("SELECT wname, url, title, keywords, description, city, country, category FROM directory WHERE city LIKE '%$search%' wname LIKE '%$search%' title LIKE '%$search%' keywords LIKE '%$search%' description LIKE '%$search%' country LIKE '%$search%' category LIKE '%$search%' url LIKE '%$search%'", $db);

if ($sql)
{
echo "<table width=100% border=0 cellpadding=0 cellspacing=5 class=border_playlist_table><tr>";

while ($myrow = mysql_fetch_array($sql)){ // Begin while
$wname = $myrow["wname"];
$url = $myrow["url"];
$title = $myrow["title"];
$city = $myrow["city"];
$country = $myrow["country"];
$category = $myrow["category"];
$keywords = $myrow["keywords"];
$description = $myrow["description"];
echo "<tr class=sub_1><td colspan=4>$wname : $category</td></tr>
<tr bgcolor=#55556F><td><p>".($i+1)."</p></td>
<td><p><a href=$url target=_blank>$url</a></p></td>
<td><p>$city</p></td>
<td><p>$country</p></td></tr>
<tr bgcolor=#55556F><td colspan=4>$keywords</td></tr>
<tr bgcolor=#55556F><td colspan=4>$description</td></tr>
<tr><td colspan=4>&nbsp;</td></tr>";
} // end while
echo "</tr></table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}
?>

6:24 am on Jan 8, 2005 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



the short answer

$counter = 1;
while ($myrow = mysql_fetch_array($sql)){
echo '<br>',$counter;
$counter++;
}

6:20 pm on Jan 8, 2005 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



the shorter answer

$counter = 0; 
while ($myrow = mysql_fetch_array($sql)){
echo '<br>',++ [php.net]$counter;
}

hehe, gotta love smart alecks eh, jatar? ;)
7:06 pm on Jan 8, 2005 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



eeewwww, fancy ;)

actually I have never done that, so, lesson learned

9:47 pm on Jan 8, 2005 (gmt 0)

10+ Year Member



Wow real FANCY!

Thanks Coopster and Jatar_K once again!

Here is the working script:

if ($sql)
{
echo "<table width=100% border=0 cellpadding=0 cellspacing=5 class=border_playlist_table><tr>";

$counter = 0;
while ($myrow = mysql_fetch_array($sql)){ // Begin while
$wname = $myrow["wname"];
$url = $myrow["url"];
$title = $myrow["title"];
$city = $myrow["city"];
$country = $myrow["country"];
$category = $myrow["category"];
$keywords = $myrow["keywords"];
$description = $myrow["description"];
echo "<tr class=sub_1><td colspan=4>".++$counter.".$wname : $category</td></tr>
<tr bgcolor=#55556F>
<td><p><a href=$url target=_blank>$url</a></p></td>
<td><p>$city</p></td>
<td><p>$country</p></td></tr>
<tr bgcolor=#55556F><td colspan=4>$keywords</td></tr>
<tr bgcolor=#55556F><td colspan=4>$description</td></tr>
<tr><td colspan=4>&nbsp;</td></tr>";
} // end while
echo "</tr></table>";
} else { echo "problems...."; }
} else {
echo "Search form is empty. <br> Go back and type a new search";
}

Thanks AGAIN!