473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Fetch xth item from mysql_array

15
Hey gentlebeings,

I'm pretty sure this is possible, just can't find the correct way to do it.

I want to select the contents of my table of testimonials, and randomly display one of them on the screen.

So the thinking we had over here was to count the number of rows and then select the xth row for display. We just weren't sure on the options available to us. :)

One option was to count the rows, use that number for the basis for a random select (i.e. mt_rand(1,$num_testimonials)) and select that row.

Just not sure if that would work at all...

If I recall correctly, fetching an associative array will allow us to move forward and backwards through it, so somehow this should be possible.

I'm open to all suggestions, can't even think of a way to start this.

Thanks,

Ray
Nov 17 '08 #1
2 1487
RayDube
15
Duh!

Sorry people, the answer was so obvious it slapped us in the face!

Expand|Select|Wrap|Line Numbers
  1. SELECT column FROM table ORDER BY RAND() LIMIT 1 
Works like a charm!

Ray

(figures we should have just spoken to the sql guru rather than the php guru)
Nov 17 '08 #2
Markus
6,050 Expert 4TB
Glad you got that sorted.
Nov 17 '08 #3

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

Similar topics

2
by: Max M | last post by:
I am using the fetch command from the imaplib to fetch messages. I get a result, but I am a bit uncertain as to how I should interpret it. The result is described at...
1
by: Agoston Bejo | last post by:
The problem is as follows: I have a stored proc. that returns a types.ref_cursor (where types.ref_cursor is defined as 'ref cursor'): PROCEDURE P(c OUT TYPES.ref_cursor); The returned cursor has...
8
by: Evan Smith | last post by:
During a routine performance check using an event monitor, I discovered a class of query whose performance has me baffled. The monitor captured: SELECT * FROM EWM_CASE fetch first 1 rows only...
9
by: Acupuncture | last post by:
Hi, I am developing a JDBC application and I encountered this problem (DB2 for ISeries). I want to do a select for update and also use the fetch first rows clause. This is my sql statement: ...
7
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that...
0
by: vinidimple | last post by:
Hi i have a serious problem while i was working in Excel.I want to fetch columns from an excel worksheet and i need to compare it with an sql querry fields,so i tried to open an excle...
10
by: scoonie999 | last post by:
I'm having a problem that I can't seem to find any solution for online. I'm using a cursor in a cobol program to fetch some data. I know for a fact that the select should return 2 rows. The...
2
by: krishnasarma | last post by:
Hi all ... . In listbox if list1.selected(index) property is true then particular item is selected . How to get the selected items in listview.Kindly tell me with simple examplesThanx in advance...
0
by: raman2ss | last post by:
Hi All, I have added a dropdownlist to the datagrid at runtime. Dim DropDownList1 As New DropDownList DropDownList1 .Items.Add("R") DropDownList1 .Items.Add("D") ...
7
by: Frank Swarbrick | last post by:
Is there a way to do a multi-row fetch in to a COBOL table with DB2/LUW? Apparently the following is supported in z/OS, but not LUW (or at least I couldn't get it to work): WORKING-STORAGE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.