Jump to content

Recommended Posts

how do i do it guys?

 

here is the code

while($res = mysql_fetch_array($result))
           {
						    $id = $res['id'];
               $date = $res['time'];
  						 $newdate = date("D, j M, Y", $date);    
						    if($res['approval'] == "Yes"){
               echo "<tr align='center' bgcolor='#CDE861'>";
						    }else if($res['approval'] == "No"){
						    echo "<tr align='center' bgcolor='#F28598'>";
						    }else{
						    echo "<tr align='center' bgcolor='#EDA553'>";
						    }
               echo"<td><font color='black'>" .$res['randid']."</font></td>";
						    echo"<td><font color='black'>" .strtoupper($res['center'])."</font></td>";
               echo"<td><font color='black'>" .$res['customer_name']."</font></td>";
               echo"<td><font color='black'>". $res['home_phone']. "</font></td>";
               echo"<td><font color='black'>". $newdate. "</font></td>";
						    if($res['approval'] == "Yes"){
						    echo"<td>Approved</td>";
						    }else if($res['approval'] == "No"){
						    echo"<td>Rejected</td>";
						    }else{
						    echo"<td>Pending</td>";
						    }
echo"<td> <a href ='view.php?id=$id'><center>Click to View </center></a></td>";
               if($name=='off'){
						    echo '';

 

i want to the rows to display results by numbering like

 

1. id name etc etc

2. id name etc etc

Link to comment
https://forums.phpfreaks.com/topic/270468-how-do-i-show-numbering-to-table/
Share on other sites

Some notes first:

 

1. The FONT tags have been deprecated for many, many years!

2. Simplify your logic by determining the values to display at the beginning of the loop and then do the output after.

 

To add the row numbers, just add a variable and increment and output it on each iteration.

 

$rowNo = 0;
while($res = mysql_fetch_array($result))
{
   $rowNo++; //Increment Row Number
   $date = date("D, j M, Y", $res['time']);
   $center = strtoupper($res['center']);

   if($res['approval'] == "Yes") {
    $approvalText = "Approved":
    $approvalColor = '#CDE861';
   } else if($res['approval'] == "No") {
    $approvalText = "Rejected":
    $approvalColor = '#F28598';
   } else {
    $approvalText = "Pending":
    $approvalColor = '#EDA553';
   }

   echo "<tr align='center' bgcolor='{$approvalColor}'>\n";
   echo "  <td style='color:black;'>{$rowNo}</td>";
   echo "  <td style='color:black;'>{$res['randid']}</td>";
   echo "  <td style='color:black;'>{$center}</td>";
   echo "  <td style='color:black;'>{$res['customer_name']}</td>";
   echo "  <td style='color:black;'>{$res['home_phone']}</td>";
   echo "  <td style='color:black;'>{$date}</td>";
   echo "  <td>{$approvalText}</td>";
   echo "  <td><a href ='view.php?id={$res['id']}'><center>Click to View </center></a></td>\n";

   //And continue on for other rows

   echo "</tr>\n";
}

Some notes first:

 

1. The FONT tags have been deprecated for many, many years!

2. Simplify your logic by determining the values to display at the beginning of the loop and then do the output after.

 

To add the row numbers, just add a variable and increment and output it on each iteration.

 

$rowNo = 0;
while($res = mysql_fetch_array($result))
{
$rowNo++; //Increment Row Number
$date = date("D, j M, Y", $res['time']);
$center = strtoupper($res['center']);

if($res['approval'] == "Yes") {
 $approvalText = "Approved":
 $approvalColor = '#CDE861';
} else if($res['approval'] == "No") {
 $approvalText = "Rejected":
 $approvalColor = '#F28598';
} else {
 $approvalText = "Pending":
 $approvalColor = '#EDA553';
}

echo "<tr align='center' bgcolor='{$approvalColor}'>\n";
echo " <td style='color:black;'>{$rowNo}</td>";
echo " <td style='color:black;'>{$res['randid']}</td>";
echo " <td style='color:black;'>{$center}</td>";
echo " <td style='color:black;'>{$res['customer_name']}</td>";
echo " <td style='color:black;'>{$res['home_phone']}</td>";
echo " <td style='color:black;'>{$date}</td>";
echo " <td>{$approvalText}</td>";
echo " <td><a href ='view.php?id={$res['id']}'><center>Click to View </center></a></td>\n";

//And continue on for other rows

echo "</tr>\n";
}

 

thanks for this mate really helpful. but im still not sure how to go on about doing the numbering?

Perhaps you missed it?

To add the row numbers, just add a variable and increment and output it on each iteration.

 

$rowNo = 0;
while($res = mysql_fetch_array($result))
{
   $rowNo++; //Increment Row Number
   $date = date("D, j M, Y", $res['time']);
   $center = strtoupper($res['center']);

   if($res['approval'] == "Yes") {
       $approvalText = "Approved":
       $approvalColor = '#CDE861';
   } else if($res['approval'] == "No") {
       $approvalText = "Rejected":
       $approvalColor = '#F28598';
   } else {
       $approvalText = "Pending":
       $approvalColor = '#EDA553';
   }

   echo "<tr align='center' bgcolor='{$approvalColor}'>\n";
   echo "  <td style='color:black;'>{$rowNo}</td>";
   echo "  <td style='color:black;'>{$res['randid']}</td>";
   echo "  <td style='color:black;'>{$center}</td>";
   echo "  <td style='color:black;'>{$res['customer_name']}</td>";
   echo "  <td style='color:black;'>{$res['home_phone']}</td>";
   echo "  <td style='color:black;'>{$date}</td>";
   echo "  <td>{$approvalText}</td>";
   echo "  <td><a href ='view.php?id={$res['id']}'><center>Click to View </center></a></td>\n";

   //And continue on for other rows

   echo "</tr>\n";
}

$rowNo = 0;
while($res = mysql_fetch_array($result))
{
$rowNo++; //Increment Row Number
$date = date("D, j M, Y", $res['time']);
$center = strtoupper($res['center']);


if($res['approval'] == "Yes") {
$approvalText = "Approved":
$approvalColor = '#CDE861';
} else if($res['approval'] == "No") {
$approvalText = "Rejected":
$approvalColor = '#F28598';
} else {
$approvalText = "Pending":
$approvalColor = '#EDA553';
}?>


<tr align='center' bgcolor='<?php {$approvalColor} \n ?>'>
<td style='color:black;'><?php {$rowNo}; ?></td>
<td style='color:black;'><?php {$res['randid']}; ?></td>
<td style='color:black;'><?php {$center}; ?></td>
<td style='color:black;'><?php {$res['customer_name']}; ?></td>
<td style='color:black;'><?php {$res['home_phone']}; ?></td>
<td style='color:black;'><?php {$date}; ?></td>
<td><?php {$approvalText}; ?></td>
<td><a href ="view.php?id=<?php {$res['id']}; ?>"><center>Click to View </center></a></td><br />


//And continue on for other rows


</tr><br /><?php
}

 

sorry but thats the better way to right it instead of using all the echo codes

Edited by JamesThePanda
sorry but thats the better way to right it instead of using all the echo codes

 

Note that code like the following will give a parse error about an unexpected '}'.

 

<td style='color:black;'><?php {$rowNo}; ?></td>

 

You still need an echo statement and the curly quotes aren't needed. Also, the inline styles could be replaced with a style sheet.

 

<tr><td><?php echo $rowNo; ?></td></tr>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.