Jump to content
jhertilus

Replacing a $ with all

Recommended Posts

$result = mysql_query("SELECT name,email,age,b6 as Goal_Weight, Goal_body_fat,height FROM calculate where `current_date`  BETWEEN '".$fromdate."' AND '".$todate."' AND admin_id='$admin_id'") or die('Query failed!');

 

 

Each admin has an id, but I want to know how to replace $admin_id with a code that will give me all admins

Share this post


Link to post
Share on other sites

No, it just means that maybe you shouldn't go messing around in there... At least not without learning first.

 

Your query currently looks for records with a matching admin_id. If you don't want to look for records that match an admin_id then the query shouldn't have the thing that tries to look for records with a matching admin_id.

 

See where I'm going with that?

Share this post


Link to post
Share on other sites

No, it just means that maybe you shouldn't go messing around in there... At least not without learning first.

 

Your query currently looks for records with a matching admin_id. If you don't want to look for records that match an admin_id then the query shouldn't have the thing that tries to look for records with a matching admin_id.

 

See where I'm going with that?

Haha, I do.   :tease-01: 

 

jhertilus, you can leave off "AND admin_id='$admin_id'" and it should have the effect you want.

 

Alternatively, if you feel you MUST have something there, you could try "AND admin_id IS NOT NULL", or, if all admins have a non-zero ID, "AND admin_id > 0", you could test for length ("AND length(admin_id) > 0") ... but really, requinix is totally correct. :)   Follow the KISS principle.

Edited by dalecosp

Share this post


Link to post
Share on other sites

As long as you are just a beginner and working on one of your first scripts, you should STOP USING OUTDATED CODE. The MySQL functions (if you have read the manual) are outdated and deprecated, as the manual indicates boldly.

 

Spend a little time reading the manual for the PDO functions and look at a couple of examples. It is just as easy to learn as the MySQL functions were and is current and fully supported. Sooner or later your host or whoever is running your server is going to remove the MySQL funcs and then you are really screwed.

 

Be sure to read up on the parts about using prepared queries too!

Share this post


Link to post
Share on other sites

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.