Page 1 of 1

using ol in php/table

Posted: Sat Mar 03, 2012 8:26 am
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.

Re: using ol in php/table

Posted: Sat Mar 03, 2012 9:49 am
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>';
=================================

Re: using ol in php/table

Posted: Sat Mar 03, 2012 12:17 pm
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++;
}

Re: using ol in php/table

Posted: Sat Mar 03, 2012 12:19 pm
by nite4000
thanks. I will try that

Re: using ol in php/table

Posted: Sat Mar 03, 2012 1:42 pm
by nite4000
that worked great thanks for the help