开发者

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 &quot;$q&quot;<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&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=$addressmap,+$city+CO&amp;&amp;&amp;ie=UTF8&amp;hq=&amp;hnear=$address,+$city,+Colorado+$zipcode&amp;safe=active&amp;&amp;&amp;t=h&amp;z=14&amp;iwloc=A&amp;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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜