M0n5terBunny Posted October 27, 2011 Share Posted October 27, 2011 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; } /////// ?> Quote Link to comment https://forums.phpfreaks.com/topic/249895-php-list-error/ Share on other sites More sharing options...
sunfighter Posted October 27, 2011 Share Posted October 27, 2011 Your echos are wrong. Echo like this if (mysql_num_rows($v1) == 1) { echo $c,"0900"; } else {echo $o,"0900"; } if (mysql_num_rows($v2) == 1) { $c,"0930"; } else { $o,"0930"; } if (mysql_num_rows($v3) == 1) { $c,"1000"; } else { $o,"1000"; } Quote Link to comment https://forums.phpfreaks.com/topic/249895-php-list-error/#findComment-1282759 Share on other sites More sharing options...
sunfighter Posted October 27, 2011 Share Posted October 27, 2011 PS. Your killing your database. You should look up COUNT Run this to see: SELECT time, COUNT(*) FROM client GROUP BY time; Quote Link to comment https://forums.phpfreaks.com/topic/249895-php-list-error/#findComment-1282762 Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2011 Share Posted October 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/249895-php-list-error/#findComment-1282767 Share on other sites More sharing options...
M0n5terBunny Posted October 29, 2011 Author Share Posted October 29, 2011 thank you worked perfectly Quote Link to comment https://forums.phpfreaks.com/topic/249895-php-list-error/#findComment-1283217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.