473,386 Members | 1,830 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,386 software developers and data experts.

Assigning values to arrays

Hi,

I am performing a MySQL SELECT (which returns multiple rows) to
$result and then extracting the results with
mysql_fetch_array($result).
I then want to build a number of arrays using the fields of each row.
Here is the relevant code:
<snip>
$result =
$i = 1;
while ($row = mysql_fetch_array($result))
{
extract($row); /* break the row into its fields */
$array0[$i] = $row[0]; /* 1st Field of Row */
$array1[$i] = $row[1]; /* 2nd Field of Row */
$array2[$i] = $row[2]; /* 3rd Field of Row */
$i++;
}
</snip>

Should this work? I am getting unexpected results when I try this.

Thanks.
Jul 17 '05 #1
1 2112
Ched wrote:
I am performing a MySQL SELECT (which returns multiple rows) to
$result and then extracting the results with
mysql_fetch_array($result).
I then want to build a number of arrays using the fields of each row.
Here is the relevant code:
<snip>
$result =
$i = 1;
while ($row = mysql_fetch_array($result))
{
extract($row); /* break the row into its fields */
Why??? You're not using the isolated variables ...
If $row is an array like
array('id'=>3, 'name'=>'pedro', 'email'=>'h*****@hotpop.com')

that extract() call will create
$id = 3;
$name = 'pedro';
$email = 'h*****@hotpop.com';
$array0[$i] = $row[0]; /* 1st Field of Row */
You set $i to 1; arrays usually start at 0.
$array1[$i] = $row[1]; /* 2nd Field of Row */
$array2[$i] = $row[2]; /* 3rd Field of Row */
$i++;
}
</snip>

Should this work?
Yes.
I am getting unexpected results when I try this.


What did you expect?
What happens differently?

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

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

Similar topics

2
by: Zitan Broth | last post by:
Greetings All, Running pg 7.3.4 and was reading: http://archives.postgresql.org/pgsql-interfaces/2003-09/msg00018.php . Basically want to assign values to an array and then a 2d array. However...
14
by: Eric Bantock | last post by:
Very basic question I'm afraid. Once an array has been declared, is there a less tedious way of assigning values to its members than the following: myarray=8; myarray=3; myarray=4; myarray=0;...
2
by: Ray D. | last post by:
I want to set matrix A with the values below, but it produced a syntax error when I try to compile the commented code. I was told to use a for loop to do this (as shown below), but that really...
43
by: emyl | last post by:
Hi all, here's an elementary question. Assume I have declared two variables, char *a, **b; I can then give a value to a like a="hello world";
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.