| | |
newnewnew
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2009
Posts: 2
Reputation:
Solved Threads: 0
PHP Syntax (Toggle Plain Text)
<?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="sort"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Retrieve data from database $sort=""; $select=$_REQUEST["select"]; if($select==1) { $sort="Order by name asc"; } elseif($select==2) { $sort="Order by email asc"; } $sql="SELECT * FROM $tbl_name $sort"; $result=mysql_query($sql); ?> <form name="myform" method="post"> <table width="400" border="1" cellspacing="0" cellpadding="3"> <tr><td> <select name="select" id="select" onChange="this.form.submit()"> <option value="">SELECT</option> <option value="1" <?php if($select==1){ echo "select";}?>>name</option> <option value="2" <?php if($select==2){ echo "select";}?>>email</option> </select> </td></tr> // Start looping rows in mysql database. <? while($rows=mysql_fetch_array($result)){ ?> <tr> <td width="10%"><? echo $rows['id']; ?></td> <td width="30%"><? echo $rows['name']; ?></td> <td width="30%"><? echo $rows['lastname']; ?></td> <td width="30%"><? echo $rows['email']; ?></td> </tr> <? // close while loop } ?> </table> </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.
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.
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.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Update Image Not Functioning Properly?
- Next Thread: Problem with ImageMagick
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






