473,394 Members | 1,700 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.

retrieve individual rows from mysql_fetch_array not using while loop

hi all

im querying a db for two rows which are always returned. how can i
reference each row and output its contents without using a while loop.
ive tried:

$row = mysql_fetch_array($result);
extract $row;
echo $var1[0]; //var 1 of row 0
echo $var1[1]; //var 1 of row 1
but this doesnt seem to be working?

kind regards

Marc

Aug 15 '06 #1
3 7415

if you talk about rows and not about columns, try this :

$row0 = mysql_fetch_array($result);
$row1 = mysql_fetch_array($result);
extract $row0;
extract $row1;
echo $row0[0]; //var 1 of row 0
echo $row1[0]; //var 1 of row 1

A+
"monomaniac21" <mc******@googlemail.coma écrit dans le message de news:
11**********************@i3g2000cwc.googlegroups.c om...
hi all

im querying a db for two rows which are always returned. how can i
reference each row and output its contents without using a while loop.
ive tried:

$row = mysql_fetch_array($result);
extract $row;
echo $var1[0]; //var 1 of row 0
echo $var1[1]; //var 1 of row 1
but this doesnt seem to be working?

kind regards

Marc

Aug 15 '06 #2
Rik
monomaniac21 wrote:
hi all

im querying a db for two rows which are always returned. how can i
reference each row and output its contents without using a while loop.
ive tried:

$row = mysql_fetch_array($result);
extract $row;
echo $var1[0]; //var 1 of row 0
echo $var1[1]; //var 1 of row 1
Nope, it won't.
You only retrieve 1 row, you call mysql_fetch_array just once.
Furthermore, extract will create vartiables named after you fieldnames or
aliasses deriving from the query.

I think you're looking for this:
$row0var1 = mysql_result($result,0,0); (or: mysql_result($result,0); for the
first value)
$row1var1 = mysql_result($result,1,0);

Grtz,
--
Rik Wasmus
Aug 15 '06 #3
"monomaniac21" <mc******@googlemail.compíse v diskusním príspevku
news:11**********************@i3g2000cwc.googlegro ups.com...
hi all

im querying a db for two rows which are always returned. how can i
reference each row and output its contents without using a while loop.
ive tried:

$row = mysql_fetch_array($result);
extract $row;
echo $var1[0]; //var 1 of row 0
echo $var1[1]; //var 1 of row 1
but this doesnt seem to be working?
You can to modify sql query for returning one row only (eg. using HAVING
....) or you can use
mysql_data_seek() before mysql_fetch_array().

Tip for you:
mysql_fetch_assoc() is more friendly then mysql_fetch_array().
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)

Aug 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Kaku | last post by:
I'm trying to retrieve a text value from a MySQL database, put it into an updateable form, allow edits, and send back the edited text back into the MySQL database. I've been able to successfully...
15
by: Good Man | last post by:
Hey there I have a dumb question.... Let's say i have a database full of 4000 people.... I select everything from the database by: $result = mysql_query("SELECT * FROM People");
6
by: PG | last post by:
When deleting a row from the database, that id is now missing. So what I'm trying to do is update in a loop (maybe an sql loop if there is one) of all of the id numbers - sort of like renaming...
8
by: julian_m | last post by:
let's say I've an array of articles's id $arr_art_id=(1, 551, 2015, 6 .......n ) what option is better (1 or 2), in order to achieve better performance? (pseudo code) 1) for i=0 to array...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
0
by: thegametb | last post by:
I got this wrestling database I'm developing. It's not as straight and narrow as most sport databases are, but this has got me stumped a bit. I am trying to implement their stats in to their specific...
2
by: mukeshrasm | last post by:
hello i want to display the subjects on the same page based on class selected by user. i am using dropdown for classes. so when user will select a particular class then it will display subjects in...
2
by: John | last post by:
I am having trouble getting this code to work, and was wondering if someone could tell me what I am doing wrong. -------------------------------------- CODE--------------------------------------...
5
by: jmDesktop | last post by:
In my code I cannot figure out how to retrieve multple rows from my returned array from a class method. I have tried: <?php class myClass { private $connection; /* Class constructor */...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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.