Jump to content

Recommended Posts

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.

 

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'");

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

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.

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

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

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.