Nymphetamine Posted August 22, 2008 Share Posted August 22, 2008 Hey guys, I've started making a chart, where along the top there's all the weeks in a year, and down the side there's several properties. These dates and property numbers will be stored in a database when the user clicks a cell according to the right date/property, and types in the name, address, and all the rest. However right now I'm having trouble just getting the chart to display properly... <?php $result = mysql_query("SELECT * FROM ###########"); while($row = mysql_fetch_assoc($result)){ echo "<td>"; if ($row['date'] == '0501' && $row['property'] == '1') { echo "$row[name]"; } else { echo "Empty"; } echo "</td><td>"; if ($row['date'] == '1201' && $row['property'] == '1') { echo "$row[name]"; } else { echo "Empty"; } echo "</td><td>"; if ($row['date'] == '1901' && $row['property'] == '1') { echo "$row[name]"; } else { echo "Empty"; } echo "</td>"; } ?> My aim is for it to display the name value for that row, or else display "Empty" in that cell, depending if the row with both the correct date and property exist in the database. At the moment it displays the names ASWELL as "Empty", and for some strange reason, not in the order in which I typed the code... Any ideas guys? Thanks! Link to comment https://forums.phpfreaks.com/topic/120798-trouble-displaying-a-chart-properly/ Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 i would imagine the reason you're getting the weird order is because of the table, not because of the order in which the code is processed; have you looked at the HTML to check whether it's a markup issue? chances are that you're getting both being echoed because it's passing through the loop enough times that you end up with a successful run and a failed run in every cell - if the spacing isn't right (or you don't have borders), they may look like they're in the cell. would you mind posting the markup that while() loop spits out? Link to comment https://forums.phpfreaks.com/topic/120798-trouble-displaying-a-chart-properly/#findComment-622651 Share on other sites More sharing options...
Nymphetamine Posted August 22, 2008 Author Share Posted August 22, 2008 Hmm I'm sure there's nothing wrong with the HTML... Sorry, I'm not very good with PHP, the while loop? This bit? while($row = mysql_fetch_assoc($result)){ I'm not even too sure what that does! haha Link to comment https://forums.phpfreaks.com/topic/120798-trouble-displaying-a-chart-properly/#findComment-622664 Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 that will go through every row that the SELECT query returns. what does the SELECT query look like? Link to comment https://forums.phpfreaks.com/topic/120798-trouble-displaying-a-chart-properly/#findComment-622682 Share on other sites More sharing options...
mmarif4u Posted August 22, 2008 Share Posted August 22, 2008 Can you show us your code with some html. Link to comment https://forums.phpfreaks.com/topic/120798-trouble-displaying-a-chart-properly/#findComment-622685 Share on other sites More sharing options...
Nymphetamine Posted August 22, 2008 Author Share Posted August 22, 2008 <?php mysql_connect("#########", "############", "########") or die(mysql_error()); mysql_select_db("##########") or die(mysql_error()); ?> <html> <head> <title>############</title> </head> <body> <table width="4000" cellspacing="5" bgcolor="lightgray"> <tr> <td> Jan 05 </td> <td> Jan 12 </td> <td> Jan 19 </td> <td> Jan 26 </td> <td> Feb 02 </td> <td> Feb 09 </td> <td> Feb 16 </td> <td> Feb 23 </td> <td> Mar 01 </td> <td> Mar 08 </td> <td> Mar 15 </td> <td> Mar 22 </td> <td> Mar 29 </td> <td> Apr 05 </td> <td> Apr 12 </td> <td> Apr 19 </td> <td> Apr 26 </td> <td> May 03 </td> <td> May 10 </td> <td> May 17 </td> <td> May 24 </td> <td> May 31 </td> <td> Jun 07 </td> <td> Jun 14 </td> <td> Jun 21 </td> <td> Jun 28 </td> <td> Jul 05 </td> <td> Jul 12 </td> <td> Jul 19 </td> <td> Jul 26 </td> <td> Aug 02 </td> <td> Aug 09 </td> <td> Aug 16 </td> <td> Aug 23 </td> <td> Aug 30 </td> <td> Sep 06 </td> <td> Sep 13 </td> <td> Sep 20 </td> <td> Sep 27 </td> <td> Oct 04 </td> <td> Oct 11 </td> <td> Oct 18 </td> <td> Oct 25 </td> <td> Nov 01 </td> <td> Nov 08 </td> <td> Nov 15 </td> <td> Nov 22 </td> <td> Nov 29 </td> <td> Dec 06 </td> <td> Dec 13 </td> <td> Dec 20 </td> <td> Dec 27 </td> </tr> <tr> <?php $result = mysql_query("SELECT * FROM #########"); while($row = mysql_fetch_assoc($result)){ echo "<td>"; if ($row['date'] == '0501' && $row['property'] == '1') { echo "$row[name]"; } else { echo "Empty"; } echo "</td><td>"; if ($row['date'] == '1201' && $row['property'] == '1') { echo "$row[name]"; } else { echo "Empty"; } echo "</td><td>"; if ($row['date'] == '1901' && $row['property'] == '1') { echo "$row[name]"; } else { echo "Empty"; } echo "</td>"; } ?> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> </body> </html> When it should be displaying the first name in the first cell, it sticks it in the fourth! I just can't work out why... It also diplays 4 "Empty" and the second name.... In my mind the first name should be first, second second, and the third should display "Empty" since that data doesn't exist in the database... and the rest should have nothing in them... Link to comment https://forums.phpfreaks.com/topic/120798-trouble-displaying-a-chart-properly/#findComment-622692 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.