Jump to content

Multiple search boxes help w/php script to get mysql results


theresa90

Recommended Posts

I have a simple (1 table, 14 fields) database. I'm using 9 separate search boxes from my search page :

http://www.cinemaposter.com/database.html

There are currently 162 entries. Hitting "submit" throws them all out, same with valid input into any box, with the exception of "country" - example  : entering "F" gives 20results; "PL" gives 34 results.

Here's my code (to simplify, I only went down to the 4th box ('country' - the last and only one giving correct results).  I'm one sorry newbie.... please help !

Here's the code :

------------------

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"

"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">

<html>

<head>

<title>Search Results</title>

<meta name="generator" content="BBEdit 6.5">

<style type="text/css">

td

{

color: #000000;

font-family: arial;

font-size: 10px;

}

</style>

</head>

<body>

<?php

$link = mysql_connect("xxxx", "xxxx", "xxxx") or die("Could not connect");

///print "Connected successfully<BR>";

mysql_select_db("xxxx") or die("Could not select database");

 

 

{

$Author = $_POST['Author'];

$sql = "SELECT * FROM posters WHERE Author LIKE '%$Author%'";

}

 

{

$Title = $_POST['Title'];

$sql = "SELECT * FROM posters WHERE Title LIKE '%$Title%'";

}

 

{

$Originaltitle =$_POST['Originalitle'];

$sql="SELECT * FROM posters WHERE Originaltitle LIKE '%$Originaltitle%'";

}

 

{

$Country =$_POST['Country'];

$sql="SELECT * FROM posters WHERE Country LIKE '%$Country%'";

}

 

 

$result = mysql_query ($sql) or die("Query failed : " . mysql_error());

$numrs = mysql_num_rows($result);

 

if ($numrs > 0){

 

if ($numrs==1){

print ("<p><font face=\"Arial\"><b>There is $numrs record in our database.</B> <BR><BR>");

}elseif($numrs>1){

print ("<p><font face=\"Arial\"><b>There are $numrs records in our database. </B><BR><BR>");//Apparently, he wan't to be able to search again...</b><form method \"POST\" action=\"$PHP_SELF\">Search Again:");

}

 

 

 

 

  echo("<a href='javascript:history.go(-1)'>Go Back</a></p>");

  print("<P align=center>Click on the column heading links to sort the results.<br><br />");

 

print ("<TABLE CELLPADDING=\"1\" CELLSPACING=\"2\" BORDER=\"0\">\n");

PRINT ("<TR BGCOLOR=\"#FFFF77\">

<TD COLSPAN=2><P align=center>Author</td>

<TD><P align=center>Title</TD>

<TD><P align=center>Original Title</TD>

<TD><P align=center>Country</TD>

<TD><P align=center>Director</TD>

<TD><P align=center>Cast</TD>

<TD><P align=center>Year</TD>

<TD><P align=center>Original Year</TD>

<TD><P align=center>Photo</TD>

<TD><P align=center>Producer</TD>

<TD><P align=center>Circulation</TD>

<TD><P align=center>Size</TD>

<TD><P align=center>Print type</TD>

<TD><P align=center>Remarks</TD></TR>");

 

$z=1;

while ($line = mysql_fetch_array($result)) {

 

$num=$z++;

//Note here that I'm assigning the found objects new names (indicated by lowercase) to that php wont get confused.....

$auth=$line['Author'];

$title=$line['Title'];

$originaltitle=$line['Originaltitle'];

$country=$line['Country'];

$director=$line['Director'];

$cast=$line['Cast'];

$year=$line['Year'];

$originalyear=$line['Originalyear'];

$producer=$line['Producer'];

$circ=$line['Circulation'];

$size=$line['Size'];

$print=$line['Print'];

$remarks=$line['Remarks'];

$pict=$line['Picture'];

 

 

//Set the formatting

$bgcolor = ($i++ & 1) ? '#d3d3d3' : '#c0c0c0';

 

 

PRINT("<TR BGCOLOR=$bgcolor>

<TD>$num.</TD>

<TD>$auth</td>

<TD>$title</TD>

<TD>$originaltitle</TD>

<TD><P align=center>$country</TD>

<TD>$director</TD>

<TD>$cast</TD>

<TD><P align=center>$year</TD>

<TD><P align=center>$originalyear</TD><TD>");

// This is the test to find do we have a picture

if ($pict) {

// If there is a picture, display it:

print ("<P align=center><a href='zdjecie.php?zdj= $pict&autor=$auth&opis=$title&orig=$originaltitle&rok=$year' target='_blank'>

<img src=$pict height=\"150\"></a>");

} else {

 

// We don't have a picture, so we print some text instead:

print ("<P align=center>no picture available");

}

 

print ("</TD><TD>$producer</TD>

<TD><P align=center>$circ</TD>

<TD>$size</TD>

<TD>$print</TD>

<TD>$remarks</TD></TR>");

 

}

PRINT("</TABLE><BR><font face=\"Arial\"><a href=\"javascript:history.go(-1);\">Search Again</a></font>");

}else {

print ("<font face=\"Arial\">Sorry, there were no results for your search. <a href=\"javascript:history.go(-1);\">Please try again</a></font>");

}

//mysql_close($link);

?>                                                                   

</body>

</html>

 

Link to comment
Share on other sites

Three things-

 

1st: wrap you code inside the forums PHP tags :php_tags: or we're likely not even going to look at it (it's in the terms of use for the forum - I'm not just being nasty.....or am I  >:)). 

2nd: you think we need it kept simple?  this is actualy counter productive, as the issue could lie further on in your code and we are just going to end up asking you to post it all anyway.

3rd: we need information on all aspects of the script, in most casses that meens table struct from databases accessed, posting up of included files contents etc.

 

Where's fenways signature when you need it?... :examine:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.