Re: ORDER BY RAND() not working

2002-07-12 Thread Arthur Fuller

I don't have your exact setup installed so cannot verify this, but how about
rewriting your statement a little? I just tried this in mysql and it works
fine, so it may from php. Let me know :-)

Change the query to:

SELECT *, Rand() as MyOrder
FROM products
WHERE sale_price IS NOT NULL
ORDER BY MyOrder;

hth,
Arthur

- Original Message -
From: Jamie Tibbetts [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, July 11, 2002 1:14 PM
Subject: Re: ORDER BY RAND() not working


  $id = mysql_query(SELECT * FROM products WHERE sale_price IS NOT NULL
ORDER
  BY RAND() LIMIT 3,$link) or die(mysql_error());

 PHP code:
 $result = mysql_query(SELECT * FROM products WHERE sale_price IS NOT NULL
 ORDER BY RAND() LIMIT 3) or die(mysql_error());

 The error message is as follows:

 You have an error in your SQL syntax near 'RAND() LIMIT 3' at line 1

 Jamie

 Jamie Tibbetts.[EMAIL PROTECTED]
 Epigroove .http://www.epigroove.com/


 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail
[EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




ORDER BY RAND() not working

2002-07-11 Thread Jamie Tibbetts

I'm running PHP 4.1.2 and MySQL 3.23.39. I have a simple query that works if
I telnet into MySQL and run the query manually. If I try and use it in a PHP
page, I get the Supplied argument is not a valid MySQL result resource
error. However, if I take out the ORDER BY RAND() part from the query, it
works in PHP.

Doesn't work:
SELECT * FROM products WHERE sale_price IS NOT NULL ORDER BY RAND() LIMIT 3

Works:
SELECT * FROM products WHERE sale_price IS NOT NULL LIMIT 3

Does anyone have any idea why this is happening?

Thanks,
Jamie

Jamie Tibbetts.[EMAIL PROTECTED]
Epigroove .http://www.epigroove.com/


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: ORDER BY RAND() not working

2002-07-11 Thread Jay Blanchard

[snip]
I'm running PHP 4.1.2 and MySQL 3.23.39. I have a simple query that works if
I telnet into MySQL and run the query manually. If I try and use it in a PHP
page, I get the Supplied argument is not a valid MySQL result resource
error. However, if I take out the ORDER BY RAND() part from the query, it
works in PHP.

Doesn't work:
SELECT * FROM products WHERE sale_price IS NOT NULL ORDER BY RAND() LIMIT 3

Works:
SELECT * FROM products WHERE sale_price IS NOT NULL LIMIT 3

Does anyone have any idea why this is happening?
[/snip]

Need to see your PHP code, that's where it's broken.

Jay
sql, mysql, query :^)



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: ORDER BY RAND() not working

2002-07-11 Thread Alain Fontaine

What does your PHP code look like ? It might be a syntax problem inside PHP


-Message d'origine-
De : Jamie Tibbetts [mailto:[EMAIL PROTECTED]]
Envoye : jeudi 11 juillet 2002 18:22
A : [EMAIL PROTECTED]
Objet : ORDER BY RAND() not working

I'm running PHP 4.1.2 and MySQL 3.23.39. I have a simple query that works if
I telnet into MySQL and run the query manually. If I try and use it in a PHP
page, I get the Supplied argument is not a valid MySQL result resource
error. However, if I take out the ORDER BY RAND() part from the query, it
works in PHP.

Doesn't work:
SELECT * FROM products WHERE sale_price IS NOT NULL ORDER BY RAND() LIMIT 3

Works:
SELECT * FROM products WHERE sale_price IS NOT NULL LIMIT 3

Does anyone have any idea why this is happening?

Thanks,
Jamie

Jamie Tibbetts.[EMAIL PROTECTED]
Epigroove .http://www.epigroove.com/


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: ORDER BY RAND() not working

2002-07-11 Thread Jamie Tibbetts

 $id = mysql_query(SELECT * FROM products WHERE sale_price IS NOT NULL ORDER
 BY RAND() LIMIT 3,$link) or die(mysql_error());

PHP code:
$result = mysql_query(SELECT * FROM products WHERE sale_price IS NOT NULL
ORDER BY RAND() LIMIT 3) or die(mysql_error());

The error message is as follows:

You have an error in your SQL syntax near 'RAND() LIMIT 3' at line 1

Jamie

Jamie Tibbetts.[EMAIL PROTECTED]
Epigroove .http://www.epigroove.com/


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: ORDER BY RAND() not working

2002-07-11 Thread Jay Blanchard

[snip]
PHP code:
$result = mysql_query(SELECT * FROM products WHERE sale_price IS NOT NULL
ORDER BY RAND() LIMIT 3) or die(mysql_error());

The error message is as follows:

You have an error in your SQL syntax near 'RAND() LIMIT 3' at line 1
[/snip]

Using;

$query = select * from tblBAR WHERE DiskSize IS NOT NULL ORDER BY RAND()
LIMIT 3 ;
if(!($db = mysql_query($query, $dbconnect))){
print(MySQL reports:  . mysql_error() . \n);
exit();
}
while($row = mysql_fetch_object($db)){
print($row-ID . nbsp . $row-ClientName . br);
}

This worked fine for me. Maybe there is not a space between NULL and ORDER?

Jay



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php