Jump to content

PHP list error


M0n5terBunny

Recommended Posts

Hello all for some reason when i do this code it puts and extra 2 list items at the bottom i have tried putting echo = "<ul>"; at the start and </ul> but it just comes back with a server error, is there any way to fix this? also can your shorten this as in ask it to repeat the same query for each time?

.



<?php

include('include/connection.inc');



$c	= "<li>unavailable - ";
$o	= "<li>available - ";

$date = date("Y/m/d");




///////



$v1 = mysql_query("SELECT * FROM client WHERE date = '$date' AND time = 900");

if (mysql_num_rows($v1) == 1) { echo "0900",$c; } else { echo "0900",$o; } 

$v2 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 930");

if (mysql_num_rows($v2) == 1) { echo "0930",$c; } else { echo "0930",$o; }

$v3 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1000");

if (mysql_num_rows($v3) == 1) { echo "1000",$c; } else { echo "1000",$o; }

$v4 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1030");

if (mysql_num_rows($v4) == 1) { echo "1030",$c; } else { echo "1030",$o; }

$v5 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1100");

if (mysql_num_rows($v5) == 1) { echo "1100",$c; } else { echo "1100",$o; }

$v6 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1130");

if (mysql_num_rows($v6) == 1) { echo "1130",$c; } else { echo "1130",$o; }

$v7 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1200");

if (mysql_num_rows($v7) == 1) { echo "1200",$c; } else { echo "1200",$o; }

$v8 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1230");

if (mysql_num_rows($v8) == 1) { echo "1230",$c; } else { echo "1230",$o; }

$v9 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1300");

if (mysql_num_rows($v9) == 1) { echo "1230",$c; } else { echo "1300",$o; }

$v10 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1330");

if (mysql_num_rows($v10) == 1) { echo "1330",$c; } else { echo "1330",$o; }

$v11 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1400");

if (mysql_num_rows($v11) == 1) { echo "1400",$c; } else { echo "1400",$o; }

$v12 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1430");

if (mysql_num_rows($v12) == 1) { echo "1430",$c; } else { echo "1430",$o; }

$v13 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1500");

if (mysql_num_rows($v13) == 1) { echo "1500",$c; } else { echo "1500",$o; }

$v14 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1530");

if (mysql_num_rows($v14) == 1) { echo "1530",$c; } else { echo "1530",$o; }

$v15 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1600");

if (mysql_num_rows($v15) == 1) { echo "1600",$c; } else { echo "1600",$o; }

$v16 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1630");

if (mysql_num_rows($v16) == 1) { echo "1630",$c; } else { echo "1630",$o; }

$v17 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1700");

if (mysql_num_rows($v17) == 1) { echo "1700",$c; } else { echo "1700",$o; }

$v18 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1730");

if (mysql_num_rows($v18) == 1) { echo "1730",$c; } else { echo "1730",$o; }

$v19 = mysql_query("SELECT * FROM client WHERE date = '$date' AND  time = 1800");

if (mysql_num_rows($v19) == 1) { echo "1800",$c; } else { echo "1800",$o; }

///////

?>

Link to comment
Share on other sites

In general, you should try to execute one query that gets all the relevant data at once -

 

SELECT * FROM client WHERE date = '$date'

 

I would then preprocess that data into a php array where the time becomes each array index/key (assuming that the other data in each row might eventually get displayed as well.) You can then simply test if a time slot contains data by testing if the time index/key isset in the array as you iterate over all the possible time slots and produce your desired output.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.