Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Need code help in creating filters using Mysql DB data : urgent

8:08 am on Sep 17, 2012 (gmt 0)

New User

joined:Aug 29, 2012
posts: 16
votes: 0

HI Friends,

I am planning to creat a multiple filters like.

by date,
by row,
by field

Initially I have started writing a code to execute Mysql command using PHP but as I am starter with PHP and still need to learn lot this pls help on below code.

<?php session_start(); ?>
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
$pagelimit = 10;
$offset = @$_POST['cPage']?@(($_POST['cPage']-1)*$pagelimit):0 ;
// Connect to server and select databse.
require_once('classes/tc_pageNav.php'); //include pageNav class
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$data = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM $tbl_name where Outage Start Time:='$date' and Outage Start Time:='$date2' LIMIT $offset, $pagelimit ")
or die(mysql_error());
$res = mysql_fetch_array(mysql_query("select FOUND_ROWS()"));
$totalRecords = $res[0];
$page_nav = new tc_pageNav($totalRecords);


<div id="templatemo_main" color="#2EFEF7">
<table border= "3">
<th>S NO:</th>
<td>Client Name:</td>
<td>WC Incident ID:</td>
<td>O2 Incident ID:</td>
<td>Supplier Name:</td>
<td>Vendor Incident ID:</td>
<td>Incident Title:</td>
<td>Incident Description:</td>
<td>Identified Party:</td>
<td>Outage Start Time:</td>
<td>Outage End Time:</td>
<td>Time the issue notified :</td>
<td>Time notification was sent:</td>
<td>Root Cause:</td>
<td>SLA Status:</td>
<td>Communication With in SLA:</td>
<td>Service Impacted:</td>
<td>Vendor Name:</td>
<td>Root Cause Type:</td>
<td>Change Related:</td>
<td>Change Number:</td>
<td>User Name:</td>
</div> <!-- end of main -->
while($info = mysql_fetch_array( $data ))
{ ?>
<td><?=$info['S NO:']?></td>
<td><?=$info['Client Name:']?></td>
<td><?=$info['WC Incident ID:']?></td>
<td><?=$info['O2 Incident ID:']?></td>
<td><?=$info['Supplier Name:']?></td>
<td><?=$info['Vendor Incident ID:']?></td>
<td><?=$info['Incident Title:']?></td>
<td><?=$info['Incident Description:']?></td>
<td><?=$info['Identified Party:']?></td>
<td><?=$info['Outage Start Time:']?></td>
<td><?=$info['Outage End Time:']?></td>
<td><?=$info['Time the issue notified :']?></td>
<td><?=$info['Time notification was sent:']?></td>
<td><?=$info['Root Cause:']?></td>
<td><?=$info['SLA Status:']?></td>
<td><?=$info['Communication With in SLA:']?></td>
<td><?=$info['Service Impacted:']?></td>
<td><?=$info['Root Cause Type:']?></td>
<td><?=$info['Change Related:']?></td>
<td><?=$info['Change Number:']?></td>
<td><?=$info['User Name:']?></td>
<?php } ?>
<tr> <td colspan = '34'> <?php echo $page_nav->printNavJump(); ?><td></tr>



Is this the right one pls help me ?
8:52 pm on Jan 20, 2013 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 0

>> multiple filters

You can filter as you demonstrated, in your WHERE clause of your query. However, AND THIS IS A BIG WARNING, never trust user-supplied input, including raw $_POST superglobals. You really should be checking your data for valid type and expected values and after that you should be using the "real_escape" features provided by your database API. More information can be found in the online PHP manual for Security as well as the MySQLi functions.