using ol in php/table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

using ol in php/table

Post by nite4000 »

Hey I am on my last issue and the problem is

I need to get records from a table however the id in the table could be like 5,6,7,8,9 due to others not there and been deleted to other functions in the script

I need to take 5 and make is display 1 and 6 would be 2 and 7 would be 3 and so on.

This is what I have currently without the use of the ol and li

Code: Select all


  <table width="798">
			  <tr><th>id</th><th width="211">Amount</th><th width="276">Date</th><th width="295">Status</th></tr>
               <?php $query=mysql_query("SELECT * from line WHERE pid='7' AND username ='{$_SESSION['admin_user']}'")or die(mysql_error());
		      while($line = mysql_fetch_array($query, MYSQL_ASSOC)) {

		  echo '<tr><td>'.$line['id'].'</td><td width="211">'.$line['spent_amt'].'</td><td width="276">'.$line['date'].'</td><td width="295">'.$line['status'].'</td></tr>';
		  
			  }
		  
		  ?></table>


any help would be appriciated.
User avatar
azycraze
Forum Commoner
Posts: 56
Joined: Mon Oct 24, 2011 12:08 pm
Location: India

Re: using ol in php/table

Post by azycraze »

try this

=================================
$id=$line['id']-4;
echo '<tr><td>'.$id.'</td><td width="211">'.$line['spent_amt'].'</td><td width="276">'.$line['date'].'</td><td width="295">'.$line['status'].'</td></tr>';
=================================
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Re: using ol in php/table

Post by litebearer »

this should work for any skipped numbers in the id field

Code: Select all

$i=1;
while($line = mysql_fetch_array($query, MYSQL_ASSOC)) {
  echo '<tr><td>'.$i .'</td><td width="211">'.$line['spent_amt'].'</td><td width="276">'.$line['date'].'</td><td width="295">'.$line['status'].'</td></tr>';
 $i++;
}
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: using ol in php/table

Post by nite4000 »

thanks. I will try that
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: using ol in php/table

Post by nite4000 »

that worked great thanks for the help
Post Reply