-1

i'm not very good in PHP but i'm learning as we go, i have a question for you as this is most likely very easy to do but i can't get my head around this and spent now many hours trying to solve this.

I'm working in a booking system, and the foreach loop showing a list of bookings and the booking details is on the same page, however the total price is just in the view of the booking list and not on the booking details. I'm trying to get the value of the total booking in a single line...

Like now it's

<?php if (isset($booking) && !empty($booking)) { ?>
<?php foreach ($booking as $key => $val) { ?>
    ...
    <?= number_format($val->total_rental, 2, '.', ',') ?>
    ...
<?php } ?>
<?php } ?>

On the booking list, and i am trying to add this on the booking details page with single line something like.

<?= number_format($booking->total_rental, 2, '.', ',') ?>

But it never gives any value, do you have an idea of what i am doing wrong or am i missing something that i should search for in the code ?.

All php code that show any details on the booking details page are echo'd out like this.

<?= $detail['info']->id_booking ?>

So i even tried something like this.

<?= number_format($detail['info']->total_rental, 2, '.', ',') ?>

But still nothing.. etc.

Any help is greatly appreciated, i might be on the wrong path here...

Jack Johnson
  • 593
  • 4
  • 11
  • 23
  • Is the object `$booking` available in the detail page? – RiggsFolly Oct 18 '16 at 12:23
  • Are you looking at the php error logs for some clues? – RiggsFolly Oct 18 '16 at 12:23
  • 1
    Please see http://stackoverflow.com/q/4559925/476 – deceze Oct 18 '16 at 12:24
  • I guess so, as the booking foreach and the booking details is actually in the same php view file carrental-booking.php – Jack Johnson Oct 18 '16 at 12:24
  • @deceze that is not what i'm looking for, the value exists and is showing the total booking price on the foreach and i'm trying to get that value on the booking details page. But then again it's actually the same php file, that's why i don't get this isn't working... – Jack Johnson Oct 18 '16 at 12:25
  • 1
    I'm pointing out to you that `isset && !empty` is redundant nonsense. Don't get used to it. Use simply only `!empty`. Yes, that's not your primary question, it's a bonus. – deceze Oct 18 '16 at 12:26
  • 1
    As you show us **so little** of what is actually going on in your code, this has been reduced to a **guessing game**, so I am off to pastures new – RiggsFolly Oct 18 '16 at 12:27

1 Answers1

-2
<?php if (isset($booking) && !empty($booking)) { ?>
    ...
    <?php echo number_format($val->total_rental, 2, '.', ',') ?>
    ...
<?php } ?>

have you tried it like this allready?

Johannes
  • 105
  • 1
  • 15