473,498 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can i make a selection from a table random?

117 New Member
Ok, i want to make a sql statment select from a table, random quotes and display a random one each time the page is loaded!

I got it to connect, but it keeps selecting all of them...

[PHP]<?php
$sql = "select * from randomquotes where quote= $quote limit $quote,1";
$result = mysql_query($sql ,$db);
?>
Rando Quote: <? echo ("$quote"); ?>[/PHP]

So in the end it will load only one of the 500 table and be random each time selecting from any of them.
I hope i was clear on what i need.
Sep 1 '07 #1
4 1229
mwasif
802 Recognized Expert Contributor
The following query will select randomly one record
Expand|Select|Wrap|Line Numbers
  1. select * from randomquotes ORDER BY RAND() LIMIT 1
Sep 1 '07 #2
Breana
117 New Member
How can i get it to load table randomquotes, table quote
and have it print it random?

It comes up blank.
[PHP]<?php
$sql = "SELECT * quote FROM randomquotes ORDER BY RAND() LIMIT 1";
$result = mysql_query($sql ,$db);
?>Rando Quote: <? echo ("$quote"); ?>[/PHP]
Sep 2 '07 #3
Weisbartb
36 New Member
You are missing a fetch function.
[PHP]<?php
$sql = "SELECT * quote FROM randomquotes ORDER BY RAND() LIMIT 1";
$result = mysql_query($sql ,$db);
$row = mysql_fetch_assoc($result);
?>
Random Quote:
<?
echo ($row['cellnameofquote']);
?>[/PHP]
Sep 2 '07 #4
Breana
117 New Member
Sweet thanx, i keep for getting about the fetch part lol.
SOLVED
Sep 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3216
by: Andie | last post by:
Hello All, How would I go about using a disconnect recordset and select (x) records from it, x being the number of records to be selected. Many thanks in advance. -- Andie
7
2704
by: middletree | last post by:
Posted this to Access group, meant to do it here: I have what I call a composite table. Can't recall what they called it in database class, but it's where you take the PK of two different...
1
1532
by: Micak | last post by:
I'm using radnom selection in ms access to select certain number of questions for the exam. i have two versions of the report: - one without marked answers - one with marked answers the problem...
2
4826
by: IceCube | last post by:
Hello, I would like to select/filter at random 30 records out of an Access-table of 1500 records. I know the option "Top" which gives me the possibility to see the 30 first records of the table...
3
2369
by: Jay Ruyle | last post by:
I'm trying to figure out a way to list several items in a listbox and let the user select any number of items in the listbox. I have tried to code in the items as bitwise items but all it stores...
13
2336
by: Bruza | last post by:
I need to implement a "random selection" algorithm which takes a list of as input. Each of the (obj, prob) represents how likely an object, "obj", should be selected based on its probability of...
3
1287
by: whiteyoh | last post by:
Hi, I have a script that can select a number of random records to display but what im after is a snippet of code on the first selection will choose a random record, but on the second selection...
3
2314
by: Manuel Ebert | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear list, who's got aesthetic advice for the following problem? I've got some joint probabilities of two distinct events Pr(X=x, Y=y), stored...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.