Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP table creation with 1 array manipulating through array indexes
    primarykey
    data
    text
    <p>I have this database:</p> <pre> +----+------------+------------+-----------+----------+---------+------+-----------------+----------+------------+ | id | reservedby | date | timestart | duration | endtime | cost | details | status | dateadded | +----+------------+------------+-----------+----------+---------+------+-----------------+----------+------------+ | 1 | enerva | 09/29/2013 | 9-10am | 3 | 11-12pm | 1500 | basketball dre! | pending | 0000-00-00 | | 2 | mangkanor | 09/30/2013 | 9-10am | 8 | 5-6pm | 4000 | Sabong Dre! | approved | 0000-00-00 | +----+------------+------------+-----------+----------+---------+------+-----------------+----------+------------+ </pre> <p>I'm using it in my table:</p> <p><img src="https://i.imgur.com/4pTuVVL.jpg" alt=""></p> <p>As you can see, the 9-10am slot is reserved by enerva; the duration for that hour is 3, meaning '3 hours', so the endtime will be 11-12pm. However, in my table, I can't incorporate the <code>'Not Available, taken by: enerva'</code> string on 10-11am and 11-12pm.</p> <p>Here's my code:</p> <pre><code>&lt;?php if (isset($_GET['checkdate'])) { $date = urldecode($_GET['date']); echo "&lt;br/&gt;&lt;br/&gt;&lt;h3&gt;Reservations&lt;/h3&gt;"; echo $date; $timearray = array("8-9am","9-10am","10-11am","11-12pm","12-1pm","1-2pm","2-3pm","3-4pm","4-5pm","5-6pm","6-7pm","7-8pm","8-9pm","9-10pm","10-11pm"); $tablecolor = 1; echo "&lt;table style='width: 90%;'&gt;"; echo "&lt;tr&gt;"; echo "&lt;th&gt;"; echo "Time"; echo "&lt;/th&gt;"; echo "&lt;th&gt;"; echo "Status"; echo "&lt;/th&gt;"; echo "&lt;/tr&gt;"; foreach ($timearray as $timearrays) { if($tablecolor %2 == 0) { echo "&lt;tr&gt;"; } else { echo "&lt;tr style='background-color: rgb(0,100,255); background: rgb(0,100,255);'&gt;"; } echo "&lt;th&gt;"; echo "&lt;h3&gt;$timearrays&lt;/h3&gt;"; echo "&lt;/th&gt;"; echo "&lt;td&gt;"; $sql = "SELECT * FROM reservation WHERE date = '$date' AND timestart = '$timearrays'"; $result = mysql_query($sql); if(mysql_num_rows($result) == 0){ echo "&lt;a href='#'&gt;&lt;h3 style='color: rgb(255,0,0);'&gt;Reserve&lt;/h3&gt;&lt;/a&gt;"; } else { while($row = mysql_fetch_array($result)) { $reservedby = $row['reservedby']; } echo "&lt;h3&gt;Not Available, taken by: $reservedby.&lt;/h3&gt;"; } echo "&lt;/td&gt;"; echo "&lt;/tr&gt;"; $tablecolor++; } echo "&lt;/table&gt;"; } ?&gt; </code></pre> <p>I'm guessing that I must use a counter for the duration and decrement it toward zero on each iteration of the loop. Whilst the counter is non-zero, the table will display the <code>'not available, reserved by: enerva'</code> string; once it reaches zero, it will display the <code>'reserve'</code> link. But I couldn't find a way to do it.</p> <p>Is there any way, or any other way to do it? Shall I look to the <code>indexof</code> arrays and find the difference between the 2 indexes of starttime and endtime?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload