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;

    }

 

 

Link to comment
Share on other sites

Try:

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

 

Ken

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.