Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 25th, 2005, 12:08 PM
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I display search results...

I have a Web site that I am building with PHP pages that are going to retrieve information from a MySQL Database. I want to be able to retrieve data from the "city" field and "count" the total number of rows "$city" is in, while displaying only one instance of the name of the "$city". I want the number of rows displayed in parentheses next to the city. In other words, I want the results to look like the following example where the data will be displayed in a 3-column Table formatted using HTML. What I have so far is at the bottom of this post. Please use it for reference. Upon reply, please be specific as I am a beginner! I can tell you more if you need me to. Thanks! To test the functionality yourself, just go to http://www.businessdirectorylistings.com/tennessee.php. You will see for yourself what kind of results I am currently getting.


EXAMPLE > THIS IS WHAT I WANT THE RESULTS TO DISPLAY:

Your Search Found The Following Results...

Chicago (3) Houston (2) Nashville (5)
Panama City (4) Phoenix (3) Portland (2)

NOTE: The cities will have hyperlinks that link to a page of search results for that city.


EXAMPLE OF WHAT THE RESULTS CURRENTLY LOOK LIKE WITH THE CODE I HAVE:

 1. Chicago
 2. Chicago
 3. Chicago
 4. Houston
 5. Houston
 6. Nashville
 7. Nashville
 8. Nashville
 9. Nashville
10. Nashville
11. Panama City
12. Panama City
13. Panama City
14. Panama City
15. Phoenix
16. Phoenix
17. Phoenix
18. Portland
19. Portland


<BEGIN HTML-PHP CODE>

<html>
<head>
<title>Get My Query</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<?php

include("connectme.inc");

$connection = mysql_connect($host,$user,$password)
    or die ("Couldn't connect to server");
$db = mysql_select_db($database,$connection)
    or die ("Couldn't select database");
$state = "$state";
$city = "$city";
$query = "SELECT * FROM tblCities WHERE city='$city' ORDER BY city";
$result = mysql_query($query)
or die ("Couldn't execute query");
$nrows = mysql_num_rows($result);

/* Display results in a table */
echo "<h1>Found The Following Results...</h1>";
echo "<table cellspacing='8'>";
echo "<tr><td colspan='4'></td></tr>";

for ($i=0;$i<$nrows;$i++)

{

$n = $i + 1; /* Add 1 so that records won't start displaying at 0 */
$row = mysql_fetch_array($result);
extract($row);
echo "<tr>\n
<td>$n.</td>\n
<td><a href='http://www.businessdirectorylistings.com/listingresults.php?city=$city&state=$state' title='Visit&nbsp;$bizname#39;s&nbsp;Web&nbsp;Site '>$bizname</a></td>\n
<td>($phonearea)&nbsp;$phone</td>\n
<td>$city,&nbsp;$state</td>\n
</tr>\n";
echo "<tr><td colspan='4'></td></tr>\n";

}

echo "</table>\n";

?>

</body>
</html>

</END HTML-PHP CODE>

Reply With Quote
  #2 (permalink)  
Old April 25th, 2005, 12:11 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Cross-post with: http://p2p.wrox.com/topic.asp?TOPIC_ID=29717
Post replies there.

Please do not cross-post.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter double search results ABplace Beginning VB 6 3 June 28th, 2007 08:11 AM
How do I display search results... aspiretech9 PHP How-To 1 April 26th, 2005 10:12 AM
How do I display search results... aspiretech9 Beginning PHP 1 April 25th, 2005 04:59 PM
How display search results ? URGENT arulkumar Classic ASP Databases 2 March 4th, 2005 10:26 AM
Customize Search Results bmains ASP.NET 1.0 and 1.1 Professional 4 January 15th, 2004 08:51 AM



All times are GMT -4. The time now is 03:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.