how do i add auto numbering with each fetching row ? i want auto add new number as serial number with each fetching rows from mysql databse?
<?php
$i=0;
$query=mysql_query("SELECT * FROM cart
WHERE email='".$_SESSION['email']."'");
while($rowdata1=mysql_fetch_array($query))
$i++;
{
?>
<?php echo $i ?> // here i want to add serial number
<?php echo $rowdata1['itemcode']?>
<?php echo $rowdata1['product']?>
<img src="admin/<?php echo $rowdata1['image'] ?>"/>
<?php echo $rowdata1['price']?>
<?php echo $rowdata1['size']?></font>
<?php echo $rowdata1['total']?>
<?php echo $rowdata1['date']?>
<?php $rowdata1['blueexnum']?>
<?php echo $rowdata1['blueexstatus']?>
<?php }?>
problem is solved now thanks
<?php
$i=0;
$query=mysql_query("SELECT * FROM cart
WHERE email='".$_SESSION['email']."'");
while($rowdata1=mysql_fetch_array($query))
{
$i++;
?>
You're almost there, change your code to:
$h = '';
$i = 0;
while($rowdata1=mysql_fetch_array($query)) {
$i++;
$h .= "$i) $rowdata1[itemcode] $rowdata1[product] ";
$h .= "<img src=\"admin/$rowdata1[image]\"/> ";
$h .= "$rowdata1[price] $rowdata1[size] $rowdata1[total] ";
$h .= "$rowdata1[date] $rowdata1[blueexnum] $rowdata1[blueexstatus]<br />";
}
echo $h;
Of course, you can use echo
as you did in your code. It's usually faster though to build the whole string in $h
and echo it out as a whole.
You might want to use a <table>
to display the data in a more structured way.
Use mysql to do that for you. Change your query to
SET @row_number=0;
SELECT @row_number:=@row_number+1 AS row_number, cart.*
FROM cart
WHERE email=?"
Then when you use it, just echo as just another column
<?php echo $rowdata1['row_number']?>
On a side note, don't use $_SESSION['email'] without escaping it.
<?php>
//set counter to 1
$counter = 1;
<thead>
<tr>
th>No.</th>
<th>REGISTRATION #</th>
<th>SURNAME<`enter code here`/th>
</tr>
<tr>
<td><?php echo $counter; ?></td>
<td><?php echo htmlentities($class['registration']); ?></td>
<td><?php echo htmlentities($class['sirname']); ?></td>
</tr>
$counter++;
</tbody>
?>