ipPHPadmin Posted December 1, 2010 Share Posted December 1, 2010 Hello everyone, I'm trying to create a page that takes information from an existing database and displays it in a 'table' on a page. The table thing didn't seem to be working with some other pages I was working on so I split each database table into its own html table and rearrange accordingly. The code below doesn't output any information and I can't figure out why. Thanks in advance. $query = mysql_query("SELECT MAX(ART_ID) AS maxAID FROM Artisan"); while(mysql_fetch_array($query)) { $maxAID = $row["maxAID"]; for($artID = 1; $artID <= $maxAID; $artID++) { $Aquery = mysql_query("SELECT * FROM Artisan WHERE ART_ID = '$artID'"); ?> <table align = "center" width="90%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while(mysql_fetch_array($Aquery)) { $ART_Name = $row["ART_Name"]; ?> <tr> <td><?php echo $ART_Name; ?></td> <td> Filler </td> </tr> <?php }?></table><?php $Qquery = mysql_query("SELECT * FROM ArtisanQuestion ORDER BY ARQ_ID"); ?> <table align = "left" width="35%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while(mysql_fetch_array($Qquery)) { $Ques_ID = $row["ARQ_ID"]; $Ques = $row["ARQ_Question"]; ?> <tr> <td><?php echo "<b>".$Ques_ID."</b>. ".$Ques; ?></td> </tr> <?php }?></table><?php $Aquery = mysql_query("SELECT * ArtisanAnswer WHERE ART_ID = '$artID' ORDER BY ARQ_ID"); ?><table align = "right" width="35%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while(mysql_fetch_array($Aquery)) { $Ans = $row["ARAN_Answer"]; ?> <tr> <td><?php echo $Ans; ?></td> </tr> <?php }?></table><?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/ Share on other sites More sharing options...
QuickOldCar Posted December 1, 2010 Share Posted December 1, 2010 You have a pile of <?php with no closing ?>. If it's all php you just need the start and stop. EDIT: I opened my eyes better and see the closes are all there. Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141623 Share on other sites More sharing options...
ipPHPadmin Posted December 1, 2010 Author Share Posted December 1, 2010 I think all of my php is closed. I have a lot of <?php and ?> because of using html and tables in the middle of the page to display the php in a somewhat formatted manner. I might be misunderstanding what you're saying though. I tried echoing data at the beginning of the code and it stops working once inside the for loop, but works everywhere before it. Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141629 Share on other sites More sharing options...
QuickOldCar Posted December 1, 2010 Share Posted December 1, 2010 My best guess is somewhere along there you have an extra } or missing the } at a certain position. Got errors on and see any messages? It would tell you the line with the issue. Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141630 Share on other sites More sharing options...
QuickOldCar Posted December 1, 2010 Share Posted December 1, 2010 Try this $query = mysql_query("SELECT MAX(ART_ID) AS maxAID FROM Artisan"); while(mysql_fetch_array($query)) { $maxAID = $row["maxAID"]; for($artID = 1; $artID <= $maxAID; $artID++) { $Aquery = mysql_query("SELECT * FROM Artisan WHERE ART_ID = '$artID'"); } ?> <table align = "center" width="90%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while(mysql_fetch_array($Aquery)) { $ART_Name = $row["ART_Name"]; ?> <tr> <td><?php echo $ART_Name; ?></td> <td> Filler </td> </tr> <?php }?></table><?php $Qquery = mysql_query("SELECT * FROM ArtisanQuestion ORDER BY ARQ_ID"); ?> <table align = "left" width="35%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while(mysql_fetch_array($Qquery)) { $Ques_ID = $row["ARQ_ID"]; $Ques = $row["ARQ_Question"]; ?> <tr> <td><?php echo "<b>".$Ques_ID."</b>. ".$Ques; ?></td> </tr> <?php }?></table><?php $Aquery = mysql_query("SELECT * ArtisanAnswer WHERE ART_ID = '$artID' ORDER BY ARQ_ID"); ?><table align = "right" width="35%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while(mysql_fetch_array($Aquery)) { $Ans = $row["ARAN_Answer"]; ?> <tr> <td><?php echo $Ans; ?></td> </tr> <?php }?></table><?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141632 Share on other sites More sharing options...
kenrbnsn Posted December 1, 2010 Share Posted December 1, 2010 Your not getting any rows in the while loops. All of the statements like <?php while(mysql_fetch_array($Qquery)) ?> need to look like <?php while($row = mysql_fetch_array($Qquery)) ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141637 Share on other sites More sharing options...
jcbones Posted December 1, 2010 Share Posted December 1, 2010 This line: $Aquery = mysql_query("SELECT * ArtisanAnswer WHERE ART_ID = '$artID' ORDER BY ARQ_ID"); is invalid MySQL syntax, it should read: $Aquery = mysql_query("SELECT * FROM ArtisanAnswer WHERE ART_ID = '$artID' ORDER BY ARQ_ID"); Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141640 Share on other sites More sharing options...
ipPHPadmin Posted December 1, 2010 Author Share Posted December 1, 2010 Alright, so I tried all of the above suggestions and I'm still not getting anything to display. Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141658 Share on other sites More sharing options...
jcbones Posted December 1, 2010 Share Posted December 1, 2010 So add error commands to all of your queries. msyql_query('whatever the query is') or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141666 Share on other sites More sharing options...
kenrbnsn Posted December 1, 2010 Share Posted December 1, 2010 Please post the code as it stands now between tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141675 Share on other sites More sharing options...
ipPHPadmin Posted December 1, 2010 Author Share Posted December 1, 2010 <? ++++Connecting to the database++++ $query = mysql_query("SELECT MAX(ART_ID) AS maxAID FROM Artisan"); while(mysql_fetch_array($query)) { $maxAID = $row["maxAID"]; for($artID = 1; $artID <= $maxAID; $artID++) { $Aquery = mysql_query("SELECT * FROM Artisan WHERE ART_ID = '$artID'"); ?> <table align = "center" width="90%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while($row = mysql_fetch_array($Aquery)) { $ART_Name = $row["ART_Name"]; ?> <tr> <td><?php echo $ART_Name; ?></td> <td> Filler </td> </tr> <?php }?></table><?php $Qquery = mysql_query("SELECT * FROM ArtisanQuestion ORDER BY ARQ_ID"); ?> <table align = "left" width="35%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while($row = mysql_fetch_array($Qquery)) { $Ques_ID = $row["ARQ_ID"]; $Ques = $row["ARQ_Question"]; ?> <tr> <td><?php echo "<b>".$Ques_ID."</b>. ".$Ques; ?></td> </tr> <?php }?></table><?php $Aquery = mysql_query("SELECT * FROM ArtisanAnswer WHERE ART_ID = '$artID' ORDER BY ARQ_ID"); ?><table align = "right" width="35%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while($row = mysql_fetch_array($Aquery)) { $Ans = $row["ARAN_Answer"]; ?> <tr> <td><?php echo $Ans; ?></td> </tr> <?php }?></table><?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/#findComment-1141690 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.