Join Login


Full Color Brochures from PrintPlace.com
 DW, PHP & MySQL: Search and Results
 by chaufournier - Dec 07, 2012

I'm struggling with getting a very simple search and results page to display. I've successfully created similar searches in the past, butt now for some reason I cannot get any of my search results tables to display dynamic data.

What I am trying to do is very simple. I have a search box (using a select list) that displays a list of account names from the database. This is working fine (at least it appears to be!). Next I set up a record set to support a dynamic table displaying the results from the dropdown search form. The table pulls three fields: Account_ID, Account_Name and Salutation_Informal. When I run the php file in a browser, the dropdown list properly displays, but no results are shown in the results table. I'm working in Dreamweaver CS6 wiht PHP and MySQL.

Here's my code. WHAT AM I DOING WRONG??????????? ANY HELP WOULD BE APPRECIATED!


------------------

<!--OPEN DATABASE CONNECTION -->
<?php require_once('Connections/dbconnect.php'); ?>
<!--THIS SCRIPT RUNS TWO RECORD SETS. THE FIRST POPULATES DATA IN THE DROPDOWN LIST AND THIS INFO IS PULLED FROM THE ACCOUNTINFO TABLE. THE SECOND RECORD SET IS USED TO GENERATE THE DYNAMIC TABLE AND THE RESULTS SHOULD DISPLAY THREE FIELDS (Account_ID, Account_Name, and Salutation_Informal) -->
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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_dbconnect, $dbconnect);
$query_rs_Populate_Dropdown = "SELECT Account_Name FROM accountinfo ORDER BY Account_Name";
$rs_Populate_Dropdown = mysql_query($query_rs_Populate_Dropdown, $dbconnect) or die(mysql_error());
$row_rs_Populate_Dropdown = mysql_fetch_assoc($rs_Populate_Dropdown);
$totalRows_rs_Populate_Dropdown = mysql_num_rows($rs_Populate_Dropdown);

$maxRows_RS_Search_Results_Account = 10;
$pageNum_RS_Search_Results_Account = 0;
if (isset($_GET['pageNum_RS_Search_Results_Account'])) {
$pageNum_RS_Search_Results_Account = $_GET['pageNum_RS_Search_Results_Account'];
}
$startRow_RS_Search_Results_Account = $pageNum_RS_Search_Results_Account * $maxRows_RS_Search_Results_Account;

$colname_RS_Search_Results_Account = "-1";
if (isset($_POST['Account_Name'])) {
$colname_RS_Search_Results_Account = $_POST['Account_Name'];
}
mysql_select_db($database_dbconnect, $dbconnect);
$query_RS_Search_Results_Account = sprintf("SELECT Account_ID, Account_Name, Salutation_Informal FROM accountinfo WHERE Account_Name = %s ORDER BY Account_Name ASC", GetSQLValueString($colname_RS_Search_Results_Account, "text"));
$query_limit_RS_Search_Results_Account = sprintf("%s LIMIT %d, %d", $query_RS_Search_Results_Account, $startRow_RS_Search_Results_Account, $maxRows_RS_Search_Results_Account);
$RS_Search_Results_Account = mysql_query($query_limit_RS_Search_Results_Account, $dbconnect) or die(mysql_error());
$row_RS_Search_Results_Account = mysql_fetch_assoc($RS_Search_Results_Account);

if (isset($_GET['totalRows_RS_Search_Results_Account'])) {
$totalRows_RS_Search_Results_Account = $_GET['totalRows_RS_Search_Results_Account'];
} else {
$all_RS_Search_Results_Account = mysql_query($query_RS_Search_Results_Account);
$totalRows_RS_Search_Results_Account = mysql_num_rows($all_RS_Search_Results_Account);
}
$totalPages_RS_Search_Results_Account = ceil($totalRows_RS_Search_Results_Account/$maxRows_RS_Search_Results_Account)-1;
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<!--THIS IS THE FORM THAT ALLOWS THE USER TO SELECT AN ACCOUNT NAME IN ORDER TO GENERATE THE SEARCH. THE PAGE RETURNS TO ITSELF AND THEN DISPLAYS A RESULTS TABLE BELOW -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="dropdownaccountname">
<Label>Select the Member's account name: </Label><select name="dropdownaccountlist" size="15">
<?php
do {
?>
<option value="<?php echo $row_rs_Populate_Dropdown['Account_Name']?>"><?php echo $row_rs_Populate_Dropdown['Account_Name']?></option>
<?php
} while ($row_rs_Populate_Dropdown = mysql_fetch_assoc($rs_Populate_Dropdown));
$rows = mysql_num_rows($rs_Populate_Dropdown);
if($rows > 0) {
mysql_data_seek($rs_Populate_Dropdown, 0);
$row_rs_Populate_Dropdown = mysql_fetch_assoc($rs_Populate_Dropdown);
}
?>
</select>
<input name="dropdown" type="submit" value="Search for Member">
</form>

<h1>Search Results</h1>
<p>Your results are displayed below: </p>
<table border="2" cellpadding="2" cellspacing="2">
<tr>
<td>Account ID</td>
<td>Account Name</td>
<td>First Name(s)</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_RS_Search_Results_Account['Account_ID']; ?></td>
<td><?php echo $row_RS_Search_Results_Account['Account_Name']; ?></td>
<td><?php echo $row_RS_Search_Results_Account['Salutation_Informal']; ?></td>
</tr>
<?php } while ($row_RS_Search_Results_Account = mysql_fetch_assoc($RS_Search_Results_Account)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($rs_Populate_Dropdown);
mysql_free_result($RS_Search_Results_Account);

?>





chaufournier
United States
Posts:1
Joined:Dec 05, 2012
  
Home About Contact Forum Youtube Privacy Policy
Copyright © 2009-2011 RiverCityGraphix.All Rights Reserved.