newnewnew

Reply

Join Date: Sep 2009
Posts: 2
Reputation: ykjadeja2020 is an unknown quantity at this point 
Solved Threads: 0
ykjadeja2020 ykjadeja2020 is offline Offline
Newbie Poster

newnewnew

 
-1
  #1
33 Days Ago
  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; 33 Days Ago at 4:15 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey
 
0
  #2
33 Days Ago
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; 33 Days Ago at 3:55 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC