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

Edited by Ezzaral: Added [code] [/code] tags. Please use them to format any code that you post.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by ShawnCplus
0

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

Edited by ShawnCplus: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.