?

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
Author:??(---.cpe.net.cable.roger)
Date:???07-15-03 10:37

okay made some changes...see if this makes a difference

error_reporting (E_ALL);
if($_POST['op'] != "search") //missing the single quotes around the op variable name
{
//shows the blank search form
$display_block = "

.......................................................
html form here. subject, image_type, extension, search_words, and submit button
........................................................



";

} else
// if($_POST[op] == "search")
{

//connect to database
$conn = mysql_connect("localhost", "odbc","") or die(mysql_error()); //i'll assume connection string is correct
mysql_select_db("shcimages",$conn) or die(mysql_error());

$image_type_request = $_POST['image_type'];
$subject_request = $_POST['subject'];
$extension_request = $_POST['extension'];
$searchstring = $_POST['search_words'];

//check for image type -- checked with some old code and this seems to be a better way of handling things...
//are these numbers or alphanumeric strings? string will require the single quote to make the query correct
if (count($image_type_request)==1){
$img_type=$image_type_request;
}elseif($image_type_request)>1) {
$img_type=implode(",",$image_type_request); //turn the results into a comma separate variable
}else{
//no value set for image type...maybe send form back to user?
//lets leave it alone and set it to "na" for not applicable
$img_type="na";
}

//are these numbers or alphanumeric strings? string will require the single quote to make the query correct
if (count($subject_request)==1){
$sub_type=$subject_request;
}elseif($subject_request)>1) {
$sub_type=implode(",",$subject_request); //turn the results into a comma separate variable
}else{
//no value set for subject type...maybe send form back to user or if not requires leave it alone??
//lets leave it alone and set it to "na" for not applicable
$sub_type="na";
}

//are these numbers or alphanumeric strings? string will require the single quote to make the query correct
if (count($extension_request)==1){
$ext_type=$extension_request;
}elseif($extension_request)>1) {
$ext_type=implode(",",$extension_request); //turn the results into a comma separate variable
}else{
//no value set for extension type...maybe send form back to user or if not requires leave it alone??
//lets leave it alone and set it to "na" for not applicable
$ext_type="na";
}

/*
$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.")";
}


$results1 = mysql_query($query1);
//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);

$query3 = "SELECT image_location FROM image_info WHERE $results1 = $results2";
$results3 = mysql_query($query3);

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

do {

printf ("Image_location: %s", $myrow["image_location"]);
// not really my code printf("%s %s
\n", $PHP_SELF, $myrow["id"], $myrow["master_id"]);

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


Image Search


print $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: > > okay made some changes...see if this makes a difference > > error_reporting (E_ALL); > if($_POST['op'] != "search") //missing the single > quotes around the op variable name > { > //shows the blank search form > $display_block = "
action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\"> > ....................................................... > html form here. subject, image_type, extension, search_words, > and submit button > ........................................................ > > > >
"; > > } else > // if($_POST[op] == "search") > { > > //connect to database > $conn = mysql_connect("localhost", "odbc","") or > die(mysql_error()); //i'll assume connection string is > correct > mysql_select_db("shcimages",$conn) or die(mysql_error()); > > $image_type_request = $_POST['image_type']; > $subject_request = $_POST['subject']; > $extension_request = $_POST['extension']; > $searchstring = $_POST['search_words']; > > //check for image type -- checked with some old code and > this seems to be a better way of handling things... > //are these numbers or alphanumeric strings? string will > require the single quote to make the query correct > if (count($image_type_request)==1){ > $img_type=$image_type_request; > }elseif($image_type_request)>1) { > $img_type=implode(",",$image_type_request); //turn the > results into a comma separate variable > }else{ > //no value set for image type...maybe send form back to > user? > //lets leave it alone and set it to "na" for not applicable > $img_type="na"; > } > > //are these numbers or alphanumeric strings? string will > require the single quote to make the query correct > if (count($subject_request)==1){ > $sub_type=$subject_request; > }elseif($subject_request)>1) { > $sub_type=implode(",",$subject_request); //turn the > results into a comma separate variable > }else{ > //no value set for subject type...maybe send form back to > user or if not requires leave it alone?? > //lets leave it alone and set it to "na" for not applicable > $sub_type="na"; > } > > //are these numbers or alphanumeric strings? string will > require the single quote to make the query correct > if (count($extension_request)==1){ > $ext_type=$extension_request; > }elseif($extension_request)>1) { > $ext_type=implode(",",$extension_request); //turn the > results into a comma separate variable > }else{ > //no value set for extension type...maybe send form back > to user or if not requires leave it alone?? > //lets leave it alone and set it to "na" for not applicable > $ext_type="na"; > } > > /* > $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.")"; > } > > > $results1 = mysql_query($query1); > //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); > > $query3 = "SELECT image_location FROM image_info WHERE > $results1 = $results2"; > $results3 = mysql_query($query3); > > if ($myrow = mysql_fetch_array($results3,MYSQL_ASSOC)) { > > do { > > printf ("Image_location: %s", > $myrow["image_location"]); > // not really my code printf("%s > %s
\n", $PHP_SELF, $myrow["id"], $myrow["master_id"]); > > } while ($myrow = > mysql_fetch_array($results3,MYSQL_ASSOC)); > } else { > $display_block= "Sorry, no records were found!"; > } > } > ?> > > > Image Search > > > print $display_block; ?> > ">??

Provided By
Phorum