<?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>

Yes, "newnewnew" explains exactly what your problem is. And not using code tags helps us out even more. What exactly is your question?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.