Jump to content

[SOLVED] displaying results with decimals, and stylizing them.


jbrill

Recommended Posts

Hey,

I just have what I think is an easy question for some of you. I have a page that pulls all the entries from a specific table in the database. The results are displayed in a table. In this table there is  column for "job_number" this job number is a decimal entry, i need to display the job numbers, grouped by the the numbers ahead of the decimal place and then ordered by the numbers after the decimal. I would also like to indent the decimals ONLY numbers below the under that does not have a decimal.

 

here is an example:

Job_numbers

123

  123.2

  123.3

 

here is my current code for the way it is displayed now:

<?
include 'admin_header.php';

// this part validates whether the user is logged in as a administrator or not
if(isset($_SESSION['id']))

include "admin_jobmenu.php";


include 'admin_search.php';
?>
<br>
<? // This displays all the jobs
$result = mysql_query("SELECT * FROM jobs");
$result_dlr = mysql_query("SELECT * FROM jobs WHERE status='In Progress' OR status='On Hold'");


echo"<table border=\"0\" width=\"80%\" bgcolor=\"#ffffff\" class=\"MainBody1\" cellpaddin=\"0\" cellspacing=\"0\"  id=\"findjobs\">";
echo"<tr>";
echo"<td class=\"underline\">Quote Number</td><td class=\"underline\">Job Number</td><td class=\"underline\">PO Number</td><td class=\"underline\">Customer</td><td class=\"underline\">Status</td><td class=\"underline\">Action</td>";
echo"<tr>";

if($_SESSION['type'] == "admin")
{
while($row = mysql_fetch_array($result))
{
$css_class = ($css_class=='row_style_1') ? 'row_style_2' : 'row_style_1';

  echo "<tr class=\"$css_class\"><td>" . $row['id'] .  "</td><td>"  . $row['job_number'] ."</td><td>" . $row['po_number'] . "</td><td>" . $row['customer'] . "</td><td>" . $row['status'] . "</td><td>"; 
  
?>

<? 
//only display delete & edit functions for admins 

echo "<a class=\"link\" href=\"admin_modjob.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionEdit.gif\" border=\"0\"></a> <a class=\"link\" href=\"admin_delete.php?idr=".$row['id']."&table=jobs\"><img src=\"images/actionDelete.gif\" border=\"0\"></a>";
}
}
else
{
while($row_dlr = mysql_fetch_array($result_dlr))
{

  echo "<tr><td class=\"underlineLight\">" . $row_dlr['id'] .  "</td><td class=\"underlineLight\">"  . $row_dlr['job_number'] ."</td><td class=\"underlineLight\">" . $row_dlr['po_number'] . "</td><td class=\"underlineLight\">" . $row_dlr['customer'] . "</td><td class=\"underlineLight\">" . $row_dlr['status'] . "</td><td class=\"underlineLight\">"; 

echo	"<a class=\"link\" href=\"admin_modprocess.php?idr=".$row_dlr['id']."&table=jobs\"><img src=\"images/actionAddTime.gif\" border=\"0\"></a>";
}
}

echo "</td></tr>";
echo "</table>";

include 'admin_footer.php';
?>

 

you could simply floor the value to find out if it's the same as the original.  for example:

 

SELECT * FROM jobs ORDER BY job_number ASC

 

while($row = mysql_fetch_array($result))
{
$css_class = ($css_class=='row_style_1') ? 'row_style_2' : 'row_style_1';

$floored = floor($row['job_number']);
if ($floored != $row['job_number'])
  $indent = '   ';

  echo "<tr class=\"$css_class\"><td>" . $row['id'] .  "</td><td>"  . $indent . $row['job_number'] ."</td><td>" . $row['po_number'] . "</td><td>" . $row['customer'] . "</td><td>" . $row['status'] . "</td><td>";

 

this will indent any number that has a decimal remainder with three spaces.  if you have a problem with the ordering of your results, it likely has to do with the type of field you're using to hold the job number (it needs to be a float to properly order them).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.