scotch33 Posted December 4, 2007 Share Posted December 4, 2007 I am trying to LIMT results for a query based on the amount of results that a user wishes to see - I am saving the amount the user wishes to see to a session variable, then trying to call it into a sql quey - but I cannot work out the syntax to do thjis - each time I try to build the query, it fails. The code below is what I thought it should be (the session mentioned being a number... // select the right type of user $adult_summary = mysql_query("SELECT * FROM hav_main_account WHERE hav_main_active = '2' LIMIT 1, '$_SESSION[member_show_amount]'"); // end select the right type Can anyone help? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/ Share on other sites More sharing options...
revraz Posted December 4, 2007 Share Posted December 4, 2007 When you start trying to incorporate array variables, it's real easy to get messed up with the quotes. So before the query do $amount = $_SESSION['member_show_amount']; then in your query use LIMIT 1, '$amount'"); Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/#findComment-406101 Share on other sites More sharing options...
scotch33 Posted December 6, 2007 Author Share Posted December 6, 2007 Hi there, Thanks for that, but I am still getting an issue - The problem is - "error performing query:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''25'' at line 2" With the folllowing code (expanded to show all code in section in case anything else in it is causing the issue)... // select the right type of user and amount of records to show if ($_SESSION['member_show_type'] == "active") { $adult_summary = mysql_query("SELECT * FROM hav_main_account WHERE hav_main_active = '2' LIMIT 1, '$amount'"); } elseif ($_SESSION['member_show_type'] == "suspended") { $adult_summary = mysql_query("SELECT * FROM hav_main_account WHERE hav_main_active = '1' LIMIT 1, '$amount'"); } else { $adult_summary = mysql_query("SELECT * FROM hav_main_account LIMIT 1, '$amount'"); } // end select the right type of user and amount of records to show Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/#findComment-407970 Share on other sites More sharing options...
revraz Posted December 6, 2007 Share Posted December 6, 2007 What is line 2 Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/#findComment-407975 Share on other sites More sharing options...
scotch33 Posted December 6, 2007 Author Share Posted December 6, 2007 Well this is an included file. Line 2 of the file that includes it is session_start(); line 2 of the file itself is just html as below <div class="box_top_left"><img src="../sitelook/box_tcorner_left.gif" width="63" height="60" /></div><div class="box_top_right"><img src="../sitelook/box_tcorner_right.gif" width="10" height="60" /></div><div class="box_bottom_left"><img src="../sitelook/box_bcorner_left.gif" /></div><div class="box_bottom_right"><img src="../sitelook/box_bcorner_right.gif" /></div> Also - if i take out '$amount' and use a number, it works as one would expect. Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/#findComment-407982 Share on other sites More sharing options...
revraz Posted December 6, 2007 Share Posted December 6, 2007 Does $amount = 25? or does $amount = "25" ? Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/#findComment-407985 Share on other sites More sharing options...
scotch33 Posted December 6, 2007 Author Share Posted December 6, 2007 aha! "25" original inputs are in a form - <input name="member_show_amount" type="radio" value="10"> 10<br /> <input name="member_show_amount" type="radio" value="25"> 25<br /> <input name="member_show_amount" type="radio" value="50"> 5 Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/#findComment-407987 Share on other sites More sharing options...
revraz Posted December 6, 2007 Share Posted December 6, 2007 Need to make sure it's being passed as a Integer and not a String. Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/#findComment-407992 Share on other sites More sharing options...
scotch33 Posted December 6, 2007 Author Share Posted December 6, 2007 That makes sense - will set them as integers before passing on. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/#findComment-407996 Share on other sites More sharing options...
scotch33 Posted December 6, 2007 Author Share Posted December 6, 2007 ok- that had some effect, but the error is still appearing. the code below includes the settign of the integer. settype($_SESSION['member_show_amount'], 'integer'); $amount = $_SESSION['member_show_amount']; echo gettype($amount); // select the right type of user and amount of records to show if ($_SESSION['member_show_type'] == "active") { $adult_summary = mysql_query("SELECT * FROM hav_main_account WHERE hav_main_active = '2' LIMIT 1, '$amount'"); } elseif ($_SESSION['member_show_type'] == "suspended") { $adult_summary = mysql_query("SELECT * FROM hav_main_account WHERE hav_main_active = '1' LIMIT 1, '$amount'"); } else { $adult_summary = mysql_query("SELECT * FROM hav_main_account LIMIT 1, '$amount'"); } The results I am getting now, are the error below - the '25' it mentions is the number i am using to test and the word integer is from the gettype command b4 the sql query starts. integer error performing query:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''25'' at line 2 Quote Link to comment https://forums.phpfreaks.com/topic/80135-trying-to-limit-sql-results-based-on-user-choice/#findComment-408046 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.