bcart Posted November 6, 2009 Share Posted November 6, 2009 I am fairly new to PHP and MySQL and I have a problem which I have been trying to resolve for days. I just can't figure it out and can't find anything on the web that is helping me work it out. I hope someone out there can assist. Ultimately I want to display the data as follows (this is just an example of how I want it displayed, it does not mirror the data set below)... <h2><a href="procedure.php?number=f1>Finance Procedure 1 - F1</a></h2> <ul> <li><a href="form/f1_fm1.pdf" target="blank">Finance Form 1</a></li> <li><a href="form/f1_fm2.pdf" target="blank">Finance Form 2</a></li> <li><a href="form/f1_fm3.pdf" target="blank">Finance Form 3</a></li> </ul> <h2><a href="procedure.php?number=f2>Finance Procedure 2 - F2</a></h2> <ul> <li><a href="form/f2_fm1.pdf" target="blank">Finance Form 1</a></li> <li><a href="form/f2_fm2.pdf" target="blank">Finance Form 2</a></li> <li><a href="form/f2_fm3.pdf" target="blank">Finance Form 3</a></li> </ul> <h2><a href="procedure.php?number=f3>Finance Procedure 3 - F3</a></h2> <ul> <li><a href="form/f3_fm1.pdf" target="blank">Finance Form 1</a></li> <li><a href="form/f3_fm2.pdf" target="blank">Finance Form 2</a></li> <li><a href="form/f3_fm2.pdf" target="blank">Finance Form 3</a></li> </ul> I have 2 tables (procedure_name and procedure_form). and run the following query which gives me the required data set. $sql = "SELECT procedure_info.id, procedure_info.name, procedure_info.number, procedure_form.form, procedure_form.form_file FROM procedure_info LEFT JOIN procedure_form ON ( procedure_info.id = procedure_form.name_id ) WHERE procedure_info.procedure_area = '14' ORDER BY procedure_info.procedure_area ASC"; My problem is that I don't know how to output the result set I achieve into the exampled display. my data set looks like this. id ---name ------------------------------number --form ---------------------form_file 33 ---Referral ---------------------------E2E1 ----NULL ----------------------NULL 34 ---Employer led E2E referral -----------E2E1a ---NULL ----------------------NULL 35 ---Centre Start & Induction -----------E2E2 ----NULL ----------------------NULL 39 ---Programme activity plan & review ---E2E4 ----NULL ----------------------NULL 38 ---Inital Assessment ------------------E2E3 ----Additional Information ------e2e2_fm4.pdf 38 ---Inital Assessment ------------------E2E3 ----E2E Weekly Batch Header ---mi1_fm2.pdf 40 ---Placement -------------------------E2E5 ----NULL ----------------------NULL 41 ---E2E Health & Safety review ---------E2E5a ---NULL ----------------------NULL 42 ---E2E Health & Safety Monitoring -----E2E5b ---NULL ----------------------NULL 43 ---E2E Basic skills ---------------------E2E6 ----NULL ------------------------NULL 44 ---Leavers ----------------------------E2E7 ----NULL ----------------------NULL I think I have to put this data into a multidimensional array but I just can not work it out. Can anyone help me? PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!! Link to comment https://forums.phpfreaks.com/topic/180552-displaying-multidimensional-arraysabout-to-put-my-head-in-a-vice-please-help/ Share on other sites More sharing options...
rajivgonsalves Posted November 6, 2009 Share Posted November 6, 2009 if you post some of your code and where you think its going wrong we might be able to help you Link to comment https://forums.phpfreaks.com/topic/180552-displaying-multidimensional-arraysabout-to-put-my-head-in-a-vice-please-help/#findComment-952549 Share on other sites More sharing options...
bcart Posted November 6, 2009 Author Share Posted November 6, 2009 if you post some of your code and where you think its going wrong we might be able to help you The code below displays the procedure_name and the form_name(s) associated with each procedure but I also need the 'number' and 'form_file' fields in order to make the links. Have I explained this enough? The code I have so far is... $procedures = array(); while($row_select = mysqli_fetch_array($result_select)) { $procedures[$row_select['name']][] = $row_select['form']; } foreach($procedures as $key => $value) { print "<h3><a href=\"form/\">".$key."</a></h3>"; print "<p><a href=\"form/\">".implode(", ",$value)."</a></p>"; } Thanks Link to comment https://forums.phpfreaks.com/topic/180552-displaying-multidimensional-arraysabout-to-put-my-head-in-a-vice-please-help/#findComment-952555 Share on other sites More sharing options...
rajivgonsalves Posted November 6, 2009 Share Posted November 6, 2009 try this $procedures = array(); while($row_select = mysqli_fetch_array($result_select)) { $procedures[$row_select['name']]['number'] = $row_select['number']; $procedures[$row_select['name']]['forms'][] = array('name' => $row_select['form'], 'file' => $row_selected['file']); } foreach($procedures as $key => $value) { print "<h3><a href=\"procedure.php?number={$value['number']}/\">".$key."</a></h3>"; foreach ($value['form'] as $form){ print "<p><a href=\"form/{$form['file']}\">".$form['name']."</a></p>"; } } Link to comment https://forums.phpfreaks.com/topic/180552-displaying-multidimensional-arraysabout-to-put-my-head-in-a-vice-please-help/#findComment-952565 Share on other sites More sharing options...
bcart Posted November 9, 2009 Author Share Posted November 9, 2009 try this $procedures = array(); while($row_select = mysqli_fetch_array($result_select)) { $procedures[$row_select['name']]['number'] = $row_select['number']; $procedures[$row_select['name']]['forms'][] = array('name' => $row_select['form'], 'file' => $row_selected['file']); } foreach($procedures as $key => $value) { print "<h3><a href=\"procedure.php?number={$value['number']}/\">".$key."</a></h3>"; foreach ($value['form'] as $form){ print "<p><a href=\"form/{$form['file']}\">".$form['name']."</a></p>"; } } Thanks for this but I'm getting an error "Invalid argument supplied for foreach()" referring to the line below... foreach ($value['form'] as $form){ Can you help? Cheers Link to comment https://forums.phpfreaks.com/topic/180552-displaying-multidimensional-arraysabout-to-put-my-head-in-a-vice-please-help/#findComment-954058 Share on other sites More sharing options...
bcart Posted November 9, 2009 Author Share Posted November 9, 2009 try this $procedures = array(); while($row_select = mysqli_fetch_array($result_select)) { $procedures[$row_select['name']]['number'] = $row_select['number']; $procedures[$row_select['name']]['forms'][] = array('name' => $row_select['form'], 'file' => $row_selected['file']); } foreach($procedures as $key => $value) { print "<h3><a href=\"procedure.php?number={$value['number']}/\">".$key."</a></h3>"; foreach ($value['form'] as $form){ print "<p><a href=\"form/{$form['file']}\">".$form['name']."</a></p>"; } } Thanks for this but I'm getting an error "Invalid argument supplied for foreach()" referring to the line below... foreach ($value['form'] as $form){ Can you help? Cheers Actually forget that it was because it should have been $forms not $form. However I have noticed that it is not picking up the form_file data from the line below print "<p><a href=\"form/{$form['file']}\">".$form['name']."</a></p>"; Any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/180552-displaying-multidimensional-arraysabout-to-put-my-head-in-a-vice-please-help/#findComment-954068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.