View Single Post
Old 06-10-2003, 07:47 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,503
sde is on a distinguished road
Re: foreach() while() for() or new mysql query?

Code:
while($row=mysql_fetch_row($result))
{ do something }
i think that is what you are looking for .. check this out:

PHP Code:
<?php
            
$db 
mysql_pconnect("localhost""username","password");
  if (!
$db)
  {
     echo 
"Error: Could not connect to database.  Please try again later.";
     exit;
  }

// get results from horizon and topic tables 
 
    
mysql_select_db("aamsurveys_com_au");

    
$query "select * from  topics, horizons
                where topics.issue = horizons.issue
                order by topics.issue desc"
;
    
$result mysql_query($query) or die(mysql_error());
    
$num_results mysql_num_rows($result);
    
    
//*************************************
    //
    // here's the loop you're looking for
    //
    //*************************************
     
while($row mysql_fetch_row($result))
     {
        
$issue=$row[0];
        
$topic=$row[2];
        
$link=$row[3];
        
$category=$row[4];
        
$month=$row[6];
        
$pdfname=$row[7];
        
$filesize=$row[8];
        
$year=$row[9];
        
        
// add topics and links etc

echo "
<tr align='left' valign='left' > 
 <td height='26' colspan='5' >&nbsp;</td>
</tr>
            
<tr align='left' valign='left' >
<td width='200'align='left' >
<font face='arial' size='2' color='#000099'>
Issue "
.$issue."&nbsp;&nbsp;&nbsp;$month&nbsp;$filesize</font>
<p><a href='issue"
.$issue."/index.html'>
<font face='arial' size='1' color='#660000'>View<b>HTML </b></font></a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>
<a href='issue"
.$issue."/".$link."'>
<font face='arial' size='1' color='#660000'>
View <b> PDF "
.$filesize."k </b></font></a>

&nbsp;&nbsp;
</p>
</font>
</td>
               
<tr>
<td colspan='2' valign='top'>
<div align='middle'>
<a href='"
.$link."'>
<font face='arial' size='2' color='#660000'><b>"
.$topic." </b></font></a>
</div></td>
<td >&nbsp;</td>
</tr>               
       <tr> 
          <td height='22'>&nbsp;</td>
          <td >&nbsp;</td>
          <td >&nbsp;</td>
          <td >&nbsp;</td>
       </tr>
 "
;

    
//*******************************************
    //
    // i think this is where you want to end loop .. not sure
    //
    //*******************************************
    
}

     
// build headings and tables    
echo"
<tr>
<td colspan='5'>
 <div align='right'>
 <a href='#top'>
<img src='images/totop.gif' width='100' height='23' border='0' class='totop'></a>
 </div>
</td>
</tr>
<tr  bgcolor='#aea981'>
<td colspan='5'>
<div align='left'>
<a href='horizonstopic.htm'>
<font face='arial' size='2' color='#000099'>
View by Topic</font></a>
</div>
</td>
</tr>
</table>
"
;
?>

--
edited in hopes to make it a little more readable - too much horizontal scrolling...

-bdl
[/b][/quote]
__________________
Mike
sde is offline   Reply With Quote