Jump to content

Arrays from MySQL database contains no data? (Simple Q)


rjt90

Recommended Posts

$fetch_data = mysql_query("SELECT * FROM data WHERE data_id IN ($var_hook) ORDER BY time_id ASC");


$series = array(); 
foreach ($var_hook as $id) { 
    $series[$id] = array();
}  


while ($new_row = mysql_fetch_array($fetch_data)) {
     $series[$new_row["data"]][] = $new_row;
}


print_r($series[1]);

Hey - haven't coded for a while. Essentially I am trying to obtain info in the database where "data_id" matches one of the entries in $var_hook. For all matches (e.g. there may be two series that match) i want to create corresponding arrays that contain the data entries ("data") for each series.

 

Above I have created the series arrays, but when I try and attach the rows (data entries) to the series, it doesn't seem to register within the respective series arrays? Would appreciate help! I expect it is an elementary error - but can't see it yet!

Link to comment
Share on other sites

Var_hook is already formatted correctly (imploded). So the SQL correctly creates the number of arrays. My problem is that I can't make the arrays contain data? E.g. when I print the first series, it does not contain the data content for that series?

Link to comment
Share on other sites

do you have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini? i can see 3-4 different things that could produce errors in the posted code.

 

that you are using a foreach() loop on $var_hook indicates it ISN'T an imploded list. it's an array and it cannot be used directly in the query statement like you have shown in your code or the foreach() loop isn't doing what you expect.

 

do you have a column named `data` in your data table so that $new_row["data"] actually exists to use as an array index?

 

since you haven't shown what your input data is, what result you got, and what result you expected from that input data, it's not really possible to help you with what you are doing. you need to share more details.

Link to comment
Share on other sites

Var_hook is already formatted correctly (imploded). So the SQL correctly creates the number of arrays. My problem is that I can't make the arrays contain data? E.g. when I print the first series, it does not contain the data content for that series?

Then you need to explode it before you do this.

 

foreach ($var_hook as $id) { 

    $series[$id] = array();

} 

 

It's a string because you imploded it before your sql.

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.