943,984 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 278
  • PHP RSS
Oct 23rd, 2009
-1

newnewnew

Expand Post »
PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $host="localhost"; // Host name
  4. $username="root"; // Mysql username
  5. $password=""; // Mysql password
  6. $db_name="sort"; // Database name
  7. $tbl_name="test_mysql"; // Table name
  8.  
  9. // Connect to server and select database.
  10. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. // Retrieve data from database
  14.  
  15. $sort="";
  16. $select=$_REQUEST["select"];
  17.  
  18. if($select==1)
  19. {
  20. $sort="Order by name asc";
  21. }
  22. elseif($select==2)
  23. {
  24. $sort="Order by email asc";
  25. }
  26.  
  27.  
  28. $sql="SELECT * FROM $tbl_name $sort";
  29. $result=mysql_query($sql); ?>
  30. <form name="myform" method="post">
  31. <table width="400" border="1" cellspacing="0" cellpadding="3">
  32. <tr><td>
  33. <select name="select" id="select" onChange="this.form.submit()">
  34. <option value="">SELECT</option>
  35. <option value="1" <?php if($select==1){ echo "select";}?>>name</option>
  36. <option value="2" <?php if($select==2){ echo "select";}?>>email</option>
  37. </select>
  38. </td></tr>
  39. // Start looping rows in mysql database.
  40. <?
  41. while($rows=mysql_fetch_array($result)){
  42. ?>
  43. <tr>
  44. <td width="10%"><? echo $rows['id']; ?></td>
  45. <td width="30%"><? echo $rows['name']; ?></td>
  46. <td width="30%"><? echo $rows['lastname']; ?></td>
  47. <td width="30%"><? echo $rows['email']; ?></td>
  48. </tr>
  49. <?
  50. // close while loop
  51. }
  52.  
  53. ?>
  54. </table>
  55. </form>
Last edited by Ezzaral; Oct 23rd, 2009 at 4:15 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ykjadeja2020 is offline Offline
2 posts
since Sep 2009
Oct 23rd, 2009
0
Re: newnewnew
Yes, "newnewnew" explains exactly what your problem is. And not using code tags helps us out even more. What exactly is your question?
Last edited by ShawnCplus; Oct 23rd, 2009 at 3:55 pm.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Update Image Not Functioning Properly?
Next Thread in PHP Forum Timeline: Problem with ImageMagick





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC