Random Value for SQL

Started on the old forum in January 2010 · view the original in the archive · old links redirect here

8 replies · 541 views · started 16 years ago · 1 min read

4 participants
kei_ki7 Senior · 431 posts #1

$pot = mysql_fetch_array(mysql_query("SELECT pid FROM ibwf_albumpic WHERE private='0' ORDER BY rand() LIMIT 1"));

$new = mysql_fetch_array(mysql_query("SELECT MAX(pid) FROM ibwf_albumpic WHERE private='0'"));

is that correct?

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/kendee/public_html/wap/v2/album.php on line of $pot

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/kendee/public_html/wap/v2/album.php on line of $new

for $pot i just want to get random pid in ibwf_albumpic for 1day (picture of the day)

and for $new i just want to get the maximum value of pid to get the newest pid or order by time

Did I help you? You can help me too Your donations will help me finance my studies.

ori Lead · 512 posts #2

the query looks fine whats the contents of ya table like rows etc

ZED Newbie · 5 posts #3

be sure that ur SqL is correct lol ....try this

$pot = mysql_fetch_array(mysql_query("SELECT DISTINCT pid FROM ibwf_albumpic WHERE private='0' ORDER BY RAND() LIMIT 1")); or

$pot = mysql_fetch_array(mysql_query("SELECT DISTINCT id FROM ibwf_albumpic WHERE private='0' ORDER BY RAND() LIMIT 1"));

or

$pot = mysql_fetch_array(mysql_query("SELECT DISTINCT id, uid FROM ibwf_albumpic WHERE private='0' ORDER BY RAND() LIMIT 1"));

thanatos Senior · 261 posts #4
SELECT pid FROM table WHERE private='0' ORDER BY time DESC LIMIT 1
ZED Newbie · 5 posts #5

thanatos wrote:

SELECT pid FROM table WHERE private='0' ORDER BY time DESC LIMIT 1

this in not random ..... it place 1st or last photo

thanatos Senior · 261 posts #6

look at his post.. he wants to get newest value of pid..

ZED Newbie · 5 posts #7

ah ok dude ...i dont see bout that i just look @ the title

ori Lead · 512 posts #8

the 1st query is for random result 2nd is for pid value

kei_ki7 Senior · 431 posts #9

ori wrote: the query looks fine whats the contents of ya table like rows etc

thanks for that info! i think i got a heavy stress 🙂

ZED wrote: be sure that ur SqL is correct lol ....try this

$pot = mysql_fetch_array(mysql_query("SELECT DISTINCT pid FROM ibwf_albumpic WHERE private='0' ORDER BY RAND() LIMIT 1")); or

$pot = mysql_fetch_array(mysql_query("SELECT DISTINCT id FROM ibwf_albumpic WHERE private='0' ORDER BY RAND() LIMIT 1"));

or

$pot = mysql_fetch_array(mysql_query("SELECT DISTINCT id, uid FROM ibwf_albumpic WHERE private='0' ORDER BY RAND() LIMIT 1"));

thanks for the red font 🙂 same comment 🙂

thanatos wrote:

SELECT pid FROM table WHERE private='0' ORDER BY time DESC LIMIT 1

thanks for the reply 🙂

by the way i got wrong column thanks to all =)

Did I help you? You can help me too Your donations will help me finance my studies.

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close