Jump to content

Recommended Posts

$query = "SELECT * FROM questions WHERE level='1' AND column='1'";

 

$query = "SELECT * FROM questions WHERE (level='1') AND (column='1')";

 

I'm trying to select rows based on values in two columns but it is throwing up NOT A VALID MYSQL RESOURCE error.  Can some one help me with the correct syntax to use here?

Link to comment
https://forums.phpfreaks.com/topic/51593-solved-query-problem-where-with-two-and/
Share on other sites

No I had tried that as well.  doesn't work.  i'm really stumped.  i've never had to select data based on two columns before.  i've verified that the columns exist in the table, tried various combinations of paranthesis, nothing seems to be working.

$server='';
$user='';
$password='';
$mydtb='';

//all the connection info is correct for sure
//also when i run the query with just WHERE level=1 MINUS THE AND CLAUSE it works correctly

$connect=mysql_connect($server,$user,$password);
mysql_select_db($mydtb);

$query = "SELECT * FROM questions WHERE level=1 AND column=1";

$result = mysql_query( $query, $connect );
while ($row = mysql_fetch_array ($result) )
{
echo $row['question'];
}

This is so weird.  I had a bit of a brain freeze I guess.  I've been reusing the same log in system for so long now that I forgot that that was the last time I used this type of query and always I have no problems with it.

 

$query = "SELECT * FROM users WHERE username='".$user."' AND password='".$password."'";

 

Can anyone think of any reason why it wouldn't be working now?  I mean the code I posted is pretty much all there is to it.  I literally just started working on this.

Stab in the dark but i always tend to backtick my queries..not sure if this actually matters but try this..

 

$query = "SELECT * FROM `questions` WHERE `level`='1' AND `column`='1'"

 

 

Also i take it you defianlty have 2 fields name level and column , no typos?

The table has only four fields:

 

id

level

column

question

 

Just as an idea i tried selecting by level and id, instead of level and column and it worked, so I wonder if perhaps column is a reserved word that has a special function to mysql, thereby breaking the query.

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.