Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    while-loop in email

    I'm having some difficulty getting a looped array in a table into the message of a HTML email.
    I think I may be approaching it incorrectly. Could someone tell me if this is the correct methodology?

    Code:
    $message="
    $inv_fetch = mysql_query("SELECT * FROM table ") or die('Error SQL !'.mysql_error());
    	<table width='800'>
    						
    						
    		<tr>					
                    <th colspan='7'><div align='left'>Purchase Order Details: </div></th>
    							</tr>
    							<tr>
    							<td width='61'>Code</td>
    							<td width='220'>Product</td>
    							</tr>
    						
    						while($row3 = mysql_fetch_array($inv_fetch_new))
    					{
    								<tr>
    								<td>$row3["code"]</td>
    								<td>$row3["prod"]</td>
    
    								</tr>
    					}
    							
    						</table>
    "
    
    Normally this should work, but the fact that it's between two double-quotes makes it not work.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    $inv_fetch = mysql_query("SELECT * FROM table ") or die('Error SQL !'.mysql_error());
    
    $message="<table width='800'>						
    		<tr>					
                    <th colspan='7'><div align='left'>Purchase Order Details:</div></th>
    		</tr>
    		<tr>
    		<td width='61'>Code</td>
    		<td width='220'>Product</td>
    		</tr>";
    						
    		while($row3 = mysql_fetch_array($inv_fetch_new))
    		{
    			$message .= "<tr>
    			<td>$row3["code"]</td>
    			<td>$row3["prod"]</td>
    			</tr>";
    		}
    $message .= "</table>";
    Should be something like. (I'm crap at code editing in these textarea's).

  • #3
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    PHP Code:
    <?php
    $sql
    'SELECT field1, field2, field3 FROM table';
    $resultmysql_query($sql);

    $message='<table>';
    $message.= '<tr colspan="3"><th>heading</th></tr>'

    while($rowmysql_fetch_assoc($result) ) {
      
    $message.= '<tr>';
      
    $message.= "<td>{$row['field1']}</td>";
      
    $message.= "<td>{$row['field2']}</td>";
      
    $message.= "<td>{$row['field3']}</td>";
      
    $message.= '</tr>';
    }
    $message.= '</table>';
    ?>
    Note I'm using the concatenation operator '.' to add to the table markup as I go. You could certainly use the HEREDOC syntax if you wanted with some portion of the output, but you do have to escape the string at some point to run programatically through the data.
    Last edited by bdl; 02-09-2010 at 03:32 AM. Reason: D'oh! Don't mind me. Brain dead today.

  • #4
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you guys rock!

    Your code snippets make much more sense! I had a feeling that I was going about it the wrong way

    thankyou!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •