SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Looping Twice

  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looping Twice

    Hi guys


    I am using the smarty template engine and have the following problem

    It should display like this


    0800 C Campbell
    0900 No Booking
    1000 J Davies
    1100 No Booking
    1200 No Booking
    but at the moment it displays duplicates for each booking

    0800 C Campbell
    0800 No Booking
    0900 No Booking
    0900 No Booking
    1000 No Booking
    1000 J Davies
    1100 No Booking
    1100 No Booking
    1200 No Booking
    1200 No Booking







    myaccount.php

    PHP Code:
    $checkrelated6 mysql_query("SELECT * FROM dates WHERE Start='$dbdate 00:00:00' and Type='Times'"); 

    $checkdatetimes mysql_num_rows($checkrelated6);

    while(
    $row mysql_fetch_assoc($checkrelated6))

    {

    $start_time=$row["Start_Time"];

    $end_time=$row["End_Time"];

    }

    $StartTime StrToTime($start_time);

    $EndTime StrToTime($end_time);

    for(
    $i $StartTime$i <= $EndTime$i += 60 60,$i++){ #########################

    $temp_array[] = $i;

    $sql "SELECT * FROM bookings ";

    $result mysql_query($sql) OR die(mysql_error());

    while(
    $row mysql_fetch_assoc($result))

    {

    $bookingdates[] = $row# $data is the array created for use in the Smarty template.

    }









    template.tpl
    PHP Code:
    <table class="dailycal">

    {foreach 
    from=$array item=foo}

    {foreach 
    from=$bookingdates item=dates key=key}

    {if 
    $dates.Date_Of_Actual_Booking|date_format:'%Y-%m-%d %H:%M:%S'==$foo|date_format:'%Y-%m-%d %H:%M:%S'}

    <
    tr class="even new-app">

    <
    th scope="row">{$foo|date_format:"%H:%M"}</th>

    <
    td><a href=setup.php>C Campbell</a></td>

    </
    tr>

    {else}

    <
    tr>
    <
    th scope="row">{$foo|date_format:"%H:%M"}</th>

    <
    td><a href=setup.php>No Booking </a></td>

    </
    tr>

    {/if}

    {/foreach}

    {/foreach}

    </
    table

    Thanks in advance

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    South Florida
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont know anything about smarty template, but i am curious why you use two foreach loops in your template?


Bookmarks

Posting Permissions

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