Page 1 of 1

printing multi-d arrays in a formatted string

Posted: Sat Apr 01, 2006 11:20 pm
by bimo
I have a page that displays the results from a query. I send the parameter(s) to a class method and it returns the result set as an array.

Code: Select all

$vid_info = $video->vid_info($video_id, $crisis_id);
then I send this array to a template page

Code: Select all

if(is_array($vid_info))
		{
			foreach($vid_info as $datum)
			{
				$datum = html_ent($datum);
				vprintf($item, $datum);
			}
		}
the template page (blah.inc) looks like this

Code: Select all

...<br/>
<span class="input">						
     <label for="cur_city">current city:</label> <input type="text" name="cur_city" value="%11$s, %13$s" />
</span>
<br/>
<span class="input">
     <label for="cur_loc">current location:</label> <input type="text" name="relief_center" value="%21$s" /> 
</span>
<br/>
<span class="input">
     <label for="number">phone contact:</label> <input type="text" name="number" value="%23$s" />
</span>...
Now there are a couple more categories of items that I want to get from the db. I could just run another query and array_push them onto the same array but I don''t know how I would be able to tell where these categories started and where they ended... unless each set were an array, I thought.

The problem with this is I don't think that vprintf will let me pas a multi-dimensional array. At least, it hasn't seemed like it will. I may have been doing somethiing wrong...

Does anyone have any ideas for how I could do this (pass a multi-d array to a formatted string and then cycle through it in that part of the template)?