-2

I would not like to echo this code because I need to match the other syntax in my .php. How would I get this to work. I've looked everywhere and can't find a solution.

<? if (mysqli_num_rows($result) > 0): ?>
    // output data of each row
  
<? while($row = mysqli_fetch_assoc($result)): ?>
  <center><b><p>Order ID: " . $row['ID'] . "</p></b></center><br>
  <center><b><p>Order Total: " . $row['total'] . "</p></b></center><br>
  <center><b><p>Order Status: " . $row['status'] . "</p></b></center><br>
  <center><b><p>Payment Status: " . $row['payment'] . "</p></b></center><br>
<? endwhile ?>
 mysqli_close($conn);
<?php endif; ?>

What is the problem with this code?

  • So I've tried fixing it as you say, and it seems for some reason nothing is displaying when I run the code. :S – Kris Fallat Nov 10 '17 at 03:37
  • Update your question to display your latest coding attempt and turn on your errors and tells us what the error(s) are. `mysqli_close($conn)` and those echo'ed `$row`s need to be inside of php as well. You ALSO don't need the if statement, the while statement will handle this case. – mickmackusa Nov 10 '17 at 03:44
  • 1
    You forgot ` – pirs Nov 10 '17 at 03:46
  • See https://stackoverflow.com/questions/200640/are-php-short-tags-acceptable-to-use and https://stackoverflow.com/questions/2185320/how-to-enable-php-short-tags – Scuzzy Nov 10 '17 at 03:48
  • Do you know that the query is error-free and that resultset actually holds some rows of data? Is there an `else`? Are you attempting to debug this with error checking? Your question is at risk of being closed as "Off-topic: Why isn't this code working?" Please update your question with the necessary information. – mickmackusa Nov 10 '17 at 03:52
  • How do you know your code does not work? What is not working? Are you getting any errors? Have you tried running from the command line using `php myfile.php` to see if any errors are generated? Have you looked in the php logs to see what errors show up there? – kojow7 Nov 10 '17 at 07:25

4 Answers4

2

this might be a short open tag issue. Either change <? to <?php or configure php to allow short open tags

rai
  • 449
  • 3
  • 10
0

Would that work?

<center><b><p>Order ID: <?= $row['ID'] ?></p></b></center><br>
Simon Bolduc
  • 175
  • 10
0

Try this let me know...

I thought you missed the following:

<? ... ?> into <?php ... ?>

endwhile missing semicolon(;)

mysqli_close without php tag

<?php if (mysqli_num_rows($result) > 0): ?>    

<?php while($row = mysqli_fetch_assoc($result)): ?>
        <center><b><p>Order ID: <?php echo $row['ID']; ?>   </p></b></center><br>
        <center><b><p>Order Total: <?php echo $row['total']; ?> </p></b></center><br>
        <center><b><p>Order Status: <?php echo $row['status']; ?>   </p></b></center><br>
        <center><b><p>Payment Status: <?php echo $row['payment']; ?>    </p></b></center><br>
<?php endwhile; ?>
<?php mysqli_close($conn); ?>
<?php endif; ?>
Maths RkBala
  • 2,207
  • 3
  • 18
  • 21
-1
<?php if(mysqli_num_rows($result)!= 0): ?>
    <?php while($row = mysqli_fetch_assoc($result)): ?>
        <center><b><p>Order ID: <?php echo $row['ID'] ?></p></b></center><br>
        <center><b><p>Order Total: <?php echo $row['total'] ?></p></b></center><br>
<? endwhile;
 mysqli_close($conn);
 endif; ?>
Ken Y-N
  • 14,644
  • 21
  • 71
  • 114