Skip to main content
Inspiring
September 21, 2011
Question

How create a table from MySQL, with filter options

  • September 21, 2011
  • 1 reply
  • 912 views

Hi,

I want to create a table in a php page that

  • links to a MySQL database that I have already created.
  • has lookup fields that people can filter the information from
  • is be able to return multiple results per lookup

The background: I have created a php page through which users submit survey questionnaires, which works well - users are able to submit information to my MySQL database. I am now trying to create a page that users can use to search through those results.

I want users to be able to pick from a drop down menu at the top of the page (say "Location: London") and to view all the results from the field "Location" that had the answer "London" in them.

I also want people to be able to filter by various different fields (so there would be many drop-down fields at the top of the page - for example "Location", "Type", "Model", etc - so that users can search through for either "Location = " or "Type = " or "model - ", etc, etc, etc...)

I have no idea how to do this.

Any suggestions? I can get the php page to connect to the database, and I can get it to reveal one record at a time by using bindings, but I can't filter it (it just returns the first record in the database) and it won't return multiple records.

Any help you could give would be great!

_AJ_TUS_

This topic has been closed for replies.

1 reply

_AJD_TUS_Author
Inspiring
September 21, 2011

I should add: here is my code (it might be esier for you to help me by tellnig me wyhat I need to add in, and where, if you know where I'm starting from...!):

<?php require_once('Connections/DB1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_DB1, $DB1);
$query_Recordset1 = "SELECT * FROM Draft3";
$Recordset1 = mysql_query($query_Recordset1, $DB1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
}
.oneColElsCtr #container {
width: 46em;
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
border: 1px solid #000000;
text-align: left; /* this overrides the text-align: center on the body element. */
}
.oneColElsCtr #mainContent {
padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
}
-->
</style></head>

<body class="oneColElsCtr">

<div id="container">
  <div id="mainContent"></div>
<!-- end #container --></div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Harm_Millaard
Inspiring
September 26, 2011

You mean something like this: Benchmark Results ?