View Single Post
Old Apr 26th, 2006, 1:18 PM   #1
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
mysql table view require()or suggestions.

i am trying to create a form that will show a database table in the required format eg. name a-z or email a-z etc.. i would like this so that when the page loads up the table is displayed and then by selecting a drop down menu. you can change the format. so far i have been totally confused by doing this on one page. so i am trying to do it over 2(if you get what i mean).
This is my form:
<html>


<body>

<form action="table.php" name="form" method="post">
<select name="view">
<option value="fullname">fullname a-z
<option value="email"> email a-z
</select>
<input type="submit" name="submit">
</form>

</body>
</html>

and this is the php code i have to interpret the form.
$view = $_POST["view"];
print("$view");

$db = mysql_connect('localhost', 'guest', 'password');
mysql_select_db('test',$db); 
$result = mysql_query('SELECT * FROM messages  ORDER BY $view DESC',$db); 
echo '<TABLE border="1">'; 
echo '<TR><TD><B>Full Name</B></td><TD><B>Email Address</B></td><TD><B>Date and time</B></td><TD><B>Message</td></B></TR>';
while($myrow = mysql_fetch_array($result)) 
{ 
echo '<TR><TD>'; 
echo $myrow['fullname']; 
echo "<TD>"; 
echo $myrow['emailaddress'];  
echo "<TD>"; 
echo $myrow['date']; 
echo "<TD>"; 
echo $myrow['message']; 
} 
echo '</TABLE>';
?>
i did a test to check the variable $view was recieving the right info from the form and it seems fine. i just cant seem to get it displaying the table once it is formated. it just displays it as it was.

please help me sort this one out or even better help me create a code thats all on one page
__________________
this forum rules you guys are great!
thanks to all who help
piercy
piercy is offline   Reply With Quote