PHP - Change The Order
I have quite a long .php page but I've attached the end of it. I was wondering if I can change the order it is displayed. Basically $j is a year. And currently it goes from 1894 until 2019. I don't think anything is currently telling it to sort either way, it just by default shows that way. But I want it to show 2019 first and go down to 1894. I had this written for me by someone who I can no longer get hold of. $total_record=count($session_player); $i=0; $palyerslink=""; foreach($session_player as $var=>$val) { $i++; if($i==$total_record) $palyerslink.="<a href='/history/?pid=$var' title='view this in more detail'>$val</a>"; else $palyerslink.="<a href='/history/?pid=$var' title='view this in more detail'>$val</a>, "; } if(!empty($session_player)) { $tr++; $records.="<tr class=row> <td class=border-right><a href='/history/browse?season=$j'>$j-$value</a></td> <td class=border-right>$max_goal_season</td> <td>$palyerslink</td> </tr>"; } } $records.="</table></div>"; echo $records; ?>
This is the end of the page where the records are then displayed using the echo. I'm not sure if more code is needed though, I could post it in full if needed Edited May 29, 2020 by alxneSimilar TutorialsHey guys, I am having trouble figuring this out. I currently have a database that automatically sorts itself by the id of the data. But, I am wanting the user to be able to change the sort order via a select box. I already have the select box programmed with the options, but I am not sure how to go about coding the options to change the sort order of the displayed data. What would the best way to go about programming this be? Thank you very much ahead of time!! Here's the query: Code: [Select] $sql = mysql_query("SELECT * FROM resources WHERE gameCat = '' ORDER BY systemCat,order_id"); I want something to happen when the systemCat changes in the results. Like this: Code: [Select] if($row['systemCat'] CHANGES){ echo '<div id="seperator"></div>'; } Any ideas? Thank you!
Hi everyone. I'm very new into self learning programming. Presently I'm trying to develop a simple basic Robot that would only Place a Market Order every seconds and it will cancel the Order every followed seconds. Using the following library: It would place Trade Order at a ( Price = ex.com api * Binance api Aggregate Trades Price) I have already wrote the api to call for xe.com exchange rate with php <?php $auth = base64_encode("username:password"); $context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ] ]); $homepage = file_get_contents("https://xecdapi.xe.com/v1/convert_from?to=NGN&amount=1.195", false, $context ); $json = json_decode($homepage, TRUE); foreach ($json as $k=>$to){ echo $k; // etc }; ?> And also for the Binance Aggregate Price in JavaScript
<script> var burl = "https://api3.binance.com"; var query = '/api/v3/aggTrades'; query += '?symbol=BTCUSDT'; var url = burl + query; var ourRequest = new XMLHttpRequest(); ourRequest.open('GET',url,true); ourRequest.onload = function(){ console.log(ourRequest.responseText); } ourRequest.send(); </script>
My problem is how to handle these two api responds and also the functions to use them to place a trade and cancel it. I've got. I got this code from a previous thread: Code: [Select] mysql_query("SET @rows = 0;"); $res = mysql_query("SELECT @rows:=@rows+1 AS view_rank,COUNT(id) AS views, credit_members_id FROM vtp_tracking GROUP BY credit_members_id ORDER BY views DESC"); $n = array(1 => 'st', 2 => 'nd', 3 => 'rd'); while($row = mysql_fetch_row($res)) { if ( $row[2] != $members_id ) continue; if ( substr($row[0], -1) < 4 ) { $row[0] .= $n[$row[0]]; } else { $row[0] .= 'th'; } echo ' You are in ' . $row[0] . ' place with ' . number_format($row[1]) . ' views.'; break; } Everything seems ok except it orders by the "credit_members_id" and not "views" as entered. Can someone explain why, and how to fix this? I need to make 0, which displays as POA appear at the ned of the list not at the begining, I currently just use order by price asc and 0 is at the beginning, i need to make 0 at the end Hi there, just registered and in need of help, this looks a good place to start! I'm a php beginner so please bear with me I have a mysql database which holds 3 pieces of info id: match: 1: I'm trying to sort the results using ORDER BY match ASC but for some reason it's just not for having it... Can't work out if it's an error with my php code or my table. I can order by "ID" no problem but I when I try ordering alphabetically by "match" it won't. my code is: Code: [Select] mysql_connect("***.***.***") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $query = "SELECT * FROM employees WHERE flag = 'tv' ORDER BY match ASC"; $result = mysql_query($query) or die ("Query failed"); $numrows = (mysql_num_rows ($result)); // loop to create rows if($numrows >0){ echo "<table width = 100% border = '0' cellspacing = '2' cellpadding = '0' >"; // loop to create columns $position = 1; while ($row = mysql_fetch_array($result)){ if($position == 1){echo "<tr>";} echo " <td align = 'center'><a href=\"http://www.website.eu/sport-stream/1/{$row['id']}.html\" target=_blank>{$row['match']} <br> <img src=\"{$row['8']}\" width=\"100\" height=\"70\" /> </a> </td> "; if($position == 4){echo "</tr> "; $position = 1;}else{ $position++;} }//while $end = ""; if($position != 1){ for($z=(4-$position); $z>0 ; $z--){ $end .= "<td></td>"; } $end .= "</tr>"; } echo $end."</table> "; }//if And here's a cap of my database: any help for a php n00b would be greatly appreciated! Hello, I have classes in a database with no set UNIX date, just the day like Wednesday and in two other columns the start and end dates. I want to be able to order by the day first and then by end_time but php orders the day column by spelling and not the day it holds in chronological order. Is there anyway to change the query to order the day column as a date? See the query below? Code: [Select] $query = "SELECT * FROM zumba_timetable WHERE end_time>'$current_time' ORDER BY day, end_time ASC LIMIT 0,1"; Currently i have a query which at the end has this Code: [Select] order by (value/counter) desc"); which works fine, however i was wondering, if in the case that 2 rows have the same, is it possible to set a second value to order by? Hey everybody, i'm building a website for the softball league i play in.... so far the website is pretty good... with all the stats and profiles.... i'm having a little problem with the ORDER of the leaders in the categories i have to calculate the result... for example... avg. is the result of the total hits divided by the total number of at bats... both numbers are coming from the database... the problem comes when i have to order the leaders from first to last... this is my php: Code: [Select] $sql = "select profile_id, SUM(total_hits) AS hitstotal, SUM(ab) AS abtotal from batters WHERE year = '2010' GROUP BY profile_id"; $cons = mysql_query($sql); while ($result = mysql_fetch_array($cons)) { $sumaab = $resultad['abtotal']; $sumahits = $resultad['hitstotal']; $p_id = $resultad['profile_id']; $prom = round(($sumahits."") / ($sumaab.""),3); that gives me all the batting averages for the players. and here is my question: how can i order that $prom result from first to last? Greetings! I am really stock on this situation. 1. I have a variable $uc_order_created. 2. I have a code like this: <b><?php echo t('Due Date:'); ?></b> </td> <td width="98%"> <?php $duedate = mktime(0,0,0,date("m"),date("d")+30,date("Y")); echo "".date("F jS Y", $duedate);?> 3. How do I code if I want the result of $uc_order_created get displayed as Due Date using the code above? Or other modifications? 4. The situation now, the code is working when printing the invoice but its not based on $uc_order_created. So, every time I will edit the Order because of the change of items among others the Due Date will also update. All I want that when Order is edited the value of Due Date will still remain based on the $uc_order_created. Thank you so much in advance for your help. I want to get the top 5 rows with common keywords how can i do this? its like this Code: [Select] $query = "SELECT adder,min(title)FROM shsh group by adder order by mysql_num_rows($q)"; Hello, Am trying to get my records in ascending order from the database using 'ORDER BY' but they come randomly. What might be the problem? Hi All, I have a 'Newspaper' in a game I'm coding. My plan was to have an edition every week and on average 15 articles a week. I would set this out like so. . Code: [Select] <? $select_paper=mysql_query("SELECT * FROM paper WHERE id=1"); while($the=mysql_fetch_object($select_paper)){ ?> <table width=100% class=table> <tr> <td> <td width=50% style=border: none; background-color: transparent; valign=top> <table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center> <tr> <td width=500 class='tableheading'><?php echo "$the->title"; ?><center> </center></td> </tr> <tr > <td class="profilerow" align=left><center><?php echo "$the->news"; ?> </td> </tr> <tr > <td class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?> </td> </tr> </table> <br> </td> <? } ?> With that repeated for 15 articles per edition. BUT! To save time, space and complication, I would rather do it using something like this. . Code: [Select] $select = mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC"); $num = mysql_num_rows($select); Could someone tell me how to intergrate this with the layout tables as show in code #1? Thanks! I'm just trying to see if the order of my logic is correct or if there's something I can do differently. I'm also curious to know at what point I should get the 2 passwords that exists in the database for the user. These are two different passwords. Code: [Select] function login_submit() { $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean'); $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean'); $this->form_validation->set_rules('remember', 'Remember me', 'integer'); $user_id = $this->users->get_user_id_by_username($this->input->post('username')); if ($user_id !== 0) { if ($this->kow_auth->is_max_login_attempts_exceeded($user_id)) { echo json_encode(array('error' => 'yes', 'message' => 'Your account is currently locked, we appologize for the inconvienence. You must wait 10 minutes before you can login again!')); } else { $user_status = $this->users->get_user_status($user_id); if ($user_status == 1) { echo json_encode(array('error' => 'yes', 'message' => 'Sorry you must verify your account before logging in!')); } elseif ($user_status == 3) { echo json_encode(array('error' => 'yes', 'message' => 'Your account has been suspended!')); } elseif ($user_status == 4) { echo json_encode(array('error' => 'yes', 'message' => 'Your account is currently banned!')); } elseif ($user_status == 5) { echo json_encode(array('error' => 'yes', 'message' => 'Your account has been deleted!')); } else { if ($this->form_validation->run()) { if ($this->kow_auth->login($this->form_validation->set_value('username'), $this->form_validation->set_value('password'), $this->form_validation->set_value('remember'))) { redirect(''); } else { echo json_encode(array('error' => 'yes', 'message' => 'Incorrect username and password combination!')); } } } } } else { echo json_encode(array('error' => 'yes', 'message' => 'Incorrect username and password combination!')); } } how do I order two tables by date so that the most recent are first and the most unrecent last? like table 1 should be first then a table 2 then a table 1. does this make sense? I'm pulling a list from a DB and inserting it in a drop down menu. Each item on the list has a numerical id associated called marketid in the DB. It works, but it orders the list alphabetically. I need it to order by marketid which is the column name. What code do I need to add? Here is what I have now.... <option value="<?=$market['marketid']?>"><?=$market['name']?></option> Thanks in advance all!! Tony Can someone please explain to me what's the importance of node order? Does certain nodes that appear first or last have impact on traversing time? Any suggestions much appreciated! By not using the order by function in SQL. Like I have $match_1 and $segment_1. They are two seperate tables so how would I order them like the ORDER BY in sql. Is there a way to do that? |