Forums

Why can't I get this data to load

Mr Toast 25 Aug, 2011
Hey can anyone tell my why this code isn't working. The table loads, all the data come from the database in the 'foreach' PHP loop just fine but the 3 pieces of data for 'code' 'summer_program' and 'school_organization' don't load.

I just can't work out why.

Cheers


<table>
	<tr>
		<td>
			<strong>Code:</strong><?php $detail = $form->data['code']; ?><br/>
			<strong>Program:</strong><?php $detail = $form->data['summer_program']; ?> <strong>School: </strong><?php $detail = $form->data['school_organization'];?>
		</td>
	</tr>
</table>
<table width="590px" style="text-align: left;" >
	<tr>
		<th width="20%"><strong>Surname:</strong></th>
		<th width="20%"><strong>First Name:</strong></th>
		<th width="20%"><strong>Passport/ID:</strong></th>
		<th width="20%"><strong>Birthday:</strong></th>
		<th width="20%"><strong>Phone:</strong></th>
	</tr>
<?php
foreach ($form->data['ProgramList'] as $detail):
?>
	<tr>
		<td><?php echo $detail['surname']; ?></td>
		<td><?php echo $detail['given_name']; ?></td>
		<td><?php echo $detail['passport']; ?></td>
		<td><?php echo $detail['phone']; ?></td>
		<td><?php echo $detail['bd_day'] ?> <?php echo $detail['bd_month'] ?> <?php echo $detail['bd_year']; ?></td>
	</tr>
<?php
endforeach;
?>
</table>
Max_admin 26 Aug, 2011
Hi,

Just like your other code snippets, instead of this:

<?php $detail = $form->data['summer_program']; ?>


You should use this:

<?php echo $form->data['summer_program']; ?>


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Mr Toast 26 Aug, 2011
[attachment=0]screen-capture-1.png[/attachment]Hmm ok so I did what you said, my code is now this:


<table>
	<tr>
		<td>
			<strong>Code: </strong><?php echo $form->data['code']; ?><br/>
			<strong>Program: </strong><?php echo $form->data['summer_program']; ?> <strong>School: </strong><?php echo $form->data['school_organization']; ?>
		</td>
	</tr>
</table>
<table width="590px" style="text-align: left;" >
	<tr>
		<th width="20%"><strong>Surname:</strong></th>
		<th width="20%"><strong>First Name:</strong></th>
		<th width="20%"><strong>Passport/ID:</strong></th>
		<th width="20%"><strong>Phone:</strong></th>
		<th width="20%"><strong>Date of Birth:</strong></th>
	</tr>
<?php
foreach ($form->data['ProgramList'] as $detail):
?>
	<tr>
		<td><?php echo $detail['surname']; ?></td>
		<td><?php echo $detail['given_name']; ?></td>
		<td><?php echo $detail['passport']; ?></td>
		<td><?php echo $detail['phone']; ?></td>
		<td><?php echo $detail['bd_day'] ?> <?php echo $detail['bd_month'] ?> <?php echo $detail['bd_year']; ?></td>
	</tr>
<?php
endforeach;
?>
</table>


And the result is this:
[attachment=0]screen-capture-1.png[/attachment]

I can't see why it wouldn't work

Thanks again for everything
Mr Toast 26 Aug, 2011
I've spent endless hours looking and experiencing but still no luck. Any idea? Thanks
Mr Toast 26 Aug, 2011
Ok the only way I can get it to work is like this


<table>
<?php
foreach ($form->data['ProgramList'] as $detail):
?>  
   <tr>
      <td>
		<strong>Code: </strong><?php echo $detail['code']; ?><br/>
		<strong>Program: </strong><?php echo $detail['summer_program']; ?> <strong>School: </strong><?php echo $detail['school_organization']; ?>

      </td>
   </tr>
</table>
<table width="590px" style="text-align: left;" >
   <tr>
      <th width="20%"><strong>Surname:</strong></th>
      <th width="20%"><strong>First Name:</strong></th>
      <th width="20%"><strong>Passport/ID:</strong></th>
      <th width="20%"><strong>Phone:</strong></th>
      <th width="20%"><strong>Date of Birth:</strong></th>
   </tr>
<?php
foreach ($form->data['ProgramList'] as $detail):
?>   
<tr>
      <td><?php echo $detail['surname']; ?></td>
      <td><?php echo $detail['given_name']; ?></td>
      <td><?php echo $detail['passport']; ?></td>
      <td><?php echo $detail['phone']; ?></td>
      <td><?php echo $detail['bd_day'] ?> <?php echo $detail['bd_month'] ?> <?php echo $detail['bd_year']; ?></td>
   </tr>
<?php
endforeach;
?>
<?php
endforeach;
?>
</table>


But that of course generates the table twice

[attachment=0]screen-capture.png[/attachment]

What do I change the outer 'foreach' loop to so that it only does it once... sorry my PHP is rubbish.

Thanks again for looking at this!
Max_admin 26 Aug, 2011
Hi,

Well, maybe I didn't understand your question first, the code depends on how many "Code", "Program" and "School" you want to display, if you have one of those for every record then they should be inside the loop, but if you have them only once then they should be out.

If you have them in each record but they are all the same then you may use the 0 key to get them from the array outside the loop:


echo $form->data['ProgramList'][0]['code'];


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Mr Toast 29 Aug, 2011
That worked! Brilliant thank you, so much.
This topic is locked and no more replies can be posted.