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

Home Posts Topics Members FAQ

fetching one field

let's say i have a table in my database, with only one column. all i
want to do is retrieve a list of the entries.. i could do it like this

$result = mysql_query("SELECT * FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}

but it seems kinda silly to fetch an entire array, when only the first
index is used. is there a better/more efficient way?

Aug 21 '06 #1
7 5999

Mark wrote:
let's say i have a table in my database, with only one column. all i
want to do is retrieve a list of the entries.. i could do it like this

$result = mysql_query("SELECT * FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}

but it seems kinda silly to fetch an entire array, when only the first
index is used. is there a better/more efficient way?
mysql_fetch_row() fetches a row !
as your table has only 1 column the row consists of only 1 value.
What you require is
$result = mysql_query("SELECT * FROM t1");
while ($row = mysql_fetch_array($result)) {
echo $x[0];
}

Aug 21 '06 #2
Suffering from cut&pasteitis
$result = mysql_query("SELECT * FROM t1");
while ($x = mysql_fetch_array($result)) {
echo $x[0];
}
davie wrote:
Mark wrote:
let's say i have a table in my database, with only one column. all i
want to do is retrieve a list of the entries.. i could do it like this

$result = mysql_query("SELECT * FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}

but it seems kinda silly to fetch an entire array, when only the first
index is used. is there a better/more efficient way?
mysql_fetch_row() fetches a row !
as your table has only 1 column the row consists of only 1 value.
What you require is
$result = mysql_query("SELECT * FROM t1");
while ($row = mysql_fetch_array($result)) {
echo $x[0];
}
Aug 21 '06 #3

davie wrote:
Mark wrote:
let's say i have a table in my database, with only one column. all i
want to do is retrieve a list of the entries.. i could do it like this

$result = mysql_query("SELECT * FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}

but it seems kinda silly to fetch an entire array, when only the first
index is used. is there a better/more efficient way?
mysql_fetch_row() fetches a row !
as your table has only 1 column the row consists of only 1 value.
What you require is
$result = mysql_query("SELECT * FROM t1");
while ($row = mysql_fetch_array($result)) {
echo $x[0];
}
uhmm... a row is an array... what exactly is the difference between
your solution and mine?? (aside from also returning an associative
array by default, which i do not need)

perhaps you misinterpreted what i was asking. i'm asking for a solution
that does NOT return an array, but is equally or more efficient.

perhaps this is the best way to do it i guess.

Aug 22 '06 #4
You wanted a list of all entries that is an array
As you have only 1 field (column) per record it is a 1 dimentional
array.
If it had more than 1 field it would be a 2 dimentional array.
mysql_fetch_row() fetches an array of row.
I suggest you read http://www.php.net/manual/en/ref.mysql.php
Mark wrote:
davie wrote:
Mark wrote:
let's say i have a table in my database, with only one column. all i
want to do is retrieve a list of the entries.. i could do it like this
>
$result = mysql_query("SELECT * FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}
>
but it seems kinda silly to fetch an entire array, when only the first
index is used. is there a better/more efficient way?
mysql_fetch_row() fetches a row !
as your table has only 1 column the row consists of only 1 value.
What you require is
$result = mysql_query("SELECT * FROM t1");
while ($row = mysql_fetch_array($result)) {
echo $x[0];
}

uhmm... a row is an array... what exactly is the difference between
your solution and mine?? (aside from also returning an associative
array by default, which i do not need)

perhaps you misinterpreted what i was asking. i'm asking for a solution
that does NOT return an array, but is equally or more efficient.

perhaps this is the best way to do it i guess.
Aug 22 '06 #5

davie wrote:
You wanted a list of all entries that is an array
As you have only 1 field (column) per record it is a 1 dimentional
array.
If it had more than 1 field it would be a 2 dimentional array.
mysql_fetch_row() fetches an array of row.
I suggest you read http://www.php.net/manual/en/ref.mysql.php
Mark wrote:
davie wrote:
Mark wrote:
let's say i have a table in my database, with only one column. all i
want to do is retrieve a list of the entries.. i could do it like this

$result = mysql_query("SELECT * FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}

but it seems kinda silly to fetch an entire array, when only the first
index is used. is there a better/more efficient way?
mysql_fetch_row() fetches a row !
as your table has only 1 column the row consists of only 1 value.
What you require is
$result = mysql_query("SELECT * FROM t1");
while ($row = mysql_fetch_array($result)) {
echo $x[0];
}
uhmm... a row is an array... what exactly is the difference between
your solution and mine?? (aside from also returning an associative
array by default, which i do not need)

perhaps you misinterpreted what i was asking. i'm asking for a solution
that does NOT return an array, but is equally or more efficient.

perhaps this is the best way to do it i guess.
in such case it should be used as
$result = mysql_query("SELECT * FROM t1");
$arr = mysql_fetch_array($result)) ;
foreach($arr as $val) {
// do something with $val
}
if it does indeed retrieve the entire column, no?
I'll look into this more. thanks anyway.

Sep 20 '06 #6
dan
If you have multiple column in your table then use

$result = mysql_query("SELECT column1 FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}

would limit the return data to column1 hence save bandwidth and memory.

Dan.

Mark wrote:
davie wrote:
You wanted a list of all entries that is an array
As you have only 1 field (column) per record it is a 1 dimentional
array.
If it had more than 1 field it would be a 2 dimentional array.
mysql_fetch_row() fetches an array of row.
I suggest you read http://www.php.net/manual/en/ref.mysql.php
Mark wrote:
davie wrote:
Mark wrote:
let's say i have a table in my database, with only one column. all i
want to do is retrieve a list of the entries.. i could do it like this
>
$result = mysql_query("SELECT * FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}
>
but it seems kinda silly to fetch an entire array, when only the first
index is used. is there a better/more efficient way?
mysql_fetch_row() fetches a row !
as your table has only 1 column the row consists of only 1 value.
What you require is
$result = mysql_query("SELECT * FROM t1");
while ($row = mysql_fetch_array($result)) {
echo $x[0];
}
>
uhmm... a row is an array... what exactly is the difference between
your solution and mine?? (aside from also returning an associative
array by default, which i do not need)
>
perhaps you misinterpreted what i was asking. i'm asking for a solution
that does NOT return an array, but is equally or more efficient.
>
perhaps this is the best way to do it i guess.

in such case it should be used as
$result = mysql_query("SELECT * FROM t1");
$arr = mysql_fetch_array($result)) ;
foreach($arr as $val) {
// do something with $val
}
if it does indeed retrieve the entire column, no?
I'll look into this more. thanks anyway.
Sep 20 '06 #7

dan wrote:
If you have multiple column in your table then use

$result = mysql_query("SELECT column1 FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}

would limit the return data to column1 hence save bandwidth and memory.

Dan.

Mark wrote:
davie wrote:
You wanted a list of all entries that is an array
As you have only 1 field (column) per record it is a 1 dimentional
array.
If it had more than 1 field it would be a 2 dimentional array.
mysql_fetch_row() fetches an array of row.
I suggest you read http://www.php.net/manual/en/ref.mysql.php
Mark wrote:
davie wrote:
Mark wrote:
let's say i have a table in my database, with only one column. all i
want to do is retrieve a list of the entries.. i could do it like this

$result = mysql_query("SELECT * FROM t1");
while( $x = mysql_fetch_row($result) ) {
echo $x[0];
}

but it seems kinda silly to fetch an entire array, when only the first
index is used. is there a better/more efficient way?
mysql_fetch_row() fetches a row !
as your table has only 1 column the row consists of only 1 value.
What you require is
$result = mysql_query("SELECT * FROM t1");
while ($row = mysql_fetch_array($result)) {
echo $x[0];
}

uhmm... a row is an array... what exactly is the difference between
your solution and mine?? (aside from also returning an associative
array by default, which i do not need)

perhaps you misinterpreted what i was asking. i'm asking for a solution
that does NOT return an array, but is equally or more efficient.

perhaps this is the best way to do it i guess.
in such case it should be used as
$result = mysql_query("SELECT * FROM t1");
$arr = mysql_fetch_array($result)) ;
foreach($arr as $val) {
// do something with $val
}
if it does indeed retrieve the entire column, no?
I'll look into this more. thanks anyway.
so dont fetch more than you need. got it.

but still..

array mysql_fetch_row ( resource result )

Returns a numerical array that corresponds to the fetched row and moves
the internal data pointer ahead

vs

array mysql_fetch_array ( resource result [, int result_type] )

Returns an array that corresponds to the fetched row and moves the
internal data pointer ahead.
they both return arrays.. but in your case

result_type

The type of array that is to be fetched. It's a constant and can
take the following values: MYSQL_ASSOC, MYSQL_NUM, and the default
value of MYSQL_BOTH.

which defaults to MYSQL_BOTH thus also returns an associative array
which isn't needed...

so IMHO my original solution was ever so slightly more efficient..?
not that i'm trying to stir up an argument, i just don't understand why
you insist that mysql_fetch_array is better than mysql_fetch_row for
this scenario.

Sep 21 '06 #8

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

Similar topics

3
3137
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
3
6040
by: Daves | last post by:
trying to get a boolean value from DataReader (that is, result from a SQL query); boolean MyBool = MyDataReader.GetBoolean(3); well it works using that number 3 but of course I would like to...
0
1686
by: Shujun Huang | last post by:
Hi, I am working on converting Informix database to Postgre. I have one question for fetching records using PostgreSQL. The record I am fetching is a variable size text string. Before fetching...
2
1393
by: Florian Albrecht | last post by:
Hi there, as I am trying to write a recordset class, I am interested in fetching field information from an oracle db. Several information on the fields are very simple to request. So I already...
22
2659
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other...
5
2960
by: Bhavesh | last post by:
Hello genious people, I m trying to insert a LARGE text from Multiline Textbox into my table of sqlserver2000. I m using vs-2005. Please note that I dont want to store blob data From FILE...
1
1813
by: Bhavesh | last post by:
Hi Bruce, Thanks For Reply. U were right, Needed to pass string , but also need to pass size of Data( instead of 16, passed actual length of data). So that worked for me & didn't get any...
17
2009
by: joberman | last post by:
I've about give up with the whole mysql_insert_id function. Always returns a "0". I do have an auto-incrementing field in my database called "ordernumber", which when I query it from another page,...
2
1392
by: nitin005 | last post by:
hi, after fetching the data into the datagridview, how to display the value of a particular field of a selected row, in a textbox. it is a windows application in c#
2
2654
by: SunshineInTheRain | last post by:
I'm trying to modify a long long code within a button click by make the insert/update/delete/select using the same transaction. Purpose is to make sure every operation can be rollback instead of some...
0
6993
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
7162
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
6881
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...
1
4899
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...
0
4584
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
3088
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
1411
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 ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
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...

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.