[FX.php List] Embed php into HTML or vice versa?

Steve Hannah shannah at sfu.ca
Thu Aug 31 19:22:50 MDT 2006


I would do:

	<?php foreach($searchResult['data'] as $key => $value)
    		{//start for each
                 $recordDetails=explode('.',$key);
		$currentRecord=$recordDetails[0];
    		echo "<tr class=\"ver12\">
                                 <td>
                                       <ahref=\"famdetail.php?recid= 
{$currentRecord}\">{$value['FamilyName'][0]}</a>
  				</td>
  				<td>{$value['StuList'][0]}</td>
    				<td>{$value['Address1'][0]}</td>
      				<td>{$value['City'][0]}</td>
     				<td>{$value['State'][0]}</td>
	 			<td>{$value['Zip'][0]}</td>
				<td align=\"right\">
					<a href=\"editfamorder.php?recid={$currentRecord}\">
						\$".number_format($value['AmtTotal'][0],'2',".","")."
  					</a>
				</td>
  				<td align=\"right\">
					<a href=\"lunchdetail.php?recid={$currentRecord}\">
						\$".number_format($value['LunchTotalPrice'][0],'2',".","")."
  					</a>
				</td>
				<td align=\"center\">{$value['PTAMembership'][0]}</td>
			</tr>";

		 } //end for each

		?>

On 31-Aug-06, at 6:08 PM, Jonathan Schwartz wrote:

> Hmmm... so how would you do that for the foreach statement?...
>
>
> 		<?php foreach($searchResult['data'] as $key => $value)
>    		{
> 		echo "<tr class=\"ver12\"><td><ahref=\"famdetail.php?recid=";
>  	 	$recordDetails=explode('.',$key);
> 		$currentRecord=$recordDetails[0];
> 		echo $currentRecord."\">".$value['FamilyName'][0];
>  		echo "</a></td>";
>  		}
> 		?>
>
> Jonathan
>
>
>
>
>> On 1/9/06 10:06 AM, "Steve Hannah" <shannah at sfu.ca> wrote:
>>
>>>  Hi Jonathan,
>>>
>>>  One tip for making HTML-in-PHP a little easier to work with is:
>>>
>>>  instead of
>>>  echo "<td>".$value['StuList'][0]."</td>";
>>>
>>>  do
>>>
>>>  echo "<td>{$value['StuList'][0]}</td>";
>>>
>>>  That way you don't have to worry about forgetting a pesky
>>>  concatenation operator.
>>>  You can only do this inside double quotes, not single quotes,  
>>> but it
>>>  works for just about any valid PHP expression.
>>>
>>>  Best regards
>>>
>>>  Steve
>>>
>>
>> I'd actually handle it like this:
>>
>> <td><?php echo $value['StuList'][0]; ?><td>
>>
>> This way, the HTML is HTML, the PHP is PHP. No need to  
>> contatenate, or worry
>> about escaping quotes or other characters. This will work inside a  
>> foreach
>> loop as you write out the data too. As I've said in earlier posts,  
>> doing it
>> this way isn't always practical, but it's cleaner and more in the  
>> spirit of
>> separating the two.
>>
>> --
>> Kevin Futter
>> Webmaster, St. Bernard's College
>> http://www.sbc.melb.catholic.edu.au/
>>
>
>
> -- 
>
> Jonathan Schwartz
> FileMaker 8 Certified  Developer
> Associate Member, FileMaker Solutions Alliance
> Schwartz & Company
> jonathan at eschwartz.com
> http://www.eschwartz.com
> http://www.exit445.com
> 415-381-1852
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>



More information about the FX.php_List mailing list