Jump to content

Implementing search on a displayed table


Recommended Posts

I want to search my order table by order Id.The implementation is such that all the orders are displayed on order management page by default.I have coded this part.Now on this page I want search facility to search by OrderId.I tried to implement but failed.Please suggest something.

 

The code is shown below(I have deleted the part I have coded for search functionality implementation).Also I have attached screenshot of UI for better understanding:

 

 

      <!-- display the list of orders-->

    <?php if(isset($_GET['index']) && ($_GET['index'] == 'List'))

{

?>

<tr>

  <td height="20">[ <a href="order.php?index=Add"><b>Add New >></b></a> ]</td>

  <td height="20"> </td>

</tr>

<tr>

<td> </td>

<td> </td>

</tr>

    <tr>

            <td colspan="2"><?php if(isset($_GET['errormsg'])){?>

<div id="showerror" class="errormessage"><?php echo $_GET['errormsg'];?></div><?php } ?>

<?php if(isset($_GET['successmsg'])){?>

<div id="showsuccess"  class="message"><?php echo $_GET['successmsg'];?></div><?php } ?></td>

            </tr>

    <?php

$selectqry = "select * from tblorder";

$result = mysql_query($selectqry) or die(mysql_error());

$count = mysql_num_rows($result);

?>

  <tr>

  <td colspan="2">

     

  <table width="450" border="0" align="center" cellpadding="0" cellspacing="0" class="TableBorder">

    <tr><td>

<table width="650" border="0" cellspacing="1" cellpadding="0">

<tr>

<td colspan="8" class="tblHeader">List of All Orders (<?php echo $count ; ?>)</td>

</tr>

 

<tr>

<td  colspan="8" valign="bottom" align="center" class="tblHeader"><select name="cmbPage" id="cmbPage" onchange="javascript:_doPagination('product.php','index=List');">

<option value="1" selected>1</option>

<option value="2">2</option>

</select></td>

</tr>

 

<tr>

<td width="20%" align="center" height="22" class="tblColHeader" style="padding-left:5px;">Order Id</td>

<td width="15%" align="center" class="tblColHeader">Customer Email</td>

<td width="20%" align="center" class="tblColHeader">Status</td>

<td width="10%" align="center" class="tblColHeader">Date</td>

<td width="10%" height="22" align="center" class="tblColHeader">Total</td>

<td width="10%" height="22" align="center" class="tblColHeader">View</td>

                <td width="10%" height="22" align="center" class="tblColHeader">Edit</td>

                <td width="10%" height="22" align="center" class="tblColHeader">Print</td>

</tr>

           

           

            <tr>

            <td width="20%" align="center" height="22" class="tblColHeader" style="padding-left:5px;"><input type="text" name="order_search" id="order_search" value=""></td>

           

            <td>

            <td width="15%" align="center" height="22" class="tblColHeader" style="padding-left:5px;"><input type="button" name= "filter" id="filter" value="Filter" onclick="javascript:window.document.form.action"></td>

           

           

            </tr>

   

             

               

                <?php

 

 

 

while($rows = mysql_fetch_assoc($result)){

$OrderId = $rows['Order_Id'];

$Customer_Email = $rows['Customer_EmailId'];

$Status = $rows['Status'];

$Date = $rows['Date'];

$Total = $rows['Grand_Total'];

 

 

?>

<tr height="22" class="alterClass2" onMouseOver="this.className='mouseOver'" onMouseOut="this.className='alterClass2'">

<td align="center" style="padding-left:5px;"><?php echo $OrderId; ?></td>

<td align="center" style="padding-left:5px;"><?php echo $Customer_Email; ?></td>

<td align="center" style="padding-left:5px;"><?php echo $Status; ?></td>

                    <td align="center" style="padding-left:5px;"><?php echo $Date; ?></td>

                    <td align="center" style="padding-left:5px;"><?php echo $Total; ?></td>

 

             

<td align="center">

<a href="order.php?index=View&Id=<?php echo $OrderId ?>"><img src="../images/bView.png" width="16" height="16" border="0" /></a>

</td>

                   

                        <td align="center">

<a href="order.php?index=Edit&Id=<?php echo $OrderId ?>"><img src="../images/b_edit.png" width="16" height="16" border="0" /></a>

</td>

 

                   

                   

                   

                   

                        <td align="center">

<a href="order.php?index=Print&Id=<?php echo $OrderId ?>"><img src="../images/print_icon.gif" width="16" height="16" border="0" /></a>

</td>

                   

                    <?php } ?>

                   

                 

                   

              <!--      <td align="center">

<a href="product.php#TB_inline?width=350&height=130&inlineId=CategoryDelete<?php echo $ProductId ?>" class="thickbox" title="Confirm Delete"><img src="../images/b_drop.png" width="16" height="16" border="0" /></a>

</td>

</tr>

                <div id="CategoryDelete<?php echo $ProductId ?>" style="display: none;"><br />

<p align="center">Are you sure you want to delete the product<BR>

<b style="color: #990000;"></b><?php echo $productname ?>?</p>

<p align="center">

<input type="button" name="btnDelete" value="  YES  " class="Button" onclick="javascript:window.location.href='product.php?index=List&action=Delete&Id=<?php echo $ProductId ?>';" /> 

<input type="button" name="btnCancelDelete" value="  NO  " onclick="javascript:tb_remove();" class="Button" /></p>

</div>

                ->>

               

 

 

</table>

</td></tr>

  </table></td>

  </tr>

<!--<tr>

  <td> </td>

  <td> </td>

</tr>

<tr>

  <td> </td>

  <td> </td>

</tr>

</table>

</td>

</tr>

<tr>

  <td> </td>

  <td> </td>

</tr>

<tr>

  <td> </td>

  <td> </td>

</tr> -->

</table></td>

  </tr>

</table>

 

<?php }?>

<!-- End of display function -->

 

[attachment deleted by admin]

Link to comment
Share on other sites

you need to add a check to see if search form was posted, and then do "select * from tblorder WHERE orderid = " . $_POST['orderid']  as the sql query instead of the "select * from tblorder" one.

 

note i havent put in any error trapping, putting a $_POST variable directly into sql statement is a no no! (and i dont mean double negative makes a plus  :P), its just to show you how to do it really

the above search is only ever going to return 1 record though

 

hope that helps

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.