-2

I have a function and I would like to call it in the paragraph tag in the echo block. How would I go about doing this?

<?php
include("includes/functions.inc.php");
include_once("includes/dbh.php");
$strSQL = "SELECT * FROM tickets";
$rs = mysqli_query($conn, $strSQL);
    while($row = mysqli_fetch_array($rs)) {
    echo  '<li>
           <div class="hk_sup_domian_name">
               <p><?php echo checkTicketStatus();?></p>
           </div>
           <div class="hk_domain_price">
               <span class="ex-price">Your box is on its way</span>
               <span class="active_price">'.$row['stage'].'</span>
               <div class="hk_promot_btn"><a class="hk_btn" href="progress.php">View</a></div>
           </div>
           </li>';
    }

    mysqli_close($conn);
?>

I have tried calling it like this and I get the error below.

<p>'checkTicketStatus();'</p> 

syntax error, unexpected '$checkTicketStatus' (T_VARIABLE), expecting ',' or ';'

Trenton Tyler
  • 1,692
  • 3
  • 24
  • 53
  • Is that really the entire line of code which produces the error? That code, by itself, wouldn't even be processed by PHP and would just be treated as HTML. There's additional context you're not providing here. – David Dec 20 '16 at 19:09
  • David, I have added the entire code block in an edit if you would like to check it out. – Trenton Tyler Dec 20 '16 at 19:12

4 Answers4

2
<ul>
    <div class="coral-wrapper left absolute">
          <p><?php insertFunctionHere();?></p>
    </div>
</ul>

Try this one.

if function need to be printed then

<p><?php echo insertFunctionHere();?></p>
Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30
1

Do this:

<ul>
    <div class="coral-wrapper left absolute">
        <p><?php echo checkTicketStatus(); ?></p>
    </div>
</ul>

Update:

Based on your edit, your code should be like this:

<?php
    include("includes/functions.inc.php");
    include_once("includes/dbh.php");
    $strSQL = "SELECT * FROM tickets";
    $rs = mysqli_query($conn, $strSQL);
    while($row = mysqli_fetch_array($rs)) {
        ?>
        <li>
        <div class="hk_sup_domian_name">
            <p><?php echo checkTicketStatus(); ?></p>
        </div>
        <div class="hk_domain_price">
           <span class="ex-price">Your box is on its way</span>
           <span class="active_price"><?php echo $row['stage']; ?></span>
           <div class="hk_promot_btn"><a class="hk_btn" href="progress.php">View</a></div>
        </div>
        </li>
        <?php
    }
    mysqli_close($conn);
?>
Rajdeep Paul
  • 16,887
  • 3
  • 18
  • 37
1

You're essentially trying to do this:

echo '<p><?php echo checkTicketStatus();?></p>';

PHP doesn't work like that. It's simply going to echo that entire literal string to the output, and the browser won't know or care what to do with <?php ?> tags.

You want to concatenate the output of the function with the rest of the string:

echo '<p>' . checkTicketStatus() . '</p>';
David
  • 208,112
  • 36
  • 198
  • 279
0

You can break out of your string and concatenate it in like

<ul>
<?php

echo '<div class="coral-wrapper left absolute"><p>' . checkTicketStatus().'</p></div>';

 ?>
</ul>

or do this

<ul>
<div class="coral-wrapper left absolute">
      <p><?php echo checkTicketStatus();?></p>
  </div>
</ul>
shauns2007
  • 128
  • 9