Re: Help with array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for the reply
I do not under stand how to apply your example
$foo[$i][$j] = "bar";

Graph example array trying to create thru sql:

$data = array(
array(0,"Concept","2002-9-1","2002-9-15",blue),
array(1,"Creative","2002-9-15","2002-9-30",red),
array(2,"Produce","2002-9-31","2002-10-10",green)):

Output $data looks like this:
0: 0
1: Concept
2: 2002-9-1
3: 2002-9-15
4: blue
0: 1
1: Creative
2: 2002-9-15
3: 2002-9-30
4: red
0: 2
1: Produce
2: 2002-9-31
3: 2002-10-10
4: green


SQL:
$query = "SELECT task, startdate, endend, barcolor
 FROM timeline WHERE jobnu = 8648";
 $result = mysql_query ($query);

    $cpt=0; $rownu =0;
    while($row = mysql_fetch_row($result))
    {
    $data[$cpt]=
$rownu.","."\"".$row[0]."\"".",\"".$row[1]."\","."\"".$row[2]."\"";
    $rownu++;
    $cpt++;

Output $data
0,Concept,2002-9-1,2002-9-15,blue
1,Creative,2002-9-15,2002-9-30,red
2,Produce,2002-9-31,2002-10-10,green
etc....

 I have tried this:

while ($data[]=mysql_fetch_row($result)){}

This almot works but for some reason places a blank record at the end or the
array.

> and to put stuff into the two dimensions, you need something like
> $foo[$i][$j] = "bar";
> and iterate over the values $i and $j.

Could you go a step farther in the $foo[$i][$j]
please

20" of snow today in New Windsor, MD....

thanks

jrt


"Fredrik De Vibe" <fredrik@devibe.net> wrote in message
ygrwuk0mluf.fsf@tva.ifi.uio.no">news:ygrwuk0mluf.fsf@tva.ifi.uio.no...
> john@jrthorne.com (John Thorne) writes:
> > $data[$cpt]= $row[0].",".$row[1].",".$row[2].",".$row[3].",".$row[4];
>
> What you need is a two dimensional array. The code above concatenates
> the $row elements into a string and puts this string into a one
> dimensional array.
>
> the 2D array $foo[3][5] can be seen as:
>
>    0 1 2 3 4
>   +-+-+-+-+-+
> 0 | | | | | |
>   +-+-+-+-+-+
> 1 | | | | | |
>   +-+-+-+-+-+
> 2 | | | | | |
>   +-+-+-+-+-+
>
> and to put stuff into the two dimensions, you need something like
> $foo[$i][$j] = "bar";
> and iterate over the values $i and $j.
>
>
> --
> --Fredrik
> "Why be a man when you can be a success?"
> -- Bertold Brecht



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux