Forum Moderators: coopster

Message Too Old, No Replies

Display Tabular Data - Newbie Needs Some Help

Trying to extract data from mysql db with php, make calculations & displa

         

jhcadmin

11:30 am on Jun 22, 2005 (gmt 0)

10+ Year Member



After conncecting to mysql database, I need to:
1. filter data by a drop-down selection,
2. make simple mathmatic calculations based on the selection above,
3. display original db fields and calculation results in tabular format in an html page.

Please provide some assistance.

mcibor

1:11 pm on Jun 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to webmasterworld!

Remember, that php is only server based language. So what you have is two ways to do this:

I
1. Select filter
2. Submit the form
3. Calculate
4. Connect to db and display the data

or

II
1. Connect to db and write the data to js
2. Select filter and filter data with js
3. Calculate with js
4. Display with js

To accomplish first task:
form.html:

<form action="process.php" method="POST"><select name="filter[]"><option value="blue">Blue</option>...</select><select name="filter[]">....<input type="submit" name="action" value="submited"></form>

mcibor

1:12 pm on Jun 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



process.php:
<?php
if($_POST["action"]!= "submited")
{header("Location: form.html");//redirect
die("Wrong form");}
$filter = "WHERE ";
$select = array("color", "type");//what is each select
foreach($_POST["filter"] as $key=>$value) {
$filter .= $select[$key] . "='" . $value ."' AND ";}
$filter = substr($filter, 0, -5);//gets rid of last AND
$sql = "SELECT product, sthelse FROM table $filter ORDER by color LIMIT 0, 20";
...//get the db and echo the values
?>

Hope this gives you some insight
Best regards
Michal Cibor