Jump to content

select which fields to display in resultant table


CJBee

Recommended Posts

I have the following html code and php code. I would like clients to select which fields in the mysql database they would like to have appear in the resultant table by checking the text box next to the field in the html form. For instance they should be able to select first name and city and have only those columns appear in the resultant table.

 

# <html>

# <head>

# <title>Search Clients Database</title>

# </head>

# <body>

# <h1>Clients Database Search Page</h1>

# <form action="searchclients.php" method="post">

#  <table width="100%" border="1" cellspacing="1" cellpadding="1">

#    <tr>

#      <th width="37" scope="col"> </th>

#      <th width="114" scope="col">Fields</th>

#      <th width="169" scope="col">Filter Value</th>

#      <th width="1157" scope="col"> </th>

#    </tr>

#    <tr>

#      <td><input type="checkbox" name="idc" id="idc"></td>

#      <td>ID</td>

#      <td><input type="text" name="ID" id="ID"></td>

#      <td> </td>

#    </tr>

#    <tr>

#      <td><label>

#        <input type="checkbox" name="fnc" id="fnc">

#      </label></td>

#      <td>First Name</td>

#      <td><input type="text" name="FirstName" id="FirstName"></td>

#      <td> </td>

#    </tr>

#    <tr>

#      <td><label>

#        <input type="checkbox" name="lnc" id="lnc">

#      </label></td>

#      <td>Last Name</td>

#      <td><input type="text" name="LastName" id="LastName"></td>

#      <td> </td>

#    </tr>

#    <tr>

#      <td><label>

#        <input type="checkbox" name="cc" id="cc">

#      </label></td>

#      <td>City</td>

#      <td><input type="text" name="City" id="City"></td>

#      <td> </td>

#    </tr>

#    <tr>

#      <td><label>

#        <input type="checkbox" name="pc" id="pc">

#      </label></td>

#      <td>Province</td>

#      <td><select name="Province" id="Province">

#        <option selected> </option>

#        <option>KZN</option>

#        <option>North West Province</option>

#        <option>Gauteng</option>

#        <option>Free State</option>

#        <option>Mpumalanga</option>

#        <option>Eastern Cape</option>

#        <option>Limpopo Province</option>

#        <option>Northern Cape</option>

#        <option>Western Cape</option>

#      </select></td>

#      <td> </td>

#    </tr>

#  </table>

#  <p>

#    <input type="submit" name="submit" value="Search" />

#  </p>

# </form>

# </body>

# </html>

 

 

# <?php

# mysql_connect ("localhost", "username","password")  or die (mysql_error());

# mysql_select_db ("clients");

# $fn = $_POST['FirstName'];

# $ln = $_POST['LastName'];

# $city = $_POST['City'];

# $prov = $_POST['Province'];

# $idc = $_POST['idc'];

# $fnc = $_POST['fnc'];

# $lnc = $_POST['lnc'];

# $cc = $_POST['cc'];

# $pc = $_POST['pc'];

# ?>

# <html>

# <body>

# <table border=1>

#  <tr>

#    <th>ID</th>

#    <th>First Name</th>

#    <th>Last Name</th>

#    <th>City</th>

#    <th>Province</th>

# </tr>

# <?php

# $sql = mysql_query("select ID, FirstName, LastName, City, Province from clients where FirstName like '%$fn%' and LastName like '%$ln%' and City like '%$city%' and Province like '%$prov%'");

# while ($row = mysql_fetch_array($sql)){

#    $id = $row['ID'];

#    $fname = $row['FirstName'];

#    $lname = $row['LastName'];

#    $city = $row['City'];

#    $prov = $row['Province'];

# ?>

# <tr>

# <th><?php echo $id;?></th>

# <th><?php echo $fname;?></th>

# <th><?php echo $lname;?></th>

# <th><?php echo $city;?></th>

# <th><?php echo $prov;?></th>

# </tr>

# <?php } //this ends the if?>

# </table>

# </html>

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.