digarati
asked on
Checkbox Search Help
I have a search page (search.html) which is snipped.
I have a database with the following 12 Fields:
id (primary key)
company_name (Company Name)
a2098 (has value of ON or is null)
a2100 (has value of ON or is null)
a2500 (has value of ON or is null)
a2510 (has value of ON or is null)
a2550 (has value of ON or is null)
a2610 (has value of ON or is null)
a2620 (has value of ON or is null)
a2710 (has value of ON or is null)
a2750 (has value of ON or is null)
a2800 (has value of ON or is null)
I am trying to create a search function that will query the database based on the search.html checkboxes and echo company_name if values exist for that record.
Example:
From search.html i will check the box 2098
The database contains one record with 2098 having the value of ON
I would like for my search to echo the company_name when queried.
I have a database with the following 12 Fields:
id (primary key)
company_name (Company Name)
a2098 (has value of ON or is null)
a2100 (has value of ON or is null)
a2500 (has value of ON or is null)
a2510 (has value of ON or is null)
a2550 (has value of ON or is null)
a2610 (has value of ON or is null)
a2620 (has value of ON or is null)
a2710 (has value of ON or is null)
a2750 (has value of ON or is null)
a2800 (has value of ON or is null)
I am trying to create a search function that will query the database based on the search.html checkboxes and echo company_name if values exist for that record.
Example:
From search.html i will check the box 2098
The database contains one record with 2098 having the value of ON
I would like for my search to echo the company_name when queried.
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search</title>
</head>
<body>
<form method="POST" action="search.php">
<table border="0" width="100%" id="table1">
<tr>
<td colspan="3">
<p align="center"><font size="4">Database Search</font></td>
</tr>
<tr>
<td width="42">2098</td>
<td width="118">Sheet Piling</td>
<td><input type="checkbox" name="a2098" value="ON"></td>
</tr>
<tr>
<td width="42">2100</td>
<td width="118">Exc./Grade/Clear</td>
<td><input type="checkbox" name="a2100" value="ON"></td>
</tr>
<tr>
<td width="42">2500</td>
<td width="118">Site Drainage</td>
<td><input type="checkbox" name="a2500" value="ON"></td>
</tr>
<tr>
<td width="42">2510</td>
<td width="118">Walks</td>
<td><input type="checkbox" name="a2510" value="ON"></td>
</tr>
<tr>
<td width="42" height="24">2550</td>
<td height="24" width="118">Site Utilities</td>
<td height="24"><input type="checkbox" name="a2550" value="ON"></td>
</tr>
<tr>
<td width="42">2610</td>
<td width="118">Concrete Paving</td>
<td><input type="checkbox" name="a2610" value="ON"></td>
</tr>
<tr>
<td width="42">2620</td>
<td width="118">Curb/Gutter</td>
<td><input type="checkbox" name="a2620" value="ON"></td>
</tr>
<tr>
<td width="42">2710</td>
<td width="118">Fence/Gates</td>
<td><input type="checkbox" name="a2710" value="ON"></td>
</tr>
<tr>
<td width="42">2750</td>
<td width="118">Irrigation</td>
<td><input type="checkbox" name="a2750" value="ON"></td>
</tr>
<tr>
<td width="42">2800</td>
<td width="118">Landscape</td>
<td><input type="checkbox" name="a2800" value="ON"></td>
</tr>
</table>
<input type="submit" value="Search" name="search"></body>
</html>
ASKER
I like the idea of the list box.
How can you do this with php my hosting company is LINUX
How can you do this with php my hosting company is LINUX
1st I would name the checkboxes different. use searchfield[id] like
<input type="checkbox" name="searchfield[a2800]" value="ON">
The in PHP you can realy easy build the query like this:
if (empty($_POST['searchfield '])) {
echo "you didn't check a box for search";
}
$searches = array();
foreach (array_keys($_POST['search field']) as $f) {
$searches = "$f = 'ON'";
}
$searchcondition = implode (' OR ', $searches);
$sql = "SELECT company_name FROm table WHERE $searchcondition";
<input type="checkbox" name="searchfield[a2800]" value="ON">
The in PHP you can realy easy build the query like this:
if (empty($_POST['searchfield
echo "you didn't check a box for search";
}
$searches = array();
foreach (array_keys($_POST['search
$searches = "$f = 'ON'";
}
$searchcondition = implode (' OR ', $searches);
$sql = "SELECT company_name FROm table WHERE $searchcondition";
ASKER
hernst42 you seem to be in my direction.
snipped is my updated html search file.
When i perform the search i am getting:
Parse error: parse error, unexpected T_IF in /home/content/h/a/l/userna me/html/be ta/search/ search.php on line 4
Can you assist me further?
snipped is my updated html search file.
When i perform the search i am getting:
Parse error: parse error, unexpected T_IF in /home/content/h/a/l/userna
Can you assist me further?
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search</title>
</head>
<body>
<form method="POST" action="search.php">
<table border="0" width="100%" id="table1">
<tr>
<td colspan="3">
<p align="center"><font size="4">Database Search</font></td>
</tr>
<tr>
<td width="42">2098</td>
<td width="118">Sheet Piling</td>
<td><input type="checkbox" name="searchfield[a2098]" value="ON"></td>
</tr>
<tr>
<td width="42">2100</td>
<td width="118">Exc./Grade/Clear</td>
<td><input type="checkbox" name="searchfield[a2100]" value="ON"></td>
</tr>
<tr>
<td width="42">2500</td>
<td width="118">Site Drainage</td>
<td><input type="checkbox" name="searchfield[a2500]" value="ON"></td>
</tr>
<tr>
<td width="42">2510</td>
<td width="118">Walks</td>
<td><input type="checkbox" name="searchfield[a2510]" value="ON"></td>
</tr>
<tr>
<td width="42" height="24">2550</td>
<td height="24" width="118">Site Utilities</td>
<td height="24"><input type="checkbox" name="searchfield[a2550]" value="ON"></td>
</tr>
<tr>
<td width="42">2610</td>
<td width="118">Concrete Paving</td>
<td><input type="checkbox" name="searchfield[a2610]" value="ON"></td>
</tr>
<tr>
<td width="42">2620</td>
<td width="118">Curb/Gutter</td>
<td><input type="checkbox" name="searchfield[a2620]" value="ON"></td>
</tr>
<tr>
<td width="42">2710</td>
<td width="118">Fence/Gates</td>
<td><input type="checkbox" name="searchfield[a2710]" value="ON"></td>
</tr>
<tr>
<td width="42">2750</td>
<td width="118">Irrigation</td>
<td><input type="checkbox" name="searchfield[a2750]" value="ON"></td>
</tr>
<tr>
<td width="42">2800</td>
<td width="118">Landscape</td>
<td><input type="checkbox" name="searchfield[a2800]" value="ON"></td>
</tr>
</table>
<input type="submit" value="Search" name="search"></body>
</html>
ASKER
sorry was missing a semicolon on my DB connection.
here is my current error when i run the search:
Warning: implode(): Bad arguments. in /home/content/h/a/l/userna me/html/be ta/search/ search.php on line 11
here is my current error when i run the search:
Warning: implode(): Bad arguments. in /home/content/h/a/l/userna
My suggestion is to give all your fields the same name. What you originally had as name would actually be the value of the checkboxes, and all the checkboxes would have the same name="id[]". That way you can easily access the data as an array. Save the attched code as hielo.php, provide the correct db info and try it.
<?php
$dbserver="localhost";
$username="John";
$password="testing";
$dbname="products";
$tableName="table1";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search</title>
</head>
<body>
<div>
<?php
if( isset($_POST['search'])
{
// we connect to example.com and port 3307
$link = mysql_connect($dbserver, $dbusername, $dbpassword);
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($dbname, $link);
if (!$db_selected){
die ("Can't use {$dbname} : " . mysql_error());
}
$idList = "'" . explode("','",$_POST['id']) . "'";
$sql = "SELECT `company_name` FROM `{$tableName}` WHERE `id` IN ({$idList})";
$result = mysql_query(sql) or die(mysql_error());
if( 0 < mysql_num_rows($result) )
{
while( $row = mysql_fetch_assoc($result) )
{
echo "<div>$row['company_name']</div>";
}
}
else
echo "<div>No matching records found.</div>";
}
?>
</div>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<table border="0" width="100%" id="table1">
<tr>
<td colspan="3">
<p align="center"><font size="4">Database Search</font></td>
</tr>
<tr>
<td width="42">2098</td>
<td width="118">Sheet Piling</td>
<td><input type="checkbox" value="a2098" name="id[]"></td>
</tr>
<tr>
<td width="42">2100</td>
<td width="118">Exc./Grade/Clear</td>
<td><input type="checkbox" value="a2100" name="id[]"></td>
</tr>
<tr>
<td width="42">2500</td>
<td width="118">Site Drainage</td>
<td><input type="checkbox" value="a2500" name="id[]"></td>
</tr>
<tr>
<td width="42">2510</td>
<td width="118">Walks</td>
<td><input type="checkbox" value="a2510" name="id[]"></td>
</tr>
<tr>
<td width="42" height="24">2550</td>
<td height="24" width="118">Site Utilities</td>
<td height="24"><input type="checkbox" value="a2550" name="id[]"></td>
</tr>
<tr>
<td width="42">2610</td>
<td width="118">Concrete Paving</td>
<td><input type="checkbox" value="a2610" name="id[]"></td>
</tr>
<tr>
<td width="42">2620</td>
<td width="118">Curb/Gutter</td>
<td><input type="checkbox" value="a2620" name="id[]"></td>
</tr>
<tr>
<td width="42">2710</td>
<td width="118">Fence/Gates</td>
<td><input type="checkbox" value="a2710" name="id[]"></td>
</tr>
<tr>
<td width="42">2750</td>
<td width="118">Irrigation</td>
<td><input type="checkbox" value="a2750" name="id[]"></td>
</tr>
<tr>
<td width="42">2800</td>
<td width="118">Landscape</td>
<td><input type="checkbox" value="a2800" name="id[]"></td>
</tr>
</table>
<input type="submit" value="Search" name="search">
</form>
</body>
</html>
Can you post the code of search.php the html code looks good.
ASKER
search.php is snipped:
<?
require_once "dbconnection.php";
if (empty($_POST['searchfield'])) {
echo "you didn't check a box for search";
}
$searches = array();
foreach (array_keys($_POST['searchfield']) as $f) {
$searches = "$f = 'ON'";
}
$searchcondition = implode (' OR ', $searches);
$sql = "SELECT company FROM scope WHERE $searchcondition";
?>
Sorry my mistake. Should be:
$searches[] = "$f = 'ON'";
Attached code with merge of hielo's output code
$searches[] = "$f = 'ON'";
Attached code with merge of hielo's output code
require_once "dbconnection.php";
if (empty($_POST['searchfield'])) {
echo "you didn't check a box for search";
}
$searches = array();
foreach (array_keys($_POST['searchfield']) as $f) {
$searches[] = "$f = 'ON'";
}
$searchcondition = implode (' OR ', $searches);
$sql = "SELECT company FROM scope WHERE $searchcondition";
$result = mysql_query($sql) or die(mysql_error());
if( 0 < mysql_num_rows($result) )
{
while( ($row = mysql_fetch_assoc($result)) !== false )
{
echo "<div>$row['company_name']</div>";
}
}
else
echo "<div>No matching records found.</div>";
ASKER
hernst42
code is snipped
error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/h/a/l/userna me/html/be ta/search/ search.php on line 18
code is snipped
error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
<?require_once "dbconnection.php";
if (empty($_POST['searchfield'])) {
echo "you didn't check a box for search";
}
$searches = array();
foreach (array_keys($_POST['searchfield']) as $f) {
$searches[] = "$f = 'ON'";
}
$searchcondition = implode (' OR ', $searches);
$sql = "SELECT company FROM scope WHERE $searchcondition";
$result = mysql_query($sql) or die(mysql_error());
if( 0 < mysql_num_rows($result) )
{
while( ($row = mysql_fetch_assoc($result)) !== false )
{
echo "<div>$row['company']</div>";
}
}
else
echo "<div>No matching records found.</div>";
?>
digarati, did you try my suggestion. It should work as is as long as you provide the corrent db info.
ASKER
hielo your code is snipped
error:
Parse error: parse error, unexpected '{' in /home/content/h/a/l/userna me/html/be ta/search/ hielo.php on line 17
error:
Parse error: parse error, unexpected '{' in /home/content/h/a/l/userna
ASKER
sorry failed to attach code:
<?php
require_once "dbconnection.php";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search</title>
</head>
<body>
<div>
<?php
if( isset($_POST['search'])
{
// we connect to example.com and port 3307
$link = mysql_connect($dbserver, $dbusername, $dbpassword);
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($dbname, $link);
if (!$db_selected){
die ("Can't use {$dbname} : " . mysql_error());
}
$idList = "'" . explode("','",$_POST['id']) . "'";
$sql = "SELECT `company` FROM `{$tableName}` WHERE `id` IN ({$idList})";
$result = mysql_query(sql) or die(mysql_error());
if( 0 < mysql_num_rows($result) )
{
while( $row = mysql_fetch_assoc($result) )
{
echo "<div>$row['company']</div>";
}
}
else
echo "<div>No matching records found.</div>";
}
?>
</div>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<table border="0" width="100%" id="table1">
<tr>
<td colspan="3">
<p align="center"><font size="4">Database Search</font></td>
</tr>
<tr>
<td width="42">2098</td>
<td width="118">Sheet Piling</td>
<td><input type="checkbox" value="a2098" name="id[]"></td>
</tr>
<tr>
<td width="42">2100</td>
<td width="118">Exc./Grade/Clear</td>
<td><input type="checkbox" value="a2100" name="id[]"></td>
</tr>
<tr>
<td width="42">2500</td>
<td width="118">Site Drainage</td>
<td><input type="checkbox" value="a2500" name="id[]"></td>
</tr>
<tr>
<td width="42">2510</td>
<td width="118">Walks</td>
<td><input type="checkbox" value="a2510" name="id[]"></td>
</tr>
<tr>
<td width="42" height="24">2550</td>
<td height="24" width="118">Site Utilities</td>
<td height="24"><input type="checkbox" value="a2550" name="id[]"></td>
</tr>
<tr>
<td width="42">2610</td>
<td width="118">Concrete Paving</td>
<td><input type="checkbox" value="a2610" name="id[]"></td>
</tr>
<tr>
<td width="42">2620</td>
<td width="118">Curb/Gutter</td>
<td><input type="checkbox" value="a2620" name="id[]"></td>
</tr>
<tr>
<td width="42">2710</td>
<td width="118">Fence/Gates</td>
<td><input type="checkbox" value="a2710" name="id[]"></td>
</tr>
<tr>
<td width="42">2750</td>
<td width="118">Irrigation</td>
<td><input type="checkbox" value="a2750" name="id[]"></td>
</tr>
<tr>
<td width="42">2800</td>
<td width="118">Landscape</td>
<td><input type="checkbox" value="a2800" name="id[]"></td>
</tr>
</table>
<input type="submit" value="Search" name="search">
</form>
</body>
</html>
Sorry. Misse a parenthesis here:
if( isset($_POST['search'])
should be:
if( isset($_POST['search']) )
if( isset($_POST['search'])
should be:
if( isset($_POST['search']) )
and also a $ sign infront of sql here:
$result = mysql_query(sql) or die(mysql_error());
should be:
$result = mysql_query($sql) or die(mysql_error());
$result = mysql_query(sql) or die(mysql_error());
should be:
$result = mysql_query($sql) or die(mysql_error());
ASKER
hielo
getting this error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/h/a/l/userna me/html/be ta/search/ search.php on line 18
getting this error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
since you have a dbconnection.php file, use the attached code instead (copy and paste from attached code)
<?php
require_once "dbconnection.php";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search</title>
</head>
<body>
<div>
<?php
if( isset($_POST['search']) )
{
$idList = "'" . explode("','",$_POST['id']) . "'";
$sql = "SELECT `company` FROM `{$tableName}` WHERE `id` IN ({$idList})";
$result = mysql_query($sql) or die(mysql_error());
if( 0 < mysql_num_rows($result) )
{
while( $row = mysql_fetch_assoc($result) )
{
echo "<div>$row['company']</div>";
}
}
else
echo "<div>No matching records found.</div>";
}
?>
</div>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<table border="0" width="100%" id="table1">
<tr>
<td colspan="3">
<p align="center"><font size="4">Database Search</font></td>
</tr>
<tr>
<td width="42">2098</td>
<td width="118">Sheet Piling</td>
<td><input type="checkbox" value="a2098" name="id[]"></td>
</tr>
<tr>
<td width="42">2100</td>
<td width="118">Exc./Grade/Clear</td>
<td><input type="checkbox" value="a2100" name="id[]"></td>
</tr>
<tr>
<td width="42">2500</td>
<td width="118">Site Drainage</td>
<td><input type="checkbox" value="a2500" name="id[]"></td>
</tr>
<tr>
<td width="42">2510</td>
<td width="118">Walks</td>
<td><input type="checkbox" value="a2510" name="id[]"></td>
</tr>
<tr>
<td width="42" height="24">2550</td>
<td height="24" width="118">Site Utilities</td>
<td height="24"><input type="checkbox" value="a2550" name="id[]"></td>
</tr>
<tr>
<td width="42">2610</td>
<td width="118">Concrete Paving</td>
<td><input type="checkbox" value="a2610" name="id[]"></td>
</tr>
<tr>
<td width="42">2620</td>
<td width="118">Curb/Gutter</td>
<td><input type="checkbox" value="a2620" name="id[]"></td>
</tr>
<tr>
<td width="42">2710</td>
<td width="118">Fence/Gates</td>
<td><input type="checkbox" value="a2710" name="id[]"></td>
</tr>
<tr>
<td width="42">2750</td>
<td width="118">Irrigation</td>
<td><input type="checkbox" value="a2750" name="id[]"></td>
</tr>
<tr>
<td width="42">2800</td>
<td width="118">Landscape</td>
<td><input type="checkbox" value="a2800" name="id[]"></td>
</tr>
</table>
<input type="submit" value="Search" name="search">
</form>
</body>
</html>
ASKER
hielo using snipped code with
error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/h/a/l/userna me/html/be ta/search/ search.php on line 18
error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
<?php
require_once "dbconnection.php";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search</title>
</head>
<body>
<div>
<?php
if( isset($_POST['search']) )
{
$idList = "'" . explode("','",$_POST['id']) . "'";
$sql = "SELECT `company` FROM `{$tableName}` WHERE `id` IN ({$idList})";
$result = mysql_query($sql) or die(mysql_error());
if( 0 < mysql_num_rows($result) )
{
while( $row = mysql_fetch_assoc($result) )
{
echo "<div>$row['company']</div>";
}
}
else
echo "<div>No matching records found.</div>";
}
?>
</div>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<table border="0" width="100%" id="table1">
<tr>
<td colspan="3">
<p align="center"><font size="4">Database Search</font></td>
</tr>
<tr>
<td width="42">2098</td>
<td width="118">Sheet Piling</td>
<td><input type="checkbox" value="a2098" name="id[]"></td>
</tr>
<tr>
<td width="42">2100</td>
<td width="118">Exc./Grade/Clear</td>
<td><input type="checkbox" value="a2100" name="id[]"></td>
</tr>
<tr>
<td width="42">2500</td>
<td width="118">Site Drainage</td>
<td><input type="checkbox" value="a2500" name="id[]"></td>
</tr>
<tr>
<td width="42">2510</td>
<td width="118">Walks</td>
<td><input type="checkbox" value="a2510" name="id[]"></td>
</tr>
<tr>
<td width="42" height="24">2550</td>
<td height="24" width="118">Site Utilities</td>
<td height="24"><input type="checkbox" value="a2550" name="id[]"></td>
</tr>
<tr>
<td width="42">2610</td>
<td width="118">Concrete Paving</td>
<td><input type="checkbox" value="a2610" name="id[]"></td>
</tr>
<tr>
<td width="42">2620</td>
<td width="118">Curb/Gutter</td>
<td><input type="checkbox" value="a2620" name="id[]"></td>
</tr>
<tr>
<td width="42">2710</td>
<td width="118">Fence/Gates</td>
<td><input type="checkbox" value="a2710" name="id[]"></td>
</tr>
<tr>
<td width="42">2750</td>
<td width="118">Irrigation</td>
<td><input type="checkbox" value="a2750" name="id[]"></td>
</tr>
<tr>
<td width="42">2800</td>
<td width="118">Landscape</td>
<td><input type="checkbox" value="a2800" name="id[]"></td>
</tr>
</table>
<input type="submit" value="Search" name="search">
</form>
</body>
</html>
this:
$idList = "'" . explode("','",$_POST['id'] ) . "'";
should be:
$idList = "'" . implode("','",$_POST['id'] ) . "'";
$idList = "'" . explode("','",$_POST['id']
should be:
$idList = "'" . implode("','",$_POST['id']
BTW: you need to replace {$tableName} with your actual tablename.
ASKER
hielo:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/h/a/l/userna me/html/be ta/search/ search.php on line 18
code snipped
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
code snipped
<?php
require_once "dbconnection.php";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search</title>
</head>
<body>
<div>
<?php
if( isset($_POST['search']) )
{
$idList = "'" . implode("','",$_POST['id']) . "'";
$sql = "SELECT `company` FROM `{$tableName}` WHERE `id` IN ({$idList})";
$result = mysql_query($sql) or die(mysql_error());
if( 0 < mysql_num_rows($result) )
{
while( $row = mysql_fetch_assoc($result) )
{
echo "<div>$row['company']</div>";
}
}
else
echo "<div>No matching records found.</div>";
}
?>
</div>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<table border="0" width="100%" id="table1">
<tr>
<td colspan="3">
<p align="center"><font size="4">Database Search</font></td>
</tr>
<tr>
<td width="42">2098</td>
<td width="118">Sheet Piling</td>
<td><input type="checkbox" value="a2098" name="id[]"></td>
</tr>
<tr>
<td width="42">2100</td>
<td width="118">Exc./Grade/Clear</td>
<td><input type="checkbox" value="a2100" name="id[]"></td>
</tr>
<tr>
<td width="42">2500</td>
<td width="118">Site Drainage</td>
<td><input type="checkbox" value="a2500" name="id[]"></td>
</tr>
<tr>
<td width="42">2510</td>
<td width="118">Walks</td>
<td><input type="checkbox" value="a2510" name="id[]"></td>
</tr>
<tr>
<td width="42" height="24">2550</td>
<td height="24" width="118">Site Utilities</td>
<td height="24"><input type="checkbox" value="a2550" name="id[]"></td>
</tr>
<tr>
<td width="42">2610</td>
<td width="118">Concrete Paving</td>
<td><input type="checkbox" value="a2610" name="id[]"></td>
</tr>
<tr>
<td width="42">2620</td>
<td width="118">Curb/Gutter</td>
<td><input type="checkbox" value="a2620" name="id[]"></td>
</tr>
<tr>
<td width="42">2710</td>
<td width="118">Fence/Gates</td>
<td><input type="checkbox" value="a2710" name="id[]"></td>
</tr>
<tr>
<td width="42">2750</td>
<td width="118">Irrigation</td>
<td><input type="checkbox" value="a2750" name="id[]"></td>
</tr>
<tr>
<td width="42">2800</td>
<td width="118">Landscape</td>
<td><input type="checkbox" value="a2800" name="id[]"></td>
</tr>
</table>
<input type="submit" value="Search" name="search">
</form>
</body>
</html>
ASKER
new error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/h/a/l/userna me/html/be ta/search/ hielo.php on line 25
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
echo "<div>" . $row['company'] . "</div>";
ASKER
Unknown column 'company' in 'field list'
OK, my question to you is what id the name of your fields on your table. My initial query was
SELECT company_name...
but you changed it to:
SELECT company...
So, what is it? You need to use the correct field name. I don't know what it is. I don't know how your db table is defined. You should know that.
SELECT company_name...
but you changed it to:
SELECT company...
So, what is it? You need to use the correct field name. I don't know what it is. I don't know how your db table is defined. You should know that.
apologies, it is company
ASKER
i am so sorry my primary key is called "key" instead of ID
:(
:(
OK, then modify your sql accordingly (assuming the company name is in the field comapany, you will need)::
$sql = "SELECT `company` FROM `{$tableName}` WHERE `key` IN ({$idList})";
and
echo "<div>" . $row['company'] . "</div>";
$sql = "SELECT `company` FROM `{$tableName}` WHERE `key` IN ({$idList})";
and
echo "<div>" . $row['company'] . "</div>";
ASKER
OK almost there:
it tells me theres no results, however i have logged into the database and know results exist for these entries...any ideas?
it tells me theres no results, however i have logged into the database and know results exist for these entries...any ideas?
what does your table look like this:
key company
1 a2098
2 a2100
OR like this:
key company
a2098 Alpha
a2100 Beta
The query I gave if you is for the second example. If your table looks like the first then you need:
$sql = "SELECT `key` FROM `{$tableName}` WHERE `company` IN ({$idList})";
and
echo "<div>" . $row['key'] . "</div>";
key company
1 a2098
2 a2100
OR like this:
key company
a2098 Alpha
a2100 Beta
The query I gave if you is for the second example. If your table looks like the first then you need:
$sql = "SELECT `key` FROM `{$tableName}` WHERE `company` IN ({$idList})";
and
echo "<div>" . $row['key'] . "</div>";
ASKER
Updated code snipped
My results:
No matching records found.
You search: 'a2620'
My results:
No matching records found.
You search: 'a2620'
<?php
require_once "dbconnection.php";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search</title>
</head>
<body>
<div>
<?php
if( isset($_POST['search']) )
{
$idList = "'" . implode("','",$_POST['id']) . "'";
$sql = "SELECT `company` FROM `scope` WHERE `key` IN ({$idList})";
$result = mysql_query($sql) or die(mysql_error());
if( 0 < mysql_num_rows($result) )
{
while( $row = mysql_fetch_assoc($result) )
{
echo "<div>" . $row['company'] . "</div>";
}
}
else
echo "<div>No matching records found.</div>";
}
echo "You search: $idList";
?>
ASKER
not sure how we strayed here, ill go ahead and take the wrap since ima newbie but
my table looks like this:
key company a2098 a2100 a2500 a2510 a2550 a2610 a2620 a2710 a2750 a2800
1 mcompany ON ON ON
2 anothername ON ON
3 billscompany ON ON
4 tomscompany ON
5 george ON ON
my table looks like this:
key company a2098 a2100 a2500 a2510 a2550 a2610 a2620 a2710 a2750 a2800
1 mcompany ON ON ON
2 anothername ON ON
3 billscompany ON ON
4 tomscompany ON
5 george ON ON
OK. update the following two lines as shown below (again, copy and paste from here):
$idList = " OR `" . explode("`='ON'",$_POST['i d']) . "'";
$sql = "SELECT `company` FROM `{$tableName}` WHERE " . substr($idList,3);
$idList = " OR `" . explode("`='ON'",$_POST['i
$sql = "SELECT `company` FROM `{$tableName}` WHERE " . substr($idList,3);
ASKER
Unknown column 'company' in 'field list'
ASKER
btw code snipped
<?php
if( isset($_POST['search']) )
{
$idList = " OR `" . explode("`='ON'",$_POST['id']) . "'";
$sql = "SELECT `company` FROM `vendor` WHERE " . substr($idList,3);
$result = mysql_query($sql) or die(mysql_error());
if( 0 < mysql_num_rows($result) )
{
while( $row = mysql_fetch_assoc($result) )
{
echo "<div>" . $row['company'] . "</div>";
}
}
else
echo "<div>No matching records found.</div>";
}
echo "You searched: $idList";
?>
This:
$idList = " OR `" . explode("`='ON'",$_POST['i d']) . "'";
should be:
$idList = " OR `" . explode("`='ON'",$_POST['i d']);
$idList = " OR `" . explode("`='ON'",$_POST['i
should be:
$idList = " OR `" . explode("`='ON'",$_POST['i
ASKER
hielo i have the same result
right before:
$result = mysql_query($sql) or die(mysql_error());
put:
echo $sql;
and report with the output. Also make sure you have the correct fieldname on your db.
$result = mysql_query($sql) or die(mysql_error());
put:
echo $sql;
and report with the output. Also make sure you have the correct fieldname on your db.
ASKER
SELECT `company` FROM `vendor` WHERE `ArrayUnknown column 'company' in 'field list'
ASKER
Updated:
SELECT `company` FROM `scope` WHERE `Array'Unknown column 'Array'' in 'where clause'
SELECT `company` FROM `scope` WHERE `Array'Unknown column 'Array'' in 'where clause'
At this point I don't know what you are doing. You wrote:
SELECT `company` FROM `scope`
and then you wrote:
SELECT `company` FROM `vendor`
could be your table name, but the point is that you are not paying attentiont to what you are doing.
SELECT `company` FROM `scope`
and then you wrote:
SELECT `company` FROM `vendor`
could be your table name, but the point is that you are not paying attentiont to what you are doing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your time and solution. Looking forward to any future assistance you can provide to me, you are very knowledgable.
ASKER
one thing, when i select more than 1 checkbox it gives me this:
SELECT `company` FROM `scope` WHERE `a2710`='ON' OR a2750`='ON'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`='ON'' at line 1
SELECT `company` FROM `scope` WHERE `a2710`='ON' OR a2750`='ON'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`='ON'' at line 1
ASKER
seems to be missing back ticks (`) for each or statement....
>>seems to be missing back ticks (`) for each or statement
Oops. should have been:
$idList = "`" . implode("`='ON' OR `",$_POST['id']) . "`='ON'";
Oops. should have been:
$idList = "`" . implode("`='ON' OR `",$_POST['id']) . "`='ON'";
HTML----
<asp:CheckBoxList ID="checkboxlist" runat="server" Font-Names="Calibri" RepeatColumns="2"
Width="257px" Height="103px" ForeColor="White">
<asp:ListItem Value="2098">2098</asp:Lis
<asp:ListItem Value="2099">2099</asp:Lis
<asp:ListItem Value="2100">2100</asp:Lis
</asp:CheckBoxList>
VB.NET -
Dim qryStr as String = "SELECT * FROM tableName"
Dim whereStr as String = ""
For i As Integer = 0 To checkboxlist.Items.Count - 1
If checkboxlist.Items(i).Sele
if whereStr <> "" then
whereStr &= " AND 2098 = " & 'VALUE HERE
else
whereStr = "WHERE 2098 = " & 'VALUE HERE
End If
Next