asimkhan Posted July 17, 2008 Share Posted July 17, 2008 Friends, i need urgent help to fix this code that should fatch the record from table and display it in descending order agains the Date/time : -------------------------------------------------------- <?php require_once 'db/db.php'; session_start(); /* function check() { $accState = $_SESSION['account_state']; $Uname = $_SESSION['user_name']; $Iclient = $_SESSION['id_client']; $Recharge = $_POST['txtRecharge']; $sql = "SELECT * FROM pins WHERE name='$Recharge' and id_status='1'"; $rs = mysql_query($sql) or die ("Wrong SQL Staement.."); while($row = mysql_fetch_array($rs)) { if($row['name'] == $Recharge && $row['id_status']==1) { $Amount = $row['amount']; $accState = $accState + $Amount; $QueryUpdate = "UPDATE clientshearlink SET account_state='$accState' " ." WHERE id_client = '$Iclient' " ." and login = '$Uname' "; echo $Uname.": ".$accState; } else echo "Invalid PIN."; } } */ if(empty($_SESSION['id_client'])) { session_destroy(); header("Location:p2plogin.php?error=illegalLogin"); } if(empty($_GET['page_no'])) { $page_no = 1; } else { $page_no = $_GET['page_no']; } $start = 30 * ($page_no - 1); $end = 30; $cur_time = getdate(time()); $cur_day = $cur_time['mday']; $cur_month = $cur_time['mon']; $cur_year = $cur_time['year']; $param = "param=null"; // passed as url parameter for next and previous page link $selected = array(); if(empty($_GET['s_day']) || empty($_GET['s_month']) || empty($_GET['s_year']) || empty($_GET['e_day']) || empty($_GET['e_month']) || empty($_GET['e_year'])) { $from = date("Y-m-d", time()) . " 00:00:00"; $to = date("Y-m-d", time()) . " 23:59:59"; $selected['s_day'] = $selected['e_day'] = $cur_day; $selected['s_month'] = $selected['e_month'] = $cur_month; $selected['s_year'] = $selected['e_year'] = $cur_year; } else { $from = $_GET['s_year'] . "-" . $_GET['s_month'] . "-" . $_GET['s_day'] . ' ' . "00:00:00"; $to = $_GET['e_year'] . "-" . $_GET['e_month'] . "-" . $_GET['e_day'] . ' ' . "23:59:59"; $param = "s_year={$_GET['s_year']}&s_month={$_GET['s_month']}&s_day={$_GET['s_day']}&" . "e_year={$_GET['e_year']}&e_month={$_GET['e_month']}&e_day={$_GET['e_day']}"; $selected['s_day'] = $_GET['s_day']; $selected['s_month'] = $_GET['s_month']; $selected['s_year'] = $_GET['s_year']; $selected['e_day'] = $_GET['e_day']; $selected['e_month'] = $_GET['e_month']; $selected['e_year'] = $_GET['e_year']; } ?> <html> <head> <style> <!-- div.header { font-family:Arial, Helvetica, sans-serif; //background-color:#CCCCCC; color:#FF0000; border:none; font-size:16px; text-align:center; float:none; width:auto } table { } --> </style> </head> <body> <div style="float:right"><a href="http://64.34.95.131/webphone/wr/guide1.aspx">Logout</a></div> <?php echo "<br/><div class=\"header\">"; echo "Client Type: PC 2 Phone, "; echo "User: ". $_SESSION['user_name'] . ", "; echo "User remaining funds: " . $_SESSION['account_state'] . "</div><br/>"; ?> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"><br/> <input type="hidden" page_no="1"> <table> <tr> <td>From</td> <td> <select name="s_day"> <option value=""> Day </option> <?php for($i = 1; $i <= 31; $i++) if($i == $selected['s_day']) printf("<option value=%02d selected> %2d </option>\n", $i, $i); else printf("<option value=%02d> %2d </option>\n", $i, $i); ?> </select> <select name="s_month"> <option value=""> Month </option> <?php for($i = 1; $i <= 12; $i++) if($i == $selected['s_month']) printf("<option value=%02d selected> %2d </option>\n", $i, $i); else printf("<option value=%02d> %2d </option>\n", $i, $i); ?> </select> <select name="s_year"> <option value=""> Year </option> <?php for($i = 1999; $i <= 2006; $i++) if($i == $selected['s_year']) printf("<option value=%04d selected> %4d </option>\n", $i, $i); else printf("<option value=%04d> %4d </option>\n", $i, $i); ?> </select> </td> </tr> <tr> <td>To</td> <td> <select name="e_day" size="1"> <option value="">Day</option> <?php for($i = 1; $i <= 31; $i++) if($i == $selected['e_day']) printf("<option value=%02d selected> %2d </option>\n", $i, $i); else printf("<option value=%02d> %2d </option>\n", $i, $i); ?> </select> <select name="e_month"> <option value="">Month</option> <?php for($i = 1; $i <= 12; $i++) if($i == $selected['e_month']) printf("<option value=%02d selected> %2d </option>\n", $i, $i); else printf("<option value=%02d> %2d </option>\n", $i, $i); ?> </select> <select name="e_year"> <option value="">Year</option> <?php for($i = 1999; $i <= 2006; $i++) if($i == $selected['e_year']) printf("<option value=%04d selected> %4d </option>\n", $i, $i); else printf("<option value=%04d> %4d </option>\n", $i, $i); ?> </select> </td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Filter"></td> </tr> </table> </form> <br><br> <a href="p2ppayments.php" target="_blank">Payment List</a> <br><br> <!--<form name="check" action="p2pcheck.php" method="post">--> <form name="PIN" method="post" action="p2pcheck.php"> <table width="30%" border="0" cellspacing="2" cellpadding="2"> <tr> <td align="left"><input name="txtRecharge" type="text" size="20" maxlength="20"></td> <td align="right"><input name="btnRecharge" type="submit" value="PIN Recharge"></td> </tr> </table> </form> <?php $query_total_cost = "SELECT SUM(cost) total_cost FROM calls " . " WHERE id_client = " . $_SESSION['id_client'] . " AND client_type = 1 " . " AND call_start >= '{$from}' AND call_start <= '{$to}'"; //. " GROUP BY id_client "; //echo "<br>" . $query_temp . "<br/>"; $result_total_cost = mysql_query($query_total_cost) or die("billing.php: 168 " . mysql_error()); $row = mysql_fetch_assoc($result_total_cost); $total_cost_period = $row['total_cost']; printf("<br/>Total cost during the period: %.2f <br/><br/>\n" , $total_cost_period); $query_all = "SELECT * FROM calls " . " WHERE id_client = " . $_SESSION['id_client'] . " AND client_type = 1 " . " AND call_start >= '{$from}' AND call_start <= '{$to}'"; $result_all = mysql_query($query_all) or die("billing.php: 97 " . mysql_error()); $num_rows = mysql_num_rows($result_all); if($num_rows == 0) { echo '<font color="red" size="+1">No call in this duration</font>'; exit(0); } // echo "<br/>Number of rows: " . $num_rows . "<br />"; $num_pages = ceil($num_rows/30); if(($page_no < 1) || ($page_no > $num_pages)) { echo '<font color="red" size="+1">Illegal page number</font>'; exit(1); } $prev_page = ($page_no > 1)? $page_no-1 : 1; $next_page = ($page_no < $num_pages)? $page_no+1 : $num_pages; ?> <center> <table width="100%" border="0" style="background-color:#CCCCCC"> <tr> <td align="left"><a href="p2pbilling.php?page_no=<?php echo $prev_page . "&". $param;?>"><< Prev</a></td> <td colspan="3" align="center"><?php echo "Page $page_no of $num_pages"; ?></td> <td align="right"><a href="p2pbilling.php?page_no=<?php echo $next_page . "&". $param;?>">Next >></td> </tr> </table> <table width="100%" cellpadding="3" cellpadding="3" border="1" rules="rows" onMouseOver="this.style.color=red"> <tr align="left"> <th>Row number</th> <th>Destination</th> <th>Call Start</th> <th>Call End</th> <!-- <th>Actual Dur</th> --> <th>Duration(Mins)</th> <th>Cost</th> </tr> <?php //echo "Number of rows " . mysql_num_rows($result_calls) . "<br/>"; $query_calls = "SELECT * FROM calls " . " WHERE id_client = " . $_SESSION['id_client'] . " AND client_type = 1 " . " AND call_start >= '{$from}' AND call_start <= '{$to}'" . " ORDER BY call_start DESC LIMIT {$start}, {$end}"; //echo "<br/>query_calls: " . $query_calls . "<br/>"; $result_calls = mysql_query($query_calls) or die("p2pbilling.php: 97 " . mysql_error()); $rowNum = 30 * ($page_no-1); $totalDuration = 0; while($row = mysql_fetch_assoc($result_calls)) { $rowNum++; echo "<tr align=\"left\">\n"; echo "<td>" . $rowNum . "</td>\n"; echo "<td>" . $row['called_number']. "</td>\n"; echo "<td>" . $row['call_start'] . "</td>\n"; echo "<td>" . $row['call_end'] . "</td>\n"; // echo "<td>" . $row['duration'] . "</td>\n"; $billingDuration = (int)(($row['duration']+59)/60); if($row['cost'] > 0) $totalDuration += $billingDuration; echo "<td>" . $billingDuration . "</td>\n"; printf("<td> %.2f </td>\n", $row['cost']); // echo "<td>" . $row['cost'] . "</td>\n"; echo "</tr>"; } echo "<tr>\n"; echo "<td colspan=4>Total</td>"; echo "<td>" . $totalDuration . "</td>\n"; echo "</tr>"; ?> </table> <table width="100%" border="0" style="background-color:#CCCCCC"> <tr> <td align="left"><a href="p2pbilling.php?page_no=<?php echo $prev_page . "&". $param;?>"><< Prev</a></td> <td colspan="3" align="center"><?php echo "Page $page_no of $num_pages"; ?></td> <td align="right"><a href="p2pbilling.php?page_no=<?php echo $next_page . "&". $param;?>">Next >></td> </tr> </table> </center> </body> </html> ---------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/115316-urgent-help-want-to-display-in-desc-order/ Share on other sites More sharing options...
ringworld Posted July 17, 2008 Share Posted July 17, 2008 A little more info would be nice. Quote Link to comment https://forums.phpfreaks.com/topic/115316-urgent-help-want-to-display-in-desc-order/#findComment-592864 Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 Simply add... ORDER BY fieldname DESC to the end of whatever query it is your talking about. Quote Link to comment https://forums.phpfreaks.com/topic/115316-urgent-help-want-to-display-in-desc-order/#findComment-592865 Share on other sites More sharing options...
asimkhan Posted July 17, 2008 Author Share Posted July 17, 2008 actully i never work on PHP with mysql, if you guys look @ the script i hope you solve it within a sec. i really appriate your help. Regards Quote Link to comment https://forums.phpfreaks.com/topic/115316-urgent-help-want-to-display-in-desc-order/#findComment-592877 Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 It might help if you tell us which query your talking about! Quote Link to comment https://forums.phpfreaks.com/topic/115316-urgent-help-want-to-display-in-desc-order/#findComment-592879 Share on other sites More sharing options...
asimkhan Posted July 17, 2008 Author Share Posted July 17, 2008 See it does fatch the record from two tables ( one is Calls and 2nd is cliente164 ), it does search the user / password from table ( cliente164 ) and then fatch the record from Calls against the ( client_Id ), and then print it on screen ), i need the printed thing in decending order, my request is where i have to change the things in the above codes. so it print the records in decending order against date/time a/c to the ( Call_start ) . I hope you can understand it now, regard Quote Link to comment https://forums.phpfreaks.com/topic/115316-urgent-help-want-to-display-in-desc-order/#findComment-592887 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.