473,769 Members | 5,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_arr ay($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_arr ay($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 2128
Ched wrote:
I am performing a MySQL SELECT (which returns multiple rows) to
$result and then extracting the results with
mysql_fetch_arr ay($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_arr ay($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
3392
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 I can't get this to run in properly I get a syntax error (at or near ", output_txt_arr TEXT, output_str text ); CREATE OR REPLACE FUNCTION F_TEST(TEXT) RETURNS NUMERIC AS '
14
74899
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; myarray=0; myarray=1; myarray=8;
2
4049
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 isn't possible considering I need these specific values. Is there a way to do this in one statement instead of multiple statements of A = ..., where I manually specify the position? Why can you initialize like this with a static array, but can't...
43
17230
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
9589
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...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8872
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
7410
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
6674
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.