> name=\"image_type[]\"> > name=\"subject[]\"> > name=\"extension[]\"> > name=\"image_type[]\"> > name=\"subject[]\"> > name=\"extension[]\"> > name=\"image_type[]\"> > name=\"subject[]\"> > name=\"extension[]\"> > name=\"image_type[]\"> > name=\"subject[]\"> > name=\"extension[]\"> > name=\"image_type[]\"> > name=\"subject[]\"> > name=\"extension[]\"> > name=\"subject[]\"> > name=\"extension[]\"> > name=\"subject[]\"> > name=\"subject[]\"> > > > > > value=\"Clear\"> > > > "; > > } else > // if($_POST['op'] == "search") > {//connect to database > $conn = mysql_connect("localhost", "odbc","") or die("Unable > to connect.".mysql_error()); > > mysql_select_db("shcimages",$conn) or die("Unable to access > the db.".mysql_error()); > > $searchstring = $_POST['search_words']; > > $num_ext=count($_POST['extension']); > print "$num_ext num_ext
";//a test to try to identify > problem > if ($num_ext==1){ > $ext_type="'".$_POST['extension']."'"; > }elseif ($num_ext>1){ > for ($x=0;$x<$num_ext;$x++){ > if ($x==0){ > //first element so no comma separator needed > $ext_type.="'".$_POST['extension']."'"; > }else{ > //add the comma separator > $ext_type.=",'".$_POST['extension']."'"; > print "$ext_type ext_type
"; > } //close if then > }//close for loop > }else{ > //no elements so set to "na" > $ext_type="na"; > } > print "$x x value
"; > print "$ext_type ext_type
"; > > $num_img=count($_POST['image_type']); > print "$num_img num_img
";//a test to try to identify > problem > if ($num_img==1){ > $img_type="'".$_POST['image_type']."'"; > }elseif ($num_img>1){ > for ($y=0;$y<$num_img;$y++){ > if ($y==0){ > //first element so no comma separator needed > $img_type.="'".$_POST['image_type']."'"; > }else{ > //add the comma separator > $img_type.=",'".$_POST['image_type']."'"; > print "$img_type img_type
"; > } //close if then > }//close for loop > }else{ > //no elements so set to "na" > $img_type="na"; > } > print "$y y value
"; > print "$img_type img_type
"; > > > $num_sub=count($_POST['subject']); > print "$num_sub num_sub
"; > if ($num_sub==1){ > $sub_type="'".$_POST['subject']."'"; > }elseif ($num_sub>1){ > for ($z=0;$z<$num_sub;$z++){ > if ($z==0){ > //first element so no comma separator needed > $sub_type.="'".$_POST['subject']."'"; > }else{ > //add the comma separator > $sub_type.=",'".$_POST['subject']."'"; > print "$sub_type sub_type
"; > } //close if then > }//close for loop > }else{ > //no elements so set to "na" > $sub_type="na"; > } > print "$z z value
"; > print "$sub_type sub_type
"; > > > > //$query1 = "SELECT id FROM image_info WHERE (image_type IN > ('".$img_type."')) > //AND > //(subject IN ('".$sub_type."')) AND (extension IN > ('".$ext_type."'))"; > > > //build the query dynamically > $query1="select id from image_info where"; > > //if img_type optional - then check for it and use if needed > if ($img_type!="na"){ > $query1.=" image_type in ('".$img_type."')"; > } > > //if sub_type optional - check for it and check if others are > set for and clause > if (($sub_type!="na")&&($img_type!="na")){ //img_type is set > $query1.=" and subject in ('".$sub_type."')"; > > }else{ > $query1.=" subject in ('".$sub_type."')"; > } > > //if ext_type optional - check for it and check if others are > set for and clause > > if > (($ext_type!="na")&&(($sub_type!="na")||($img_type!="na"))){ > //sub_type or img_type is set > $query1.=" and extension in ('".$ext_type."')"; > > }else{ > $query1.=" extension in ('".$ext_type."')"; > } > echo "$query1
"; > > $results1 = mysql_query($query1) or die ("Could not execute > query1. ".mysql_error()); > > //This returns an array holding all keywords, delimited by > commas > $the_search = explode(",",$searchstring); > for ($s=0; $s { > if ($s==0) > { > $search_item="'%".strtolower(trim($the_search[$s]))."%'"; > }else > { > $search_item=",'%".strtolower(trim($the_search[$s]))."%'"; > } > } > $query2 = "SELECT master_id FROM keyword WHERE (keywords IN > ('".$search_item."'))"; > $results2 = mysql_query($query2) or die ("Could not execute > query2".mysql_error()); > > $query3 = "SELECT image_location FROM image_info WHERE > $results1 = $results2"; > $results3 = mysql_query($query3) or die ("Could not execute > query3".mysql_error()); > > if ($myrow = mysql_fetch_array($results3,MYSQL_ASSOC)) { > > do { > > printf ("Image_location: %s", $myrow["image_location"]); > > } while ($myrow = mysql_fetch_array($results3,MYSQL_ASSOC)); > } else { > $display_block= "Sorry, no records were found!"; > } > } > ?> > > > Image Search > > > print $display_block; ?> > ">??
?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

?
?Re: keywords, checkbox array search



























";

} else
// if($_POST['op'] == "search")
{//connect to database
$conn = mysql_connect("localhost", "odbc","") or die("Unable to connect.".mysql_error());

mysql_select_db("shcimages",$conn) or die("Unable to access the db.".mysql_error());

$searchstring = $_POST['search_words'];

$num_ext=count($_POST['extension']);
print "$num_ext num_ext
";//a test to try to identify problem
if ($num_ext==1){
$ext_type="'".$_POST['extension']."'";
}elseif ($num_ext>1){
for ($x=0;$x<$num_ext;$x++){
if ($x==0){
//first element so no comma separator needed
$ext_type.="'".$_POST['extension']."'";
}else{
//add the comma separator
$ext_type.=",'".$_POST['extension']."'";
print "$ext_type ext_type
";
} //close if then
}//close for loop
}else{
//no elements so set to "na"
$ext_type="na";
}
print "$x x value
";
print "$ext_type ext_type
";

$num_img=count($_POST['image_type']);
print "$num_img num_img
";//a test to try to identify problem
if ($num_img==1){
$img_type="'".$_POST['image_type']."'";
}elseif ($num_img>1){
for ($y=0;$y<$num_img;$y++){
if ($y==0){
//first element so no comma separator needed
$img_type.="'".$_POST['image_type']."'";
}else{
//add the comma separator
$img_type.=",'".$_POST['image_type']."'";
print "$img_type img_type
";
} //close if then
}//close for loop
}else{
//no elements so set to "na"
$img_type="na";
}
print "$y y value
";
print "$img_type img_type
";


$num_sub=count($_POST['subject']);
print "$num_sub num_sub
";
if ($num_sub==1){
$sub_type="'".$_POST['subject']."'";
}elseif ($num_sub>1){
for ($z=0;$z<$num_sub;$z++){
if ($z==0){
//first element so no comma separator needed
$sub_type.="'".$_POST['subject']."'";
}else{
//add the comma separator
$sub_type.=",'".$_POST['subject']."'";
print "$sub_type sub_type
";
} //close if then
}//close for loop
}else{
//no elements so set to "na"
$sub_type="na";
}
print "$z z value
";
print "$sub_type sub_type
";



//$query1 = "SELECT id FROM image_info WHERE (image_type IN ('".$img_type."'))
//AND
//(subject IN ('".$sub_type."')) AND (extension IN ('".$ext_type."'))";


//build the query dynamically
$query1="select id from image_info where";

//if img_type optional - then check for it and use if needed
if ($img_type!="na"){
$query1.=" image_type in ('".$img_type."')";
}

//if sub_type optional - check for it and check if others are set for and clause
if (($sub_type!="na")&&($img_type!="na")){ //img_type is set
$query1.=" and subject in ('".$sub_type."')";

}else{
$query1.=" subject in ('".$sub_type."')";
}

//if ext_type optional - check for it and check if others are set for and clause

if (($ext_type!="na")&&(($sub_type!="na")||($img_type!="na"))){
//sub_type or img_type is set
$query1.=" and extension in ('".$ext_type."')";

}else{
$query1.=" extension in ('".$ext_type."')";
}
echo "$query1
";

$results1 = mysql_query($query1) or die ("Could not execute query1. ".mysql_error());

//This returns an array holding all keywords, delimited by commas
$the_search = explode(",",$searchstring);
for ($s=0; $s {
if ($s==0)
{
$search_item="'%".strtolower(trim($the_search[$s]))."%'";
}else
{
$search_item=",'%".strtolower(trim($the_search[$s]))."%'";
}
}
$query2 = "SELECT master_id FROM keyword WHERE (keywords IN ('".$search_item."'))";
$results2 = mysql_query($query2) or die ("Could not execute query2".mysql_error());

$query3 = "SELECT image_location FROM image_info WHERE $results1 = $results2";
$results3 = mysql_query($query3) or die ("Could not execute query3".mysql_error());

if ($myrow = mysql_fetch_array($results3,MYSQL_ASSOC)) {

do {

printf ("Image_location: %s", $myrow["image_location"]);

} while ($myrow = mysql_fetch_array($results3,MYSQL_ASSOC));
} else {
$display_block= "Sorry, no records were found!";
}
}
?>


Image Search


print $display_block; ?>

Author:??(---.phnx.uswest.net)
Date:???07-20-03 13:57

At this point, the script looks great to me, but it can't get past query1. Any help is greatly appreciated. Here's the output I receive when I search for two items in each array set,

"2 num_ext

Notice: Undefined variable: ext_type
'Array','Array' ext_type
2 x value
'Array','Array' ext_type
2 num_img

Notice: Undefined variable: img_type
'Array','Array' img_type
2 y value
'Array','Array' img_type
2 num_sub

Notice: Undefined variable: sub_type
'Array','Array' sub_type
2 z value
'Array','Array' sub_type
select id from image_info where image_type in (''Array','Array'') and subject in (''Array','Array'') and extension in (''Array','Array'')
Could not execute query1. 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 'Array','Array'') and subject in (''Array','Array'') and extensi"

And here's the code....

error_reporting (E_ALL);
if($_POST['op'] != "search")
{//shows the blank search form
$display_block = "

...

?Topics Author? Date
?keywords, checkbox array search??new
Truly 07-05-03 12:47?
?Re: keywords, checkbox array search??new
bastien 07-06-03 07:10?
?Re: keywords, checkbox array search??new
Truly 07-08-03 10:20?
?Re: keywords, checkbox array search??new
bastien 07-09-03 19:00?
?Re: keywords, checkbox array search??new
Truly 07-09-03 20:54?
?Re: keywords, checkbox array search??new
bastien 07-13-03 17:29?
?Re: keywords, checkbox array search??new
bastien 07-15-03 10:37?
?Re: keywords, checkbox array search??new
Truly 07-16-03 20:20?
?Re: keywords, checkbox array search??new
bastien 07-17-03 06:44?
?Re: keywords, checkbox array search??new
Truly 07-20-03 13:57?
?Re: keywords, checkbox array search??new
bastien 07-21-03 17:41?
?Re: keywords, checkbox array search??new
Truly 08-21-03 08:21?
Go to Top??|??Go to Topic??|??Flat View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??wrote: > > At this point, the script looks great to me, but it can't get > past query1. Any help is greatly appreciated. Here's the > output I receive when I search for two items in each array set, > > "2 num_ext > > Notice: Undefined variable: ext_type > 'Array','Array' ext_type > 2 x value > 'Array','Array' ext_type > 2 num_img > > Notice: Undefined variable: img_type > 'Array','Array' img_type > 2 y value > 'Array','Array' img_type > 2 num_sub > > Notice: Undefined variable: sub_type > 'Array','Array' sub_type > 2 z value > 'Array','Array' sub_type > select id from image_info where image_type in > (''Array','Array'') and subject in (''Array','Array'') and > extension in (''Array','Array'') > Could not execute query1. 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 > 'Array','Array'') and subject in (''Array','Array'') and > extensi" > > And here's the code.... > > error_reporting (E_ALL); > if($_POST['op'] != "search") > {//shows the blank search form > $display_block = "
action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\"> > ... > name=\"extension[]\">

Provided By
Phorum