cmattoon Posted May 23, 2010 Share Posted May 23, 2010 Is there a way to force an SQL query to display blanks for values that dont' exist? Once you select a date, it shows all scheduled events for that date, in half hour blocks. There are two half-hour blocks per time (see below). If something is scheduled, the time shows up as plain text, along with some information about the event. If there is nothing scheduled at that time, it shows no information (obviously), and displays the time as a link. When the user clicks the link, it takes them to a page to register an event (keeps people from over-booking). the times are displayed from $start to $end, as chosen on the first page. When I do a simple "generate times" php function, that prints two of each block on the screen from $start to $end, it works fine. When I use a standard SELECT * FROM where date='$date', it only displays the scheduled events. 07:00 07:00 07:30 07:30 08:00 08:00 08:30 08:30 etc... Maybe generate times, then fill the other table cells depending on query using a foreach? Quote Link to comment https://forums.phpfreaks.com/topic/202679-display-blank-values-duplicates-even-if-no-record-exists/ Share on other sites More sharing options...
jskywalker Posted May 24, 2010 Share Posted May 24, 2010 you could create a table (i.e. TIMES) which gives above output and than do a: SELECT t.TIMES, .... FROM TIMES t LEFT JOIN ......(rest of the query) Quote Link to comment https://forums.phpfreaks.com/topic/202679-display-blank-values-duplicates-even-if-no-record-exists/#findComment-1062620 Share on other sites More sharing options...
cmattoon Posted May 24, 2010 Author Share Posted May 24, 2010 Still showing existing trips only? $sql2 = mysql_query("SELECT * FROM wcvschedule WHERE trip_date='$human_date' LEFT JOIN times ON wcvschedule.trip_time=times.txtime ORDER BY times.txtime"); $sql3 = mysql_query("SELECT * FROM wcvschedule, times WHERE times.txtime=wcvschedule.trip_time ORDER BY times.txtime"); //sql3 works, only shows trips that are entered..no blanks $sql4 = mysql_query("SELECT times.*, wcvschedule.* FROM wcvschedule LEFT JOIN times ON wcvschedule.trip_time=times.txtime WHERE wcvschedule.trip_date='$human_date' ORDER BY times.txtime"); $sql5 = mysql_query("SELECT * FROM wcvschedule LEFT JOIN times ON times.txtime=wcvschedule.trip_time WHERE wcvschedule.trip_date='$human_date' ORDER BY times.txtime"); while($row = mysql_fetch_assoc($sql5)){ if($row[khfd] == ""){ $khfd = ""; $trip_time = "<a href=\"../wcv/tx2.php?t=$row[trip_time]&d=$human_date\">$row[trip_time]</a>"; $ptid = NULL; }else{ $khfd = $row[khfd]; $trip_time = $row[trip_time]; $ptid = $row[pt_id]; } echo "<tr><td>$khfd</td><td>$trip_time</td><td>$row[ref_fac]</td><td>$row[rec_fac]</td><td>$row[pt_id]</td><td>$row[driver]</td><td>$row[status]</td></tr>"; } Quote Link to comment https://forums.phpfreaks.com/topic/202679-display-blank-values-duplicates-even-if-no-record-exists/#findComment-1062728 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.