Jump to content

echoing strings + object calls


lewashby
Go to solution Solved by mac_gyver,

Recommended Posts

<?php


require_once('init.php');


function print_rows($inmates)
{
    foreach($inmates as $inmate)
    {
        echo "<tr>";
        echo "<td><span class='rightpadding'>$inmate->get_property('first_name');</span>$inmate->get_property('number');<span class='rightpadding'>(W)</span>Facility<br /><br /><span class='dates'>8-05-15 <span class='red'>/</span> 8-08-15</span><a href=''><span class='edit'>Edit</span></a></td>";
        echo "</tr>";
    }
}


?>

In the code above my inmate object method calls are being displayed a literal strings in the output. How can I get these to expand in this string? I also tried concatenation with the . operator but the page wouldn't load at all using that method.

 
Link to comment
Share on other sites

  • Solution

your concatenation probably didn't work due to the semi-colons ;. those only go on the end of php statements. when not within a quoted string, the first semi-colon that was encountered was telling php that was the end of the statement. everything following that probably didn't make any sense to php and it was throwing a syntax error.

 

to put the object method calls in the string, you would need to put { } around each object method call so that php can figure out what part is the reference to the object. you would also remove the semi-colons, unless you literally want the ; character to be in the output.

Edited by mac_gyver
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.