Forum Moderators: coopster

Message Too Old, No Replies

spot the error

argh *(@(!*@!(*

         

dmmh

4:50 pm on Feb 8, 2005 (gmt 0)

10+ Year Member



Excuse me for bugging you guys for something that ought to be simple, but somehow this thing gives me error message

I just cant spot the error, a pair of helping eyes would be nice :)

function func_select_random_members_pay($1, $2, $skip_uid)
{
@mysql_select_db('db');
$query = 'SELECT * FROM table'.
" WHERE value > '$1'".
" AND user_id!= '$skip_uid'".
" LIMIT '$2'";
$result = mysql_query($query) or die ("Error selecting random members from database");
if ($result){
return true;
}else{
return false;
}
}

aside from the fact this isnt random, still have to modify the query from that...what is wrong here? :( been looking at it for half an hour now and it seems ok to me

jatar_k

5:41 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what might the error message be?

kilonox

6:06 pm on Feb 8, 2005 (gmt 0)

10+ Year Member



$query = 'SELECT * FROM table'.
" WHERE value > '$1'".
" AND user_id!= '$skip_uid'".
" LIMIT '$2'";

....

$query = '
SELECT * FROM table WHERE value > '.$1.'
AND user_id!= '.$skip_uid.' LIMIT '.$2;

?

jatar_k

7:16 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if I use this to test the vars

<?
$query = 'SELECT * FROM table'.
" WHERE value > '$1'".
" AND user_id!= '$skip_uid'".
" LIMIT '$2'";
echo '<p>1: ',$query;

$query = '
SELECT * FROM table WHERE value > '.$1.'
AND user_id!= '.$skip_uid.' LIMIT '.$2;
echo '<p>2: ',$query;
?>

then I get

Parse error: parse error, unexpected T_DNUMBER, expecting T_VARIABLE or '$' in #*$! on line 10

so I make the second one a single line

$query = 'SELECT * FROM table WHERE value > '.$1.' AND user_id!= '.$skip_uid.' LIMIT '.$2;

and get
Parse error: parse error, unexpected T_DNUMBER, expecting T_VARIABLE or '$' in xxx on line 8

so we stop using numbers for varnames in the second query
$query = 'SELECT * FROM table WHERE value > '.$a1.' AND user_id!= '.$skip_uid.' LIMIT '.$b2;

and my output is

1: SELECT * FROM table WHERE value > '$1' AND user_id!= '' LIMIT '$2'

2: SELECT * FROM table WHERE value > AND user_id!= LIMIT

so the second one resolves properly but the first is still hooped

[php.net...]

A valid variable name starts with a letter or underscore,

grandpa

8:30 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$query = 'SELECT * FROM table WHERE value > '.$a1.' AND user_id!= '.$skip_uid.' LIMIT '.$b2;

There appears to be a problem in that you are using the period in your query. Try it without them. Also noticed a missing apostrophe on the variable $b2. Also, not sure, but there is no space after the field name, user_id. Finally, I quote the entire query string.

$query = "SELECT * FROM table WHERE value > '$a1' AND user_id!= '$skip_uid' LIMIT '$b2' ";

<edit> I think the missing space after user_id has something to do with the editing of the message. ie, it closes up and I know I've editied it twice now...
</edit>

dmmh

11:13 pm on Feb 8, 2005 (gmt 0)

10+ Year Member



really never knew you couldnt use a number for a variable name, one learns every day :)
thanks people

really doesnt matter if you make a query the way I did, on multiple lines, I use it for huge queries for better readability and have adopted the same way for smaller queries...to stay concistent :)

grandpa

11:27 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



really never knew you couldnt use a number for a variable name

But you can, sort of. It just has to be assigned first.

$ROWNUM = 'ROW' . $row_number;
Gives me $ROW1, $ROW2, $ROW3.... whatever value is currently assigned to $row_number.

Otherwise, variable names must begin with a letter or underscore. So, $1 = 1 is illegal (but you discovered that already...)

dmmh

12:03 am on Feb 9, 2005 (gmt 0)

10+ Year Member



your first reply to this topic was all about the bugged query of someone else grandpa, not my query ;)

thanks anyway though, just thought I should mention it :)