reading results on mysql table - with filter & sorting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danieln
Forum Newbie
Posts: 4
Joined: Sat Apr 12, 2008 4:05 am

reading results on mysql table - with filter & sorting

Post by danieln »

i have created a form to key in some datas into my database. now i need some help on how to have the results displayed with some filtering options.

my mysql fields are like id,name,address,class,year,project

i need to have the results displayed where i can select a filter to just show data like for 2007 only or by class abc only. how do i make this filter as a dropdown on the result page?

also can please give me some links on how to make this page protected for registered users only where there will different user levels view different report results?

thanks!
danieln
Forum Newbie
Posts: 4
Joined: Sat Apr 12, 2008 4:05 am

Re: reading results on mysql table - with filter & sorting

Post by danieln »

in case you neeed to view the codes, here they are (with no filters & sorting)

-----------
<?php
$username="root";
$password="";
$database="dbsample";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die ("Unable to connect");

$query= "SELECT * FROM evoucher";
$result= mysql_query($query);

$num= mysql_numrows($result);
?> <table width="100%" border="1" cellspacing="0" cellpadding="5">
<tr>
<td valign="top" bgcolor="#CCCCCC"><strong>Full Name</strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>Contact</strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>Address</strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>IC</strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>Email</strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>Voucher</strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>Outlet</strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>Promotion </strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>Validity</strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>Day</strong></td>
<td valign="top" bgcolor="#CCCCCC"><strong>Time</strong></td>
</tr>

<?php

$i= 0;
while ($i < $num) {
$name= mysql_result($result, $i, "name");
$contact= mysql_result($result, $i, "contact");
$address= mysql_result($result, $i, "address");
$ic= mysql_result($result, $i, "ic");
$email= mysql_result($result, $i, "email");
$voucher= mysql_result($result, $i, "voucher");
$outlet= mysql_result($result, $i, "outlet");
$promo= mysql_result($result, $i, "promo");
$validity= mysql_result($result, $i, "validity");
$day= mysql_result($result, $i, "day");
$month= mysql_result($result, $i, "month");
$year= mysql_result($result, $i, "year");
$hour= mysql_result($result, $i, "hour");
$min= mysql_result($result, $i, "min");
$sec= mysql_result($result, $i, "sec");
$ap= mysql_result($result, $i, "ap");
?>
<tr>
<td valign="top"><?php echo $name; ?></td>
<td valign="top"><?php echo $contact; ?></td>
<td valign="top"><?php echo $address; ?></td>
<td valign="top"><?php echo $ic; ?></td>
<td valign="top"><a href='mailto:$email'><?php echo $email; ?></a></td>
<td valign="top"><?php echo $voucher; ?></td>
<td valign="top"><?php echo $outlet; ?></td>
<td valign="top"><?php echo $promo; ?></td>
<td valign="top"><?php echo $validity; ?></td>
<td valign="top"><?php echo $day; ?>-<?php echo $month; ?>-<?php echo $year; ?></td>
<td valign="top"><?php echo $hour; ?>:<?php echo $min; ?>:<?php echo $sec; ?>:<?php echo $ap; ?></td>
</tr>

<?php
$i++;

}
mysql_close();
?>
</table>
<p>
-------------
Post Reply