list categories

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim39
Forum Newbie
Posts: 2
Joined: Sat Dec 19, 2009 5:20 pm

list categories

Post by Jim39 »

Hi

If anyone could help with below code as I am new to php

Code: Select all

<?php
$result = mysql_query("SELECT * FROM hotels ORDER BY city");
 
while($row = mysql_fetch_array($result))
  {
  echo $row['city'] . " " ;
  echo "<br />";
  }
?>
above code list all cities as below
newyork
newyork
newyork
newyork
newyork
newyork
Washington
Washington
Washington
Washington
Washington
Washington
Seattle
Seattle
Seattle
Seattle
Seattle
Kansas
Kansas
Kansas
Kansas
Kansas
Kansas
Kansas
.... continue

but i want to list like below and when a city link is clicked, all the hotels in that city will display on a city Page using the appropriate template

Newyork
washington
seattle
kansas ....

any help much appreciate

Thanks
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: list categories

Post by aravona »

Code: Select all

$result = mysql_query("SELECT DISTINCT * FROM hotels ORDER BY city");
This will make a list of every place just once
Post Reply