[PHP] More values than I want !(php->mysql query) From: Alain \ (alain.cyberspace <email protected>)
Date: 12/16/00

Ok, I'm having a loop running in the folowing Query in PHP. When I run it
through Mysql command line (Only 1 or 2 desired row returns), but when I try
it through a PHP page, it gets the "near endless loop"...

Mysql Code :

SELECT cybgoods.*, categorie.*, materiel.* FROM cybgoods, categorie,
materiel
WHERE
cybgoods.name LIKE '%falcon\%'
OR cybgoods.textdesc LIKE '%falcon%'
AND categorie.cat_id = cybgoods.Gcat
AND materiel.mat_id = cybgoods.Pcat
AND cybgoods.Gcat = 3
AND categorie.cat_id = 3
AND cybgoods.Pcat = 6
AND materiel.mat_id = 6
;

(This works FINE in the Command line)

"Materiel" and "Categories" are basicaly 2 tables with an INT as
reference/primary key (cat_id and mat_id) and a description(cat_desc &
mat_desc). the main table holds INTs as references to these two tables (Gcat
& Pcat), YET, when i do the Query, it returns ALL the text values for the 2
tables... (It returns ALL the vaulues in materiel & Categorie)

Here's the PHP code :

function displaysearch()
{
     global $PHP_SELF, $materiel, $Categorie, $keyword;
     //Display Search Results !
     $keyword = addslashes($keyword);

     echo "<p>$keyword";
     if (isset($Categorie))
          {
          echo "<p>$Categorie";
          }
     if (isset($materiel))
          {
          echo "<p>$materiel";
          }

     $query = "SELECT cybgoods.*, categorie.catdesc, materiel.matdesc";
     $query .= " FROM cybgoods, categorie, materiel";
     $query .= " WHERE cybgoods.name LIKE '%$keyword%'";
     $query .= " OR cybgoods.textdesc LIKE '%$keyword%'";
     $query .= " AND categorie.cat_id = cybgoods.Gcat";
     $query .= " AND materiel.mat_id = cybgoods.Pcat";

     //check if categorie and Materiel are set, if they are, inlude in
search

     if (isset($Categorie))
          {
          $query .= " AND cybgoods.Gcat = $Categorie";
          $query .= " AND categorie.cat_id = $Categorie";
          }

     if (isset($materiel))
          {
          $query .= " AND cybgoods.Pcat = $materiel";
          $query .= " AND materiel.mat_id = $materiel";
          }

     $query .= " ORDER BY cybgoods.name";

     $result = mysql_query($query)
          or die ("Mysql Says :" .mysql_error());

     if (mysql_num_rows($result) == 0)
         {
         Print "<p>Pas de resultats disponibles avec ces parrametres:
<b>$keyword</b></p>";
         }

 /**********************/
 /*LECTURE DE LA TABLE */
 /**********************/

print "<table border=\"1\" cellpadding=\"1\">\n";

 print "<TR>\n";

 print "<TD width=\"75\">Nom</TD>\n";
 print "<TD width=\"75\">ware</TD>\n";
 print "<TD width=\"75\">pcat</TD>\n";
 print "<TD width=\"75\">gcat</TD>\n";
 print "<TD width=\"75\">prix</TD>\n";
 print "</TR>\n";

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

          $itemname = $row[name];
          $itemware = $row[ware];
          $itempcat = $row[matdesc];
          $itemgcat = $row[catdesc];
          $itemprice = $row[prix];

          print "<TR>\n";
          print "<TD width=\"75\">$itemname</TD>";
          print "<TD width=\"75\">$itemware</TD>";
          print "<TD width=\"75\">$itempcat</TD>";
          print "<TD width=\"75\">$itemgcat</TD>";
          print "<TD width=\"75\">$itemprice</TD>";
          print "</TR>\n";
          }
 print "</Table>\n";
}
------------------

please hlp, being stuck on that for 2 days, grrrr....
Alain

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>