jbrill Posted July 17, 2007 Share Posted July 17, 2007 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'; ?> Link to comment https://forums.phpfreaks.com/topic/60390-solved-displaying-results-with-decimals-and-stylizing-them/ Share on other sites More sharing options...
akitchin Posted July 17, 2007 Share Posted July 17, 2007 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). Link to comment https://forums.phpfreaks.com/topic/60390-solved-displaying-results-with-decimals-and-stylizing-them/#findComment-300432 Share on other sites More sharing options...
jbrill Posted July 17, 2007 Author Share Posted July 17, 2007 That worked great EXCEPT for one little thing... it is now indenting every job number after the initial like so: Job Number 123 123.2 123.3 222 222.1 Link to comment https://forums.phpfreaks.com/topic/60390-solved-displaying-results-with-decimals-and-stylizing-them/#findComment-300446 Share on other sites More sharing options...
akitchin Posted July 17, 2007 Share Posted July 17, 2007 perhaps add an else statement to set it to empty; for some reason i guess it's probably propagating its value: if ($floored != $row['job_number']) $indent = ' '; else $indent = ''; Link to comment https://forums.phpfreaks.com/topic/60390-solved-displaying-results-with-decimals-and-stylizing-them/#findComment-300453 Share on other sites More sharing options...
jbrill Posted July 17, 2007 Author Share Posted July 17, 2007 THANKS GUYS! what would i do without this forum! Link to comment https://forums.phpfreaks.com/topic/60390-solved-displaying-results-with-decimals-and-stylizing-them/#findComment-300457 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.