RE: looping through a database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16 June 2008 21:58, Richard Kurth advised:

> I am looping through a database of files that are numbers 1 through 10
> if  number 1 is in the database I what to print out the first table
> below if it is not then print the else section below. Then
> loop through
> the database to see if 2 through 10 are there and do the same thing.
Of
> course what I am doing does not work. Should I move it all to
> an array
> and then loop through it. Or use a foreach loop.
> Could you please give me an idea where to start looking
> 
> while($row=mysql_fetch_array($sql_result)){
> 
> if ($row["number"]==1) {
> <tr>
> <td> File 1</td>
> <td>This is the file</td>
> <td>Delete</td>
> </tr>
> }else{
> <tr>
> <td>File1</td>
> <td></td>
> <td>Add</td>
> </tr>
> }
> 
> }

Well, first of you need a few <?php ?> tags to make this legal:

  if ($row["number"]==1) {
  ?>
  <tr>
  <td> File 1</td>
  <td>This is the file</td>
  <td>Delete</td>
  </tr>
  <?php
  }else{
  ?>
  <tr>
  <td>File1</td>
  <td></td>
  <td>Add</td>
  </tr>
  <?php
  }
  
  }

Of course, some people frown on this and prefer other techniques such as
echo-ing the HTML, or assembling it into a variable which gets echoed at
the end -- but whatever floats your boat...!!

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 812 4730


To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux