Jump to content

[SOLVED] not sure how to display data on a web page based on selection in a list box


cluce

Recommended Posts

I am not sure how to display data on a web page in a table based on selection in a list box.  I am just not sure how to execute the onclick beahvior from the list box to do this?

I tried googling for an example on the web but I cant find anything that will help me code this??

can someone look at my code of what I have so far? ???  Any feedback is appreciated.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
//connect to database
include'db.php5';

//get parts of records
$get_list_sql = "SELECT * FROM products WHERE Category = '".$_POST['select']."'";
$get_list_res = mysqli_query($mysqli, $get_list_sql) or die(mysqli_error($mysqli));

//create table with the selected data 
    $display_block = "<p align = 'center'> <table class='sortable' border = '1' bordercolor = 'black' cellpadding= '0' cellspacing = '0'>
<thead>
<th  bgcolor = 'orange'>Item Number</th>
<th  bgcolor = 'orange'>Manufacturer</th>
<th  bgcolor = 'orange'>Category</th>
<th  bgcolor = 'orange'>Description</th>
<th  bgcolor = 'orange'>Model</th>
<th  bgcolor = 'orange'>Quantity</th>
<th  bgcolor = 'orange'>Kw</th>
<th  bgcolor = 'orange'>Hours</th>
<th  bgcolor = 'orange'>Price</th> 
</thead>";

//if authorized, get the values
while ($info = mysqli_fetch_array($result)) {
	$ItemNo = stripslashes($info['Item_No']);
	$Man = stripslashes($info['Manufacturer']);
	$Cat = stripslashes($info['Category']);
	$Des = stripslashes($info['Description']);
	$Model = stripslashes($info['Model']);
	$Qty = stripslashes($info['Qty']);
	$Kw = stripslashes($info['Kw']);
	$Hours = stripslashes($info['Hours']);
	$Price = stripslashes($info['Price']);

//create display string
$display_block .= "
<tr>
<td class = 'numeric'>".$ItemNo."</td>
<td>".$Man."</td>
<td>".$Cat."</td>
<td>".$Des."</td>
<td>".$Model."</td>
<td>".$Qty."</td>
<td>".$Kw."</td>
<td>".$Hours."</td>
<td>".$Price."</td>
</tr>";
}
$display_block .= "</table></p>"; 
//display selected data in a table 


//free result
mysqli_free_result($get_list_res);
?>

<form id="form1" name="form1" method="post" action="">
          <label>
          <div align="right">Display by Category:
           <select name="select">
              <option>Diesal</option>
              <option>Engines</option>
              <option>Generators</option>
           </select>
</div>
</label>
</form>
</body>
</html>

Link to comment
Share on other sites

Well, you need a submit button to submit the form...see if this gets you what you want.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php

if (isset($_POST['submit'])){
//connect to database
include'db.php5';

//get parts of records
$get_list_sql = "SELECT * FROM products WHERE Category = '".$_POST['select']."'";
$get_list_res = mysqli_query($mysqli, $get_list_sql) or die(mysqli_error($mysqli));

//create table with the selected data 
    $display_block = "<p align = 'center'> <table class='sortable' border = '1' bordercolor = 'black' cellpadding= '0' cellspacing = '0'>
<thead>
<th  bgcolor = 'orange'>Item Number</th>
<th  bgcolor = 'orange'>Manufacturer</th>
<th  bgcolor = 'orange'>Category</th>
<th  bgcolor = 'orange'>Description</th>
<th  bgcolor = 'orange'>Model</th>
<th  bgcolor = 'orange'>Quantity</th>
<th  bgcolor = 'orange'>Kw</th>
<th  bgcolor = 'orange'>Hours</th>
<th  bgcolor = 'orange'>Price</th> 
</thead>";

//if authorized, get the values
while ($info = mysqli_fetch_array($result)) {
	$ItemNo = stripslashes($info['Item_No']);
	$Man = stripslashes($info['Manufacturer']);
	$Cat = stripslashes($info['Category']);
	$Des = stripslashes($info['Description']);
	$Model = stripslashes($info['Model']);
	$Qty = stripslashes($info['Qty']);
	$Kw = stripslashes($info['Kw']);
	$Hours = stripslashes($info['Hours']);
	$Price = stripslashes($info['Price']);

//create display string
$display_block .= "
<tr>
<td class = 'numeric'>".$ItemNo."</td>
<td>".$Man."</td>
<td>".$Cat."</td>
<td>".$Des."</td>
<td>".$Model."</td>
<td>".$Qty."</td>
<td>".$Kw."</td>
<td>".$Hours."</td>
<td>".$Price."</td>
</tr>";
}
$display_block .= "</table></p>"; 
//display selected data in a table 


//free result
mysqli_free_result($get_list_res);
}
?>

<form id="form1" name="form1" method="post" action="">
          <label>
          <div align="right">Display by Category:
           <select name="select">
              <option>Diesal</option>
              <option>Engines</option>
              <option>Generators</option>
           </select>
</div>
</label>
   <input type="submit" name="submit" value="Submit">
</form>
</body>
</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.