Order PHP MYSQL search by a,b,c
Ok so I have a database that I am searching for business results. I have the following code
<?php
REQUIRE('config.php');
$q = mysql_real_escape_string(ucfirst(trim($_REQUEST['q'])));
$result = mysql_query("SELECT * FROM gj WHERE name LIKE '%$q%' OR cat1 LIKE '%$q%' OR cat2 LIKE '%$q' OR cat3 LIKE '%$q' ORDER by name") or trigger_error(mysql_error());
$rows = mysql_num_rows($result);
if($rows == 0){
}
echo " <div id='title'>Search for "$q"<div class='right'>$rows business";if($rows > 1){echo "es";}elseif($rows == "0"){echo "es";}echo" found</div></div>";
while($row = mysql_fetch_array($result))
{
$id=$row['id'];
$name=$row['name'];
$phone=$row['phone'];
$webs开发者_JAVA技巧ite=$row['website'];
$city=$row['city'];
$address=$row['address1'];
$zipcode=$row['zipcode'];
$sponsored = $row['sponsored'];
$addressmap = preg_replace('/\s/', '+',$address);
$citymap = preg_replace('/\s/', '+',$city);
//Start While Loop
echo"<div id='listing'>
<div id='mainlisting'>
<div class='name'>
<a href='./more.php?id=$id' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"'>$name</a> <div class='right'>$phone</div>
</div>
<div class='other'>
$address, $city, CO $zipcode
|<a target='_blank' href='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=$addressmap,+$city+CO&&&ie=UTF8&hq=&hnear=$address,+$city,+Colorado+$zipcode&safe=active&&&t=h&z=14&iwloc=A&output=embed' rel='lyteframe' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"' title='$name' rev='width: 500px; height: 500px; scrolling: no;'> See Map</a><br/>
<a href='#' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"'>";if($website != null){ echo "<a target='_blank' href='$website' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"'>Website</a> |";}echo" <a href='#' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"'>More Info</a>
</div>
</div>
</div><!--/LISTING-->";
}
I then echo listings name, phone, website, address, and a clickable map. Now I want to order each listing ABC style. So the first listing shows A by it and the second shows B next to it and so on (Like what happens when you search for a business on Dex Knows)...I'm a PHP novice so any help would be greatly appreciated.
you can use css to do that.
Wrap the name in li
and use list-style:upper-alpha
good luck
see more here http://w3schools.com/Css/css_list.asp
精彩评论