| | |
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 |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube






