homepage Welcome to WebmasterWorld Guest from 50.17.21.7
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Numbering Search Query Results : (PHP, MySQL)
How can I number my search query results?
alcheme




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

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";
}
?>

 

jatar_k




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

the short answer

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

coopster




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

the shorter answer

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

hehe, gotta love smart alecks eh, jatar? ;)

jatar_k




msg:1310642
 7:06 pm on Jan 8, 2005 (gmt 0)

eeewwww, fancy ;)

actually I have never done that, so, lesson learned

alcheme




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

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved