jhertilus Posted January 30, 2018 Share Posted January 30, 2018 $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 Quote Link to comment https://forums.phpfreaks.com/topic/306373-replacing-a-with-all/ Share on other sites More sharing options...
requinix Posted January 30, 2018 Share Posted January 30, 2018 So how much about SQL do you understand? Quote Link to comment https://forums.phpfreaks.com/topic/306373-replacing-a-with-all/#findComment-1555889 Share on other sites More sharing options...
jhertilus Posted January 30, 2018 Author Share Posted January 30, 2018 none....does that mean I'm screwed? Quote Link to comment https://forums.phpfreaks.com/topic/306373-replacing-a-with-all/#findComment-1555890 Share on other sites More sharing options...
requinix Posted January 30, 2018 Share Posted January 30, 2018 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? Quote Link to comment https://forums.phpfreaks.com/topic/306373-replacing-a-with-all/#findComment-1555893 Share on other sites More sharing options...
dalecosp Posted January 30, 2018 Share Posted January 30, 2018 (edited) 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. 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 January 30, 2018 by dalecosp Quote Link to comment https://forums.phpfreaks.com/topic/306373-replacing-a-with-all/#findComment-1555897 Share on other sites More sharing options...
ginerjm Posted January 31, 2018 Share Posted January 31, 2018 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! Quote Link to comment https://forums.phpfreaks.com/topic/306373-replacing-a-with-all/#findComment-1555904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.