php - Creating foreach loops using Code Igniter controller and view -


This is a situation I have found myself in some time and I want to clear it once and for all I am

My Controller

  function my_controller () {$ Id = $ this- & gt; Yuri- & gt; Segment (3); $ This- & gt; Db- & gt; ('Cue_sheets'); $ This- & gt; Db- & gt; Where ('id', $ id); $ Data ['get_cue_sheets'] = $ this- & gt; Db- & gt; Find (); $ This- & gt; Db- & gt; From ('clip'); $ This- & gt; Db- & gt; Where ('sheet_id', 'qi sheet id goes here' ???); $ Data ['get_clips'] = $ this- & gt; DB- & gt; Find (); $ This- & gt; Load-> View ('show_sheets_and_clips', $ data); }  

My view

  & lt ;? Php if ($ get_cue_sheets-> result_are ()) {? & Gt; & Lt ;? Php foreach ($ get_cue_sheets-> as result_are ($ sheetRow)):? & Gt; & Lt; H1 & gt; & Lt ;? Php echo $ sheet row ['sheet_name']; ? & Gt; & Lt; / H1> & Lt; Br / & gt; & Lt ;? Php if ($ get_clips-> result_are ()) {? & Gt; & Lt; Ul & gt; & Lt ;? Php foreach ($ get_clips-> as result_are ($ clipRow)):? & Gt; & Lt; Li & gt; & Lt ;? Php echo $ Clipper ['clip_name']; ? & Gt; & Lt; / Li & gt; & Lt ;? Php endforeach; ? & Gt; & Lt; / Ul & gt; & Lt ;? Php} else {echo 'no clips found'; }? & Gt; & Lt ;? Php endforeach; ? & Gt; & Lt ;? Php}? & Gt;  

So basically I'm trying to display several sheets and then within each sheet of the clip related to that sheet

I hope it

Tim

code A user on the Igniter forum came up with a solution below. The original thread is.

It is not efficient to view different clips of each letter, use a JOIN query to get both lists at the same time. Data from $

  // ($ 'cue_sheets') $ - this-> Db- & gt; get receive; $ This- & gt; Db- & gt; Where ('cue_sheets.id', $ id); $ This- & gt; Db- & gt; Join ('clip', 'clip.sheet_id = cue_sheets.id', 'left'); $ Rawdata = $ it- & gt; DB- & gt; Find () - & gt; Result_are (); // Generate data in a multidimensional array $ data = array; Foreign currency ($ raw data as line $) {// If this is the first clip of new sheet, create a new entry for it (! Assets ($ data [$ row ['id']]) {$ Data [$ line ['id']] = $ line; $ Data [$ row ['id']] ['clip'] = array (); } // Add existing clip sheet $ data [$ row ['id']] ['clip'] [] = $ line; }  

Now you can loop through chats in your view, and in it, loops through the clip:

  foreach ($ $ $) Data as sheet) {// versus header etc. (Size ($ letter ['clip'])) {foreach ($ sheet ['clip'] as $ clip) {// show clip}} and {// show 'any clip'}}  

Thanks again,

Tim


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -