Link to home
Start Free TrialLog in
Avatar of digarati
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.
<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>

Open in new window

Avatar of ycgov
ycgov

I would suggest trying it with a checkboxlist so you can do:

HTML----
        <asp:CheckBoxList ID="checkboxlist" runat="server" Font-Names="Calibri" RepeatColumns="2"
                            Width="257px" Height="103px" ForeColor="White">
                            <asp:ListItem Value="2098">2098</asp:ListItem>
                            <asp:ListItem Value="2099">2099</asp:ListItem>
                            <asp:ListItem Value="2100">2100</asp:ListItem>
                        </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).Selected = True Then
                 if whereStr <> "" then
                    whereStr &= "  AND 2098 = " & 'VALUE HERE
                else
                    whereStr  = "WHERE 2098 = " & 'VALUE HERE
            End If
        Next
Avatar of digarati

ASKER

I like the idea of the list box.
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['searchfield']) as $f) {
   $searches = "$f = 'ON'";
}
$searchcondition = implode (' OR ', $searches);
$sql = "SELECT company_name FROm table WHERE $searchcondition";
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/username/html/beta/search/search.php on line 4

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>

Open in new window

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/username/html/beta/search/search.php on line 11
Avatar of hielo
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>

Open in new window

Can you post the code of search.php the html code looks good.
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";
?>

Open in new window

Sorry my mistake. Should be:
 $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>";

Open in new window

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/username/html/beta/search/search.php on line 18
<?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>";
?>

Open in new window

digarati, did you try my suggestion. It should work as is as long as you provide the corrent db info.
hielo your code is snipped
error:
Parse error: parse error, unexpected '{' in /home/content/h/a/l/username/html/beta/search/hielo.php on line 17
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>

Open in new window

Sorry. Misse a parenthesis here:
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());
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/username/html/beta/search/search.php on line 18
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>

Open in new window

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/username/html/beta/search/search.php on line 18
<?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>

Open in new window

this:
$idList = "'" . explode("','",$_POST['id']) . "'";

should be:
$idList = "'" . implode("','",$_POST['id']) . "'";
BTW: you need to replace {$tableName} with your actual tablename.
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/username/html/beta/search/search.php on line 18

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>

Open in new window

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/username/html/beta/search/hielo.php on line 25
echo "<div>" . $row['company'] . "</div>";
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.
apologies, it is company
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>";
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?
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>";
Updated code snipped
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";
?>

Open in new window

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
OK. update the following two lines as shown below (again, copy and paste from here):
      $idList = " OR `" . explode("`='ON'",$_POST['id']) . "'";
      $sql = "SELECT `company` FROM `{$tableName}` WHERE " . substr($idList,3);
Unknown column 'company' in 'field list'
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";
?>

Open in new window

This:
$idList = " OR `" . explode("`='ON'",$_POST['id']) . "'";

should be:
$idList = " OR `" . explode("`='ON'",$_POST['id']);
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.
SELECT `company` FROM `vendor` WHERE `ArrayUnknown column 'company' in 'field list'
Updated:

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.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for your time and solution. Looking forward to any future assistance you can provide to me, you are very knowledgable.
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
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'";