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

Link to comment
Share on other sites

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

  }

} ?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?

 

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

}

} ?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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