rjt90 Posted June 7, 2013 Share Posted June 7, 2013 $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! Quote Link to comment Share on other sites More sharing options...
Barand Posted June 7, 2013 Share Posted June 7, 2013 Syntax for IN is a comma-separated list eg IN (1,2,3) It looks like your $var_hook is an array, so $id_list = join(',', $var_hook); then use IN ($id_list) Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted June 7, 2013 Share Posted June 7, 2013 or "SELECT * FROM data WHERE data_id IN (".implode(",", $var_hook).") ORDER BY time_id ASC" Syntax for IN is a comma-separated list eg IN (1,2,3) It looks like your $var_hook is an array, so $id_list = join(',', $var_hook); then use IN ($id_list) Quote Link to comment Share on other sites More sharing options...
rjt90 Posted June 8, 2013 Author Share Posted June 8, 2013 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? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 8, 2013 Share Posted June 8, 2013 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. Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted June 9, 2013 Share Posted June 9, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.