Jump to content


Photo

WHERE this is this and this is this???


  • Please log in to reply
8 replies to this topic

#1 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 17 August 2006 - 02:32 PM

I know that you can use the clause WHERE this_field='$this'

However, is there a way you can use two WHEREs?

Can someone tell me how to do this?



Something like (it doesn't work i've tried it):

WHERE this_field='$this' AND this_other_field='$this2'



Thanks!

#2 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 August 2006 - 02:33 PM

WHERE this_field='$this' AND this_other_field='$this2'

that is correct......



#3 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 17 August 2006 - 02:38 PM

well I am using this and it says that it isn't working.

  $queryphones = mysql_query("SELECT * FROM phones WHERE manufacturer='$catmode' AND special='$type' ORDER by model ASC");
while($phones = mysql_fetch_array($queryphones)) { 

}

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/noth/public_html/igbltd/browse.php on line 313

http://www.finalfant...s&type=Walkmans

Please help

#4 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 17 August 2006 - 02:46 PM

Try adding an or die statement. Also, separating the query out will help so you can echo the query string:
  $sql = "SELECT * FROM phones WHERE manufacturer='$catmode' AND special='$type' ORDER by model ASC";
  $queryphones = mysql_query($sql) or die("mysql_error()<br />Sql:$sql");
while($phones = mysql_fetch_array($queryphones)) {

}


#5 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 17 August 2006 - 02:49 PM

<?php

session_start();

$database_host = "localhost";
$database_username = "";
$database_password = "";
$database_name = "";

$connection = mysql_connect($database_host, $database_username, $database_password) or die(mysql_error());
$db = mysql_select_db($database_name, $connection);

$catmode = "a";
$type = "a";

$queryphones = mysql_query("SELECT * FROM phones WHERE manufacturer='$catmode' AND special='$type' ORDER by model ASC");

while($phones = mysql_fetch_array($queryphones))
{
echo"$phones[manufacturer]";
}

?>

that works and echos out results...

#6 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 17 August 2006 - 02:50 PM

still not working.

Error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/noth/public_html/igbltd/browse.php on line 319

Ill give you the whole snippet from that area. It starts at line 286 and ends at line 300
if ($type == "All") {
  
  $queryphones = mysql_query("SELECT * FROM phones WHERE manufacturer='$catmode' ORDER by model ASC"); 
  
  $temp1 == "";
  
} elseif (!$type == "All") {
  
  $temp1 == $type;
  
  $sql = "SELECT * FROM phones WHERE manufacturer='$catmode' AND special='$type' ORDER by model ASC";
  $queryphones = mysql_query($sql) or die("mysql_error()
Sql:$sql");
  
}


#7 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 17 August 2006 - 02:53 PM

The reason the error is after line 300 is because the while statement is further down

#8 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 17 August 2006 - 02:55 PM

Well i would guess the error is on the other query then
<?php
if ($type == "All") {
  
  $sql= "SELECT * FROM phones WHERE manufacturer='$catmode' ORDER by model ASC"; 
  $queryphones = mysql_query($sql) or die("mysql_error() Sql:$sql");
  
  $temp1 == "";
  
} elseif (!$type == "All") {
  
  $temp1 == $type;
  
  $sql = "SELECT * FROM phones WHERE manufacturer='$catmode' AND special='$type' ORDER by model ASC";
  $queryphones = mysql_query($sql) or die("mysql_error() Sql:$sql");
  
}
?>


#9 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 17 August 2006 - 03:06 PM

I got it working. I used what GingerRobot said.

For some reason if I take out the elseif (!$type == "All") and change it to just else it works.

If I leave it as elseif (!$type == "All") then it shows nothing in the while loop.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users