473,465 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Array question

Hello all,

I have a mysql select query and got it in an array

$query = "select persid from reactie";

$result = mysql_query($query);
$query_data = mysql_fetch_array($result);// Haal de gegevens uit de
tabel

NOW I WANT TO ECHO I"T:

echo "$query_data[8]";

But only the query_date[0] is valid. What am i doing wrong? there are many
more values in the table. I want to make an array with all the values from
the field "persid" in the database.

Irlan

Jul 17 '05 #1
5 1697
Irlan agous wrote:
But only the query_date[0] is valid. What am i doing wrong? there are
many more values in the table. I want to make an array with all the
values from the field "persid" in the database.


Although the result might return many rows, a single row is what you are
getting with your code.

If you want to populate an array with all retrieved values, you should do
someting like:

while ($query_data = mysql_fetch_array($result)) {
$array[] = $query_data[0];
}

JW

Jul 17 '05 #2
On 2005-04-13, Irlan agous <ir******@msn.com> wrote:
$query = "select persid from reactie";

$result = mysql_query($query);
$query_data = mysql_fetch_array($result);// Haal de gegevens uit de
tabel

NOW I WANT TO ECHO I"T:

echo "$query_data[8]";


Every call to mysql_fetch_array() will return a row from your query
result. The normal way to get all the data is to loop like this:

while($row = mysql_fetch_array($result)) {
// Do something with $row
}

--
Cheers
- Jacob Atzen
Jul 17 '05 #3
Thanks that worked!

Now i get a list
of all the persid's like 2,2,3,4,4,4,5. I want to select the maximun
existing values, the second maximum etc. For example in this care number 4
had the highest rank(with 3 times), second is 2 (with 2 times) etc. But how
can i save distinct numbers and its amount to a variable? becouse then im
able to check which one is the maximum etc, thanks for the help
But only the query_date[0] is valid. What am i doing wrong? there are
many more values in the table. I want to make an array with all the
values from the field "persid" in the database.


Although the result might return many rows, a single row is what you are
getting with your code.

If you want to populate an array with all retrieved values, you should do
someting like:

while ($query_data = mysql_fetch_array($result)) {
$array[] = $query_data[0];
}

JW

Jul 17 '05 #4
On Wed, 13 Apr 2005 23:00:21 +0200, Irlan agous wrote:
of all the persid's like 2,2,3,4,4,4,5. I want to select the maximun
existing values, the second maximum etc. For example in this care number 4
had the highest rank(with 3 times), second is 2 (with 2 times) etc. But how


http://dev.mysql.com/doc/mysql/en/counting-rows.html
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #5
ell i tried, and i came to the next step, i got this script working now

$query = "SELECT persid, count(logid) from reactie GROUP BY persid order by
persid";
$result = mysql_query($query);
$query_data = mysql_fetch_array($result);
$total_num_user = $query_data[0];

while($query_data = mysql_fetch_array($result)){
$tlogid = $query_data["count(logid)"];
$persid = $query_data["persid"];

echo "$persid =";

echo "$tlogid<br>";

}

shown as:
persid - count(logid)
16 =1
18 =2
19 =1
20 =2
21 =5

now how can i write the scrip that i can select the maximum value of
count(logid) ??

Irlan

$result = mysql_query($query);
$query_data = mysql_fetch_array($result);// Haal de gegevens uit
de
tabel

NOW I WANT TO ECHO I"T:

echo "$query_data[8]";


Every call to mysql_fetch_array() will return a row from your query
result. The normal way to get all the data is to loop like this:

while($row = mysql_fetch_array($result)) {
// Do something with $row
}

--
Cheers
- Jacob Atzen

Jul 17 '05 #6

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

Similar topics

3
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include...
9
by: buda | last post by:
Hi, I've been wondering for a while now (and always forgot to ask :) what is the exact quote from the Standard that forbids the use of (&array) (when x >= number_of_columns) as stated in the FAQ...
3
by: Pol Bawin | last post by:
Hi All, One : I have a property that get/set a array of an abstract class A By default my array is null In the propertygrid, It is not works correctly when my array is null. (when my array...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
51
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
8
by: T. Wintershoven | last post by:
Hello all, I have a form with some checkboxes. The names of these checkboxes come from an array. When i click the submit button the resultcode doesn't recognize the names when i want to check...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
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,...
1
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...
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...
0
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,...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.