473,819 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

retrieve individual rows from mysql_fetch_arr ay 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_arr ay($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 7507

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

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

A+
"monomaniac 21" <mc******@googl email.coma écrit dans le message de news:
11************* *********@i3g20 00...legro 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_arr ay($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_arr ay($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_arr ay 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($r esult,0,0); (or: mysql_result($r esult,0); for the
first value)
$row1var1 = mysql_result($r esult,1,0);

Grtz,
--
Rik Wasmus
Aug 15 '06 #3
"monomaniac 21" <mc******@googl email.compíse v diskusním príspevku
news:11******** **************@ i3g2000cwc.goog legroups.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_arr ay($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_arr ay().

Tip for you:
mysql_fetch_ass oc() is more friendly then mysql_fetch_arr ay().
--

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
5282
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 retrieve the text and put it into the editable form, using htmlspecialchars function. But, I can't find a way of accepting the edited text and sending back to the database. Here's my code for retrieval. <?php
15
2690
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
4043
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 them. It did partly work because all the id's were set to 22. Thats because there was 22 rows. Here's the code I used: $result = mysql_query ("SELECT * FROM counter"); for($counting = 1; $row = mysql_fetch_row ($result); ++$counting)
8
1697
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 count{ select * from articles where articles.id=$arr_art_id
3
32284
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 datatable without having to loop through each column in the datagridview? Or is there a way to retrieve the rows from the original datatable filtered by the dataview into a separate table? I only want to copy the rows from the main table that...
0
1677
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 profiles, but instead of having them naturally split (while loop), I need them to be accumulated (sp?) in to win one sole row of data. So in essence, I want all of the possible values added as one complete value. I'm going to give some rough...
2
5354
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 the same page based on class from database. i am giving my code along with so please tell me the error. code for database <?php include "database.php";
2
1679
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-------------------------------------- if (isset($_POST)) { require_once("database.php"); $appt_date = $_POST . '/' . $_POST . '/' . $_POST;
5
6651
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 */ function myClass(){
0
9748
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10458
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10159
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9250
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7700
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6910
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5724
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4381
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 we have to send another system
3
3046
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.