?

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:??(---.phnx.uswest.net)
Date:???08-21-03 08:21

I changed a few things and it works great now. Here's the script....

//error_reporting (E_ALL);
if($_POST['op'] != "search")
{

//shows the blank search form
//I use backslashes before the quotation marks because it indicates to the PHP engine that I want to use the quotation mark rather than interpret it as the beginning or end of a string.

$display_block = "

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

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

$num_ext=count($_POST['extension']);
if ($num_ext==1){
$ext_type="'".$_POST['extension'][0]."'";
}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'][$x]."'";
}else{
//add the comma separator
$ext_type.=",'".$_POST['extension'][$x]."'";
} //close if then
}//close for loop
}else{
//no elements so set to "na"
$ext_type="na";
}

$num_img=count($_POST['image_type']);
if ($num_img==1){
$img_type="'".$_POST['image_type'][0]."'";
}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'][$y]."'";
}else{
//add the comma separator
$img_type.=",'".$_POST['image_type'][$y]."'";

} //close if then
}//close for loop
}else{
//no elements so set to "na"
$img_type="na";
}

$num_sub=count($_POST['subject']);
if ($num_sub==1){
$sub_type="'".$_POST['subject'][0]."'";
}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'][$z]."'";
}else{
//add the comma separator
$sub_type.=",'".$_POST['subject'][$z]."'";
} //close if then
}//close for loop
}else{
//no elements so set to "na"
$sub_type="na";
}
//requires all criteria to be set
if(!($_POST['subject']) || !($_POST['image_type']) || !($_POST['extension']) || !($_POST['search_words']))
{
$display_block = "please set your search criteria for the file type, image type, and subject of your desired image.
Click here to try again (or just press the back button).";
}
else
{
$searchstring = trim(addslashes(strtolower($_POST['search_words'])));
//echo "$searchstring
";
//This returns an array holding all keywords, delimited by spaces
$the_search = explode(" ",$searchstring);
//echo "$the_search
";
$count=count($the_search);
//echo "count of keyword search items: $count
";

$query1 = "select image_location, keywords, image_type, extension, subject from image_info
INNER JOIN keyword ON image_info.id = keyword.master_id
WHERE (((image_info.image_type) IN (".$img_type.")) AND
((image_info.subject) IN (".$sub_type.")) AND ((image_info.extension) IN (".$ext_type."))) AND";

if ($count==1){
$query1.="(keywords LIKE '%$searchstring%')";
}
else {
for($a=0; $a<$count; $a++){
$query1.="(keywords LIKE ('%$the_search[$a]%'))";

if ($a < $count-1){
//if it is last keyword then don't put OR in select statment.
$query1.=" OR ";
}
}
}

print "

Image Search Results

";

//echo "$query1
";
print "You searched for the keyword(s) of: $searchstring
in files with the file extension(s) of: $ext_type
the image
type(s) of: $img_type
and in the subject category(s) of: $sub_type
";

$results1 = mysql_query($query1) or die ("Could not execute query1. ".mysql_error());
if ($myrow = mysql_fetch_array($results1,MYSQL_ASSOC)) {
$number = mysql_numrows($results1);
print "

$number total image result(s)

";
print "Scroll down for results and click on the hyperlinks to view or save the images.
Click here to try another search or click here to upload an image.\n

";
do {

printf (" Image location\n
File type: %s \n
Image type: %s \n
Subject: %s \n
Keywords: %s \n

", $myrow['image_location'], $myrow['extension'], $myrow['image_type'], $myrow['subject'], $myrow['keywords']);

} while ($myrow = mysql_fetch_array($results1,MYSQL_ASSOC));
} else {
$display_block= "Sorry, no records were found! Click here to try again or Click here upload an image.";
}
}}
?>

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: > > I changed a few things and it works great now. Here's the > script.... > > //error_reporting (E_ALL); > if($_POST['op'] != "search") > { > > //shows the blank search form > //I use backslashes before the quotation marks because it > indicates to the PHP engine that I want to use the quotation > mark rather than interpret it as the beginning or end of a > string. > > $display_block = "
action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\"> > ..... here's the html form........ > } else > // if($_POST['op'] == "search") > { > //connect to database > $conn = mysql_connect("localhost", "odbc","") or die("Unable > to connect.".mysql_error()); > > mysql_select_db("db",$conn) or die("Unable to access the > db.".mysql_error()); > > $num_ext=count($_POST['extension']); > if ($num_ext==1){ > $ext_type="'".$_POST['extension'][0]."'"; > }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'][$x]."'"; > }else{ > //add the comma separator > $ext_type.=",'".$_POST['extension'][$x]."'"; > } //close if then > }//close for loop > }else{ > //no elements so set to "na" > $ext_type="na"; > } > > $num_img=count($_POST['image_type']); > if ($num_img==1){ > $img_type="'".$_POST['image_type'][0]."'"; > }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'][$y]."'"; > }else{ > //add the comma separator > $img_type.=",'".$_POST['image_type'][$y]."'"; > > } //close if then > }//close for loop > }else{ > //no elements so set to "na" > $img_type="na"; > } > > $num_sub=count($_POST['subject']); > if ($num_sub==1){ > $sub_type="'".$_POST['subject'][0]."'"; > }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'][$z]."'"; > }else{ > //add the comma separator > $sub_type.=",'".$_POST['subject'][$z]."'"; > } //close if then > }//close for loop > }else{ > //no elements so set to "na" > $sub_type="na"; > } > //requires all criteria to be set > if(!($_POST['subject']) || !($_POST['image_type']) || > !($_POST['extension']) || !($_POST['search_words'])) > { > $display_block = "please set your search criteria for the > file type, image type, and subject of your desired image. > Click here to try again (or > just press the back button)."; > } > else > { > $searchstring = > trim(addslashes(strtolower($_POST['search_words']))); > //echo "$searchstring
"; > //This returns an array holding all keywords, delimited by > spaces > $the_search = explode(" ",$searchstring); > //echo "$the_search
"; > $count=count($the_search); > //echo "count of keyword search items: $count
"; > > $query1 = "select image_location, keywords, image_type, > extension, subject from image_info > INNER JOIN keyword ON image_info.id = keyword.master_id > WHERE (((image_info.image_type) IN (".$img_type.")) AND > ((image_info.subject) IN (".$sub_type.")) AND > ((image_info.extension) IN (".$ext_type."))) AND"; > > if ($count==1){ > $query1.="(keywords LIKE '%$searchstring%')"; > } > else { > for($a=0; $a<$count; $a++){ > $query1.="(keywords LIKE ('%$the_search[$a]%'))"; > > if ($a < $count-1){ > //if it is last keyword then don't put OR in select statment. > $query1.=" OR "; > } > } > } > > print "

Image Search Results

"; > > //echo "$query1
"; > print "You searched for the keyword(s) of: > $searchstring
in files with the file extension(s) > of: $ext_type
the image > type(s) of: $img_type
and in the subject > category(s) of: $sub_type
"; > > $results1 = mysql_query($query1) or die ("Could not execute > query1. ".mysql_error()); > if ($myrow = mysql_fetch_array($results1,MYSQL_ASSOC)) { > $number = mysql_numrows($results1); > print "

$number total image result(s)

"; > print "Scroll down for results and click on the hyperlinks to > view or save the images.
Click href=\"mastersearch.php\">here to try another search or > click here to upload an > image.\n

"; > do { > > printf (" Image location\n
File > type: %s \n
Image type: %s \n
> Subject: %s \n
Keywords: %s \n

", > $myrow['image_location'], $myrow['extension'], > $myrow['image_type'], $myrow['subject'], $myrow['keywords']); > > } while ($myrow = mysql_fetch_array($results1,MYSQL_ASSOC)); > } else { > $display_block= "Sorry, no records were found! Click href=\"mastersearch16.php\">here to try again or Click href=\"masterupload.php\">here upload an image."; > } > }} > ?> > > Image Search > > > print $display_block; ?> > ">??

Provided By
Phorum