Jump to content

building a mysql query using php


ajoo
Go to solution Solved by ginerjm,

Recommended Posts

Hi all !

 

I wish to build a mysql query which is very simple. An example of the query I want is as follows:

 

$query = "Select * FROM $table WHERE tables=1 OR tables=2  AND Member_status = 'D' ";
 
The problem is that the conditions Where tables=1 or tables=2 can vary and i can have tables=3 , tables=4  etc. as well. So basically the OR condition is ramdom and must be constructed in a loop. 
 
I constructed a loop which stores the result in a variable $tablescnt. i.e. 
 
echo .$tablescnt;    gives      tables=1 OR tables=2 OR tables=3       and so on depending upon the loop iterations. 
 
However i don't know i am going to substitute this ($tablescnt) into $query above.
 
I tried 
$query = "Select * FROM $table WHERE '$tablescnt' AND Member_status = 'D' ";
 
where i hoped that $tablescnt would expand as desired. However it did not work. So any suggestions on how I may proceed would be very helpful. 
 
Thanks all for your time to check this out and help me. 
 
 
 
 

 

 

Link to comment
Share on other sites

Hi guys ! thanks for both the replies. Ginerjim, you were right. leaving the quotes off the variable did the trick. Surprising thing is that I tried that before posting this question and for some reason it did not work. After your suggestion I tried it again just now and it worked !! Thanks loads both of you. Very grateful.

 

Ajoo.

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.