RE: Re: Search script problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Have you tried to catch (echo) the query you try to execute in mysql and
then debug it from there?

I saw that you in your code did all in one row. Separate it to:

$Query = "your query";

echo $Query; //Use this in phpMyAdmin or any other MySQL administrator and
see if the query is correct. If you get matches there your code should be
fine.

$Result = mysql_query($Query);
...
...


Best regards,
Peter Lauri

www.dwsasia.com  - company web site
www.lauri.se  - personal web site
www.carbonfree.org.uk  - become Carbon Free


-----Original Message-----
From: Wikus Moller [mailto:wikus.m@xxxxxxxxx] 
Sent: Sunday, January 07, 2007 1:20 AM
To: php-general@xxxxxxxxxxxxx
Subject:  Re: Search script problem

So it should be like this (it still doesn't show the results):

<?php

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML Mobile 1.0//EN\"
\"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\";>";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\";>";

error_reporting(E_ALL ^ E_NOTICE);

$pwd = $_GET["pwd"];
$uid = $_GET["uid"];
$action = $_GET["action"];
$cid = $_GET["cid"];
$sid = $_GET["sid"];
$var = $_GET["q"];

include ("function.php");
include ("config.php");
connect($dbserver,$dbname,$dbuser,$dbpass);



/////////////////////////////////////////////Search main page
if(!isset($var)){
echo "<head>";
echo "<title>Search Engine</title>";
echo "<style type=\"text/css\">
       .m3 {background-color: #291C6F;}
       .n1 {background-color: #A0A0A0;}
       .n2 {background-color: #888888;}
       .c2 {color: #000000;}
       .m2 {color: #91D0FF;}
       body   {font-family: Arial, sans-serif;
                       font-size: 12px;
                       color: #ffffff;
                       background-color: #000033;
                       margin-left: 0px;
                       margin-right: 0px;
                       margin-top: 0px;}
       .ct1 {font-family: Arial, sans-serif;
                       font-size: 12px;
                       color: #800080;}
       .cre {background-color: #1300A4;
                       padding: 2px 2px 2px 2px;
                       margin: 3px 0 0;
                       font-size: 12px;
                       color:#000000;
                       text-align: center;
                       border-width:1px 0;
                       border-style:solid;
                       border-color:#000000;}
</style>";
echo "</head>";
echo "<body>";
echo "<table>";
echo "<div class=\"cre\">";
echo "<b>Search Engine</b></div>";
echo "<form method=\"GET\"
action=\"search.php?uid=$uid&amp;pwd=$pwd\">"; ///the uid and pwd is
nessecary cause my member features are very basic and the urls is used
to keep the user 'logged in'
echo "Keywords: <input type=\"text\" name=\"q\" /><br/>";
echo "<input type=\"submit\" name=\"Submit\"/>";
echo "</form>";
echo "</table>";
echo "<div class=\"cre\"><img src=\"images/home.gif\" alt=\"*\"/><a
href=\"index.php?uid=$uid&amp;pwd=$pwd\">Home</a></div>";
echo "</body>";
echo "</html>";
}

///////////////////////////////////////////////////Display Results

if(isset($var)){
$var = $_GET["q"];
$trimmed = trim($var); //trim whitespace from the stored variable
echo "<head>";
echo "<title>Search Results</title>";
echo "<style type=\"text/css\">
       .m3 {background-color: #291C6F;}
       .n1 {background-color: #A0A0A0;}
       .n2 {background-color: #888888;}
       .c2 {color: #000000;}
       .m2 {color: #91D0FF;}
       body   {font-family: Arial, sans-serif;
                       font-size: 12px;
                       color: #ffffff;
                       background-color: #000033;
                       margin-left: 0px;
                       margin-right: 0px;
                       margin-top: 0px;}
       .ct1 {font-family: Arial, sans-serif;
                       font-size: 12px;
                       color: #800080;}
       .cre {background-color: #1300A4;
                       padding: 2px 2px 2px 2px;
                       margin: 3px 0 0;
                       font-size: 12px;
                       color:#000000;
                       text-align: center;
                       border-width:1px 0;
                       border-style:solid;
                       border-color:#000000;}
</style>";
echo "</head>";
echo "<body>";
echo "<div class=\"cre\">";
echo "<b>Search Results</b></div>";
echo "<table>";
 // Get the search variable from URL



// check for an empty string and display a message.
if ($trimmed == "")
 {
 echo "Please enter a search...";
 exit;
 }



if($pg==0)$pg=1;
 $pg--;
 $lmt = $pg*20;
 $pg++;
 $cou =$lmt+1;
 $scount = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM table
WHERE keywords like \"%$trimmed%\" AND banned='0' AND hits_in >=
'2'"));
 $pgs = ceil($scount[0]/20);
 // Build SQL Query
 $sql = "SELECT * FROM table WHERE keywords like \"%$trimmed%\" AND
banned='0' and hits_in >='2' ORDER by hits_in DESC LIMIT ".$lmt.", 20;";
// EDIT HERE and specify your table and field names for the SQL query
 $sites=mysql_query($sql);


while ($site = mysql_fetch_array($sites))
{
   $dscr =htmlspecialchars($site[11]);
   $snm=htmlspecialchars($site[1]);
   echo "<tr><td align=\"left\"><a
href=\"index.php?action=vsite&amp;sid=$site[0]&amp;uid=$uid&amp;pwd=$pwd\">$
snm</a></td></tr>";
   echo "<tr><td align=\"left\">$dscr</td></tr>";
   $cou++;
}
$npage = $pg+1;
$ppage = $pg-1;
if($pg<$pgs)
//this is just for clicking on the site's name when the results are
displayed
{

   $nlink = "<a
href=\"index.php?action=vsites&amp;pg=$npage&amp;uid=$uid&amp;pwd=$pwd&amp;c
id=$cid\"
accesskey=\"1\"><img src=\"images/next.gif\" alt=\"1\"/>Next</a>";

}
if($pg >1)
{
   $plink = "<a
href=\"index.php?action=vsites&amp;pg=$ppage&amp;uid=$uid&amp;pwd=$pwd&amp;c
id=$cid\"
accesskey=\"2\"><img src=\"images/prev.gif\" alt=\"2\"/>Prev</a>";
}


echo "<tr class=\"m2\"><td align=\"right\">$nlink</td></tr>";
echo "<tr class=\"m2\"><td align=\"left\">$plink</td></tr>";

echo "</table>";
echo "<div class=\"cre\"><img src=\"images/home.gif\" alt=\"*\"/><a
href=\"index.php?uid=$uid&amp;pwd=$pwd\">Home</a></div>";
echo "</body>";
echo "</html>";
}
?>



On 1/7/07, Wikus Moller <wikus.m@xxxxxxxxx> wrote:
> And the hits_in of the mysql query are the same, I just made a typing
> mistake.
>
> On 1/7/07, Wikus Moller <wikus.m@xxxxxxxxx> wrote:
> > Hi.
> >
> > I am having problems with a script I wrote which searches keywords
> > from a field in a mysql db table.
> >
> > It is a very simple,  one-page script. My site is a toplist, very
> > basic, still in it's infancy. When I go to the page, key in the
> > keywords and press submit, the head, body etc. part of the result
> > script is shown, but no results.
> > , although there are rows in my database containing the `keyword` field
> > data.
> >
> > Below is the script, please see if you find any errors, it could be
> > that I just made a stupid mistake.
> >
> > <?php
> >
> > echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
> > echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML Mobile 1.0//EN\"
> > \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\";>";
> > echo "<html xmlns=\"http://www.w3.org/1999/xhtml\";>";
> >
> > error_reporting(E_ALL ^ E_NOTICE);
> >
> > $pwd = $_GET["pwd"];
> > $uid = $_GET["uid"];
> > $action = $_GET["action"];
> > $cid = $_GET["cid"];
> > $sid = $_GET["sid"];
> > $var = $_GET["q"];
> >
> > include ("function.php");
> > include ("config.php");
> > connect($dbserver,$dbname,$dbuser,$dbpass);
> >
> >
> >
> > /////////////////////////////////////////////Search main page
> > if(!isset($var)){
> > echo "<head>";
> > echo "<title>Search Engine</title>";
> > echo "<style type=\"text/css\">
> > 	.m3 {background-color: #291C6F;}
> >     	.n1 {background-color: #A0A0A0;}
> >     	.n2 {background-color: #888888;}
> > 	.c2 {color: #000000;}
> > 	.m2 {color: #91D0FF;}
> > 	body   {font-family: Arial, sans-serif;
> > 			font-size: 12px;
> > 			color: #ffffff;
> > 			background-color: #000033;
> > 			margin-left: 0px;
> > 			margin-right: 0px;
> > 			margin-top: 0px;}
> > 	.ct1 {font-family: Arial, sans-serif;
> > 			font-size: 12px;
> > 			color: #800080;}
> > 	.cre {background-color: #1300A4;
> > 			padding: 2px 2px 2px 2px;
> > 			margin: 3px 0 0;
> > 			font-size: 12px;
> > 			color:#000000;
> > 			text-align: center;
> > 			border-width:1px 0;
> > 			border-style:solid;
> > 			border-color:#000000;}
> > </style>";
> > echo "</head>";
> > echo "<body>";
> > echo "<table>";
> > echo "<div class=\"cre\">";
> > echo "<b>Search Engine</b></div>";
> > echo "<form method=\"GET\"
> > action=\"search.php?uid=$uid&amp;pwd=$pwd\">"; ///the uid and pwd is
> > nessecary cause my member features are very basic and the urls is used
> > to keep the user 'logged in'
> > echo "Keywords: <input type=\"text\" name=\"q\" /><br/>";
> > echo "<input type=\"submit\" name=\"Submit\"/>";
> > echo "</form>";
> > echo "</table>";
> > echo "<div class=\"cre\"><img src=\"images/home.gif\" alt=\"*\"/><a
> > href=\"index.php?uid=$uid&amp;pwd=$pwd\">Home</a></div>";
> > echo "</body>";
> > echo "</html>";
> > }
> >
> > ///////////////////////////////////////////////////Display Results
> >
> > if(isset($var)){
> > $var = $_GET["q"];
> > $trimmed = trim($var); //trim whitespace from the stored variable
> > echo "<head>";
> > echo "<title>Search Results</title>";
> > echo "<style type=\"text/css\">
> > 	.m3 {background-color: #291C6F;}
> >     	.n1 {background-color: #A0A0A0;}
> >     	.n2 {background-color: #888888;}
> > 	.c2 {color: #000000;}
> > 	.m2 {color: #91D0FF;}
> > 	body   {font-family: Arial, sans-serif;
> > 			font-size: 12px;
> > 			color: #ffffff;
> > 			background-color: #000033;
> > 			margin-left: 0px;
> > 			margin-right: 0px;
> > 			margin-top: 0px;}
> > 	.ct1 {font-family: Arial, sans-serif;
> > 			font-size: 12px;
> > 			color: #800080;}
> > 	.cre {background-color: #1300A4;
> > 			padding: 2px 2px 2px 2px;
> > 			margin: 3px 0 0;
> > 			font-size: 12px;
> > 			color:#000000;
> > 			text-align: center;
> > 			border-width:1px 0;
> > 			border-style:solid;
> > 			border-color:#000000;}
> > </style>";
> > echo "</head>";
> > echo "<body>";
> > echo "<div class=\"cre\">";
> > echo "<b>Search Results</b></div>";
> > echo "<table>";
> >  // Get the search variable from URL
> >
> >
> >
> > // check for an empty string and display a message.
> > if ($trimmed == "")
> >   {
> >   echo "Please enter a search...";
> >   exit;
> >   }
> >
> >
> >
> > if($pg==0)$pg=1;
> >   $pg--;
> >   $lmt = $pg*20;
> >   $pg++;
> >   $cou =$lmt+1;
> >   $scount = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM table
> > WHERE keywords like \"%$trimmed%\" AND banned='0' AND hitsin >=
> > '2'"));
> >   $pgs = ceil($scount[0]/20);
> >   // Build SQL Query
> >   $sql = "SELECT * FROM table WHERE keywords like \"%$trimmed%\" AND
> > banned='0' and hits_in >='2' ORDER by hin DESC LIMIT ".$lmt.", 20;";
> > // EDIT HERE and specify your table and field names for the SQL query
> >   $sites=mysql_query($sql);
> >
> >
> > while ($site = mysql_fetch_array($sites))
> > {
> >     $dscr =htmlspecialchars($site[11]);
> >     $snm=htmlspecialchars($site[1]);
> >     echo "<tr><td align=\"left\"><a
> >
>
href=\"index.php?action=vsite&amp;sid=$site[0]&amp;uid=$uid&amp;pwd=$pwd\">$
snm</a></td></tr>";
> >     echo "<tr><td align=\"left\">$dscr</td></tr>";
> >     $cou++;
> > }
> > $npage = $pg+1;
> > $ppage = $pg-1;
> > if($pg<$pgs)
> > //this is just for clicking on the site's name when the results are
> > displayed
> > {
> >
> >     $nlink = "<a
> >
>
href=\"index.php?action=vsites&amp;pg=$npage&amp;uid=$uid&amp;pwd=$pwd&amp;c
id=$cid\"
> > accesskey=\"1\"><img src=\"images/next.gif\" alt=\"1\"/>Next</a>";
> >
> > }
> > if($pg >1)
> > {
> >     $plink = "<a
> >
>
href=\"index.php?action=vsites&amp;pg=$ppage&amp;uid=$uid&amp;pwd=$pwd&amp;c
id=$cid\"
> > accesskey=\"2\"><img src=\"images/prev.gif\" alt=\"2\"/>Prev</a>";
> > }
> >
> >
> > echo "<tr class=\"m2\"><td align=\"right\">$nlink</td></tr>";
> > echo "<tr class=\"m2\"><td align=\"left\">$plink</td></tr>";
> >
> > echo "</table>";
> > echo "<div class=\"cre\"><img src=\"images/home.gif\" alt=\"*\"/><a
> > href=\"index.php?uid=$uid&amp;pwd=$pwd\">Home</a></div>";
> > echo "</body>";
> > echo "</html>";
> > }
> > ?>
> >
> > Like I said, very basic. I know there must be a screw-up somewhere but
> > I can't seem to find it.
> >
> > Thanks
> > Wikus
> >
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux