Jump to content

PHP Loops don't display any data


ipPHPadmin

Recommended Posts

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

}

} ?>

Link to comment
https://forums.phpfreaks.com/topic/220305-php-loops-dont-display-any-data/
Share on other sites

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.

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

  }

} ?>

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");

<?

 

++++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

}

} ?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.