Array question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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


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.


Re: Array question

Quoted text here. Click to load it

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

- Jacob Atzen

Re: Array question

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
 $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) ??


Quoted text here. Click to load it

Re: Array question

Irlan agous wrote:
Quoted text here. Click to load it

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];


Re: Array question

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

Quoted text here. Click to load it

Re: Array question

On Wed, 13 Apr 2005 23:00:21 +0200, Irlan agous wrote:
Quoted text here. Click to load it">

Firefox Web Browser - Rediscover the web - /
Thunderbird E-mail and Newsgroups - /

Site Timeline