Jump to content

Another query within a while loop


doddsey_65

Recommended Posts

Okay here is the code. I want to run another SELECT * query within this while loop, which i thought could be done but i cant get it to work.

 

I want the query to select the comments from the comments table in the database that matches the id of the tutorial.

 

                     <?php
                           
                     $i = 0;   
                     
                     $result = mysql_query("SELECT * FROM tutorials ORDER BY added ASC LIMIT 4") or die(mysql_error());
                     while($row = mysql_fetch_object($result)) {
                     
                     if($i==2) {      
                     echo '</tr><tr><td>';      
                     $i=0;  
                     }
                           
                     if ($row->category == 1) {
                     $row->category = 'Animation';
                     }
                     if ($row->category == 2) {
                     $row->category = 'Basics';
                     }
                     if ($row->category == 3) {
                     $row->category = 'Cloth';
                     }
                     if ($row->category == 4) {
                     $row->category = 'Compositing';
                     }
                     if ($row->category == 5) {
                     $row->category = 'Dynamics';
                     }
                     if ($row->category == 6) {
                     $row->category = 'Fluid';
                     }
                     if ($row->category == 7) {
                     $row->category = 'Game Engine';
                     }
                     if ($row->category ==  {
                     $row->category = 'General';
                     }
                     if ($row->category == 9) {
                     $row->category = 'Lighting';
                     }
                     if ($row->category == 10) {
                     $row->category = 'Modelling';
                     }
                     if ($row->category == 11) {
                     $row->category = 'Modifiers';
                     }
                     if ($row->category == 12) {
                     $row->category = 'Particles';
                     }
                     if ($row->category == 13) {
                     $row->category = 'Rendering';
                     }
                     if ($row->category == 14) {
                     $row->category = 'Rigging';
                     }
                     if ($row->category == 15) {
                     $row->category = 'Scripts';
                     }
                     if ($row->category == 16) {
                     $row->category = 'Sculpting';
                     }
                     if ($row->category == 17) {
                     $row->category = 'Texturing';
                     }
                     if ($row->category == 18) {
                     $row->category = 'Tips and Tricks';
                     }
                     if ($row->category == 19) {
                     $row->category = 'UV Mapping';
                     }
                     
                     
                     
                     ?>
<table style="background-image:url(images/tut_back.png); background-repeat: repeat-y; border:1px solid #C2D0DC; width:100%;">
   <tr>
      <td class="tutorials_left" valign="top">

         <div class="tutorial_icon"><a href="tutorials.php?id=<?php echo $row->id; ?>">
            <img src="<?php echo $row->path; ?>" alt="Tutorial Icon" class="tutorial_icon" width="50" height="50"></a>
            
         </div>
      </td>
      
      
      
      
        <td class="tutorials_right" valign="top">
            <div class="tutorial_title"><a href="tutorials.php?id=<?php echo $row->id; ?>"><?php echo $row->name; ?></a>
         </div>
         <div class="tutorial_uploaded"> Uploaded by <?php echo $row->fullname; ?> on <em><?php echo $row->added; ?></em>
         </div>         
         
            <div class="tutorial_cat">Category: <?php echo $row->category; ?>
            </div>
        </td>
   </tr>
</table>
   
      <?php
if ($row->RatedBy == 0) {

$avg = 0;

} else {

$avg = $row->Rating/$row->RatedBy;
$avg = round($avg, 2);
}
   ?>
   
   <div class="tutorial_bar">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="views">Views: <em><?php echo $row->views; ?></em></td>
            <td class="comments">Comments: <em>3</em></td>
            <td class="rating">Rating: <?php echo $avg; ?></a></td>
          </tr>
        </table>
   </div>
   
   <td>

<?php

$i++;

}
?>

Link to comment
https://forums.phpfreaks.com/topic/198885-another-query-within-a-while-loop/
Share on other sites

why have it like that I don't know.

Usually... the while, would display the tutorials by title on one page.

Clicking on the tutorial title goes to viewtutorials.php?tutid=$tutid

So when on that page, it gets all the nessecary details where tutorial_id = $_GET['tudid']

 

Easier method I believe? Although you have categories.. I didn't quite use that.. so .. might be in the same way I guess, it'll display the tutorials by title where category is .. php for example.

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.