I have query with anchor tag in php mysql?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Harshita Rana
    New Member
    • Dec 2010
    • 2

    I have query with anchor tag in php mysql?

    If i click on city link give data order by city.same for username

    Code:
    <html>
    <body>
    
    <p>
    <a href="searchorderby.php" >User Name</a> &nbsp;&nbsp;
        <a href="searchorderby.php" >City</a>
    </p>
    <p></p>
    <table border="1">
    <tr>
    <td>userid</td>
    <td>usernmae</td>
    <td>userpassword</td>
    <td>address</td>
    <td>gender</td>
    <td>city</td>
    <td>Birthdate</td>
    </tr>
    
    <?php 
    $link=mysql_connect("localhost","root","");
    mysql_select_db("login");
    
    $queryfirst="SELECT * FROM userinfo ";
    
    $result=mysql_query($queryfirst) or die(mysql_error());
    
    while($row=mysql_fetch_array($result))
    {
    ?>
    <tr> 
    <td><?php echo $row['userid']; ?></td>
    <td><?php echo $row['username']; ?></td>
    <td><?php echo $row['userpassword']; ?></td>
    <td><?php echo $row['address']; ?></td>
    <td><?php echo $row['gender']; ?></td>
    <td><?php echo $row['city']; ?></td>
    <td><?php echo $row['Birthdate']; ?></td>
    </tr> 
    <?php 
    }
    ?>
    
    </table>
    </body>
    </html>
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    you did nothing to be ordered as User name or as city name

    here is a piece of suggested
    Code:
     
    <a href="searchorderby.php?order=user" >User Name</a> 
    &nbsp;&nbsp;
    <a href="searchorderby.php?order=city" >City</a>
    
    <?php
     $link=mysql_connect("localhost","root","");
     mysql_select_db("login");
     
     if(isset($_GET['order'])==false) 
      $queryfirst="SELECT * FROM userinfo ";
     else if($_GET['order']=='user')
        $queryfirst="SELECT * FROM userinfo Order By UserName";
        else if($_GET['order']=='city')
        $queryfirst="SELECT * FROM userinfo Order By City";
        else
    $queryfirst="SELECT * FROM userinfo ";
    
    ?>

    Comment

    Working...