Jump to content

Filling an array from mysql select statement


dpwhite

Recommended Posts

$reeadings is a associative array

 

 

function getdata1()

  {

    $stmt1= "select * from latlonreadings";

    $results = mysql_query($stmt1);

    $line=1;

    while (($row = mysql_fetch_object($results)))

    {

    $readings[$line]=array($row);

    #### this line is wrong

              it fills array but includes more than values(i.e. lat=>12.123456)

    $line=$line+1;

    }

 

 

Try:

<?php
function getdata1()
  {
    $stmt1= "select * from latlonreadings";
    $results = mysql_query($stmt1);
    $line=1;
    while (($row = mysql_fetch_assoc($results)))
     {
          $readings[$line++]=$row;
     }
  }
?>

 

Ken

That cleaned up somethings but here is dump

Array ( [1] => Array ( [ukey] => 143 [cid] => [vid] => 4pas1 => 4 [tnum] => 1234 [driver] => dpw [direction] => N [speed] => 45 [date] => 2008-09-07 [time] => 05:01:00 [timestamp] => 20080907050100 [street] => 460 Race St [description] => Garage [city] => Holyoke [state] => MA [lat] => 42.196175 [lon] => -72.612205 )

it is naming the variables when I just want to put relational data  in array

  (i.e  143,,4pas1,1234,dpw,N,45,2008-09-17,05:01:00, 20080907051000, 460 rase st, garage, holyoke, ma, 42.196175,-72612205

 

Your advice is appreciated

dave

Try this:

<?php
function getdata1()
  {
    $stmt1= "select * from latlonreadings";
    $results = mysql_query($stmt1);
    $line=1;
    while (($row = mysql_fetch_assoc($results)))
     {
          $readings[$line++]=implode(',',$row);
     }
  }
?>

 

Ken

it seemed to work until I looked at the data in the $row

to make it simple:

$array = array(1,,3,4pas1,5);

does not work

it does not like an empty field nor does it like the alpha numeric field 4pas1

so I put data in the empty field and quotes around the alphanumeric

 

$array = array(1,a,3,"4pas1",5);

does work

 

any suggestions

thanks

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.