PHP - Little Help Sorting Table
Similar TutorialsHere is the code: Code: [Select] <table class="sortable"> <?php while($row = mysql_fetch_array($result)) { $title = $row["Rim"]; $model = $row["model"]; $dimenzija = $row["Dimenzija"]; $ime = $row['name']; $cena = $row['price']; $cena = number_format($cena, 2, ',', '.'); $id = $row['product_id']; if($i == 0) echo "<tr>"; echo "<td>" ?><a href="index.php?route=product/product&product_id=<?php echo $id?>"><?php echo $model ?></a> <?php echo "<br>$dimenzija<br>$ime<br>"; ?> <span style="color: #900; font-weight: bold;"><?php echo $cena . "din"?> </span> <?php echo "</td>"; if(++$i == $max_columns) { echo "</tr>"; $i=0; } }} if($i > 0) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo "</tr>"; } $prev = $start - $per_page; $next = $start + $per_page; if (!($start<=0)){ echo "<a href='{$_SERVER['PHP_SELF']}&start=$prev'>Prethodna strana </a>"; } $page = 1; for($x=0;$x<$record_count;$x=$x+$per_page){ if($start != $x){ echo " <a href='{$_SERVER['PHP_SELF']}&start=$x'> $page </a> ";} else{ echo " <a href='{$_SERVER['PHP_SELF']}&start=$x'> <b>$page</b> </a> ";} $page++; } if (!($start>=$record_count - $per_page)){ echo "<a href='{$_SERVER['PHP_SELF']}?route=product/search&start=$next'> Sledeća strana</a>"; } ?> </table> How can i create sorting button? Is it possible to do it without javascript (I am new to PHP and JS is still unknown to me)? Hi, I want to be able to sort table columns dynamically, like clicking on a header arrow? I have no idea where to start. I did a google search and I found lots of pre-made extensions bu not a simple tutorial to get me started. Can you point me in the right direction? Thanks This topic has used a waypoint to get to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=359489.0 How do I like it, you ask? Quite well. Besides the downtime Tuesday I haven't had any server problems, and the game itself is great. Very D2-esque but with very noticeable enhancements. Hello to all phpfreaks out there I need help with sorting some database columns. I ve been searching all day but i didnt found something nice to implement (or my mind is too tired to think right at this specific time) I have a table and inside it i display a picture and some other data.Above the table i inserted a div and inside it i have 5 links which when clicking on them i want to change the display order of the data being displayed in the table, and if clicked again to change again the state for ASC to DESC and so on... Is there any short solution that do the trick? With an array maybe? PS:I have also a pagination which i would like to keep the sorted order from the above table so not to mess around with the results. Thanks in advance I have an array like this: $array[$row] = array ( 'name' = $name, 'discount' = $discount, 'price' = $price ); Now, I have about 200 of those in that array, and im trying to sort by the discount, highest 1st. How would I go about doing that? Thanks. Part of my code: Code: [Select] <?php $arr = array ("Christina", "Daniel", "Andreea); reset($arr); foreach ($arr as $username) { //more code here ... foreach ($stats as $result) { echo $username."'s points - ".$result."<br />"; } } ?> And gives this: Code: [Select] Christina's points - 14 Daniel's points - 45 Andreea's points 23 My question is: can you sort the the $result so it will show Code: [Select] Daniel's points - 45 Andreea's points 23 Christina's points - 14 Thank you i need to sort my database results by the day they were added to the database. There is a column with the timestamp of when they were inserted but how do i group them by the day they were inserted so i can display them as such: Mon 14th: 5 records Tues 15th: 11 records etc. Just a further question from a earlier post that was complete if i do a search and i want to order them from a drop box the if statement would it just look like Quote "select * from Table order by '".$_POST['order']."'" Or would this not work ? Thanx Hello. I have a multi dimensional array that needs to be sorted. Array top25 [index][product id][number_of_purchases]. The index will contain a unique number for each product id. First product will be 1, second product will be 2, etc. The product id will be a id number like 34324ac9a89. The number of purchases will be how many times the item has been purchased. - End result: I want to print the 25 most purchased products in this format. product id - number of purchases a39acz - 503 a8cz9c - 480 zc8ac - 392 How do I do this? Thanks I have a situation where I need to sort files on a screen based on the date that is embedded into the file name. The problem is that I am sorting based off the file name, and when I get my output the LEGACY file always comes out on top of the sort because it starts with a 0 meanwhile the rest have dates appended the the filename so I don't have a problem sorting those. Please help me if you can. <? //Special case for extra files IF($Recordmyrow['App'] == "(Printable)") { $display = false; $column3 = "Printable VER"; IF($securityvalue == "P") { if(substr($path, 0, 5) == "file:") { $filename = substr($path, 5); if(file_exists($filename)) { $basename = substr($filename, 0, strrpos($filename, '.')); $ext = ".pdf"; $allfiles = glob("{$basename}*.pdf"); rsort($allfiles, SORT_NUMERIC); foreach($allfiles as $file) { if($ext == ".pdf") { $column4 = "<a href=\"pdf.php?src={$file}\">VIEW</a><br />\n"; $codate = substr($file, 70, 8); $co = substr($file, 59, 1); if ($codate != "pdf") { $column3 = "Printable File - ".$codate; } elseif ($codate == "pdf") { $column3 = "Printable File - LEGACY"; } IF($lastGroup != $Recordmyrow['Grouping']) { $lastGroup = $Recordmyrow['Grouping']; ?> <TR> <TD colspan="4" align="center" bgcolor="#418765"><B><FONT color="white"><? echo $Recordmyrow['Grouping'] ?></FONT></B></TD> </TR> <? } ?> <TR> <TD class="display" align="center" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column1 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column2 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column3 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>" align="center"><B><? echo $column4 ?></B></TD> </TR> <? $rowcount++; } } } else { $column4 = "Not Available"; ?> <TR> <TD class="display" align="center" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column1 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column2 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column3 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>" align="center"><B><? echo $column4 ?></B></TD> </TR> <? $rowcount++; } } } } i have an array from a database that looks like this (below) but what i want is for the array to be sorted assedningly by the start position so the team with start position 1 will be 1st and so on...if anyone can help me on what i should do please...thank you Code: [Select] Array ( [1] => Array ( [team_name] => A Team [team_nationality] => British [start_position] => 2 ) [2] => Array ( [team_name] => B Team [team_nationality] => British [start_position] => 1 ) [3] => Array ( [team_name] => C Team [team_nationality] => British [start_position] => 4 ) [4] => Array ( [team_name] => B Team [team_nationality] => British [start_position] => 3 ) ) Hello everyone, Could be possible someone help me on this code please? I need to group and sort $search_query. They are the keywords extracted from $_SERVER[HTTP_REFERER] (referer in the query). Thank you in advance. Code: [Select] $query = ("SELECT referer, browser_ip, date, customers_id, counter, browser_id, browser_language FROM visitors WHERE SUBSTRING(browser_language,1,1) != '[' ORDER by date DESC"); $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $referer = $row[0]; IF($referer) { PREG_MATCH("/[\&\?]q=([^&]*)/", $referer, $matches); $search_query = RAWURLDECODE($matches[1]); $search_query = STR_REPLACE("+", " ", $search_query); } ........................ Hello! I have a 2D array that look as follows: $test["name"][0] = "arnold"; $test["name"][1] = "nate"; $test["name"][2] = "steve"; $test["id"][0] = 2; $test["id"][1] = 0; $test["id"][2] = 1; This means arnold has an ID of 2, nate has an ID of 0 and steve has an ID of 1. Now I want to sort the array based on the ID value, so I want to achieve the following result: $test["name"][0] = "nate"; $test["name"][1] = "steve"; $test["name"][2] = "arnold"; How would I achieve this? Help much appreciated. Greetings! I would like to ask for you help sorting a couple of lists that are autogenerated with php. The page reads a content of a folder and makes a menu from the names. The folder names a a, b, c, d... etc. The other part reads the content of the selected folder and displays the files. My problem is, that on windows, using xampp, the both the folders and files appear in alphabetic order (what I want), but on the linux server they get completely messed up. Instead of a, b, its o, a, d, etc. I tried using the sort() function but there is no array to sort... Thank you for any suggestions and help! Inka ps. the server has php 4.3.9... does this matter? could help if we upgrade to 5.3? here is the code: Code: [Select] <?php $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; if ($filename != "." && $filename != "..") { if($_SERVER['REQUEST_URI'] == "index.php?l=" . $filename . '&sec=' . $sec){ echo '<td><img src="imagini/arow.gif"></td><td style="text-align: left;">' . strtoupper($filename) . $space; } else { echo '<td style="text-align: left;"><a href="index.php?l='. $filename . '&sec=' . $sec . '">' . strtoupper($filename) . $space; }}} ?> <?php $letter = "a"; if(isset($_GET["l"])){ $letter = $_GET["l"];} $letter = $dir . $letter; if ($handle = opendir($letter)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $filename = $file; $file2 = substr($filename, 0, -4); $thelist .= '<tr><td style="width: 250px; text-align: left;"><a href="'. $letter . '/'. $file.'">'.$file2.'</a></td></tr>'; } } closedir($handle); } ?> <p><?php echo $thelist; ?></p> I have an array that looks like this... Code: [Select] Array ( [0] => Array ( [0] => 2 [1] => Dylan Cross ) [1] => Array ( [0] => 5 [1] => Bob Smith ) [2] => Array ( [0] => 1 [1] => Sarah Park ) [3] => Array ( [0] => 7 [1] => Jane Knowles ) [4] => Array ( [0] => 6 [1] => Harry Hill ) [5] => Array ( [0] => 3 [1] => Jack Rock ) ) How do I sort this array so it is ordered alphabetically by the names so the result will be... Code: [Select] Array ( [0] => Array ( [0] => 5 [1] => Bob Smith ) [1] => Array ( [0] => 2 [1] => Dylan Cross ) [2] => Array ( [0] => 6 [1] => Harry Hill ) [3] => Array ( [0] => 3 [1] => Jack Rock ) [4] => Array ( [0] => 7 [1] => Jane Knowles ) [5] => Array ( [0] => 1 [1] => Sarah Park ) ) Thanks Hi - I'm modifying some PHP code that someone else wrote. Below is a snippet of code that basically takes mp3 files files within all the folders in a directory, and creates an RSS feed. In the resulting feed, the files are intermingled in date order. Instead, I'd like them sorted by the directory that they are in. So, if there are files in these directories: 01-First 02-Second 03-Third I'd like all the files in the "01-First" directory to come before the "02-Second" directory and so on. Within each directory the files can be sorted as they currently are. The name of the directory in the code is signified by $dir_name. I tried sort() and array_multisort() but I couldn't get either of them to work the way I wanted. Any thoughts? if ($url_params['mode'] == 'rss2') { print getRSSHeader('UTF-8', $device, $vm_config, $vm_name, $web_master, $logo_image,$context); $mailboxes = array(); if ($dev_dir = @opendir($VMHome . $device)) { //might fail if mailbox has not received first message yet while ($f = readdir($dev_dir)) { if (!eregi("tmp","$f") && !eregi("\.+","$f") && !eregi("Exclude-From-CD", "$f")) { //skip tmp directory and Exclude-From-CD Directories array_push($mailboxes,"$f"); #collect all existing mailboxes } } array_multisort($mailboxes, SORT_DESC); foreach ($mailboxes as $mailbox) { $files=array(); $dir_name = $VMHome . $device . '/'. $mailbox .'/'; $dir = opendir($dir_name); while ($f = readdir($dir)) { if (eregi("\.txt",$f)){ #if filename matches .txt in the name array_push($files,"$f"); #push into $files array } } foreach($files as $file){ $props = getProperties($dir_name, $file); $uid = getMP3File($dir_name, $file, $props, $device, $mailbox, $vm_config, $vm_name,$context); print getRSSItem ($props, $uid, $dir_name, $device, '/' . $mailbox . '/', $context); } } } print ' </channel> </rss>'; } I am looking for information on how to accomplish this: I want to order an array based on a variable. I have an array that is set like this array(1,2,3,4,5,6). I want to order this array base on a variable that will be in the array. So say my variable $x = 3, I want to order the array starting with the number right after the $x. So the array would look like this now array(4,5,6,1,2,3). Is this even possible? Another example if $x = 6, The array would be array(1,2,3,4,5,6). So basically order the array so that the set variable (in this case $x) will be at the end and the rest will run in order. First of all I am very new to php. I have coded in asp for years but have made the switch so I kinda know what I want to do but I am unsure on how to achieve it. I have a css menu that I am trying to populate through a database. The parent tabs are in a standard list. The first child submenu is in sepearate unordered list and anymore child tabs are within that list. Like this. Code: [Select] <div id="ddtopmenubar" style="width: 960px"> <ul> <li><a href="?page=">HOME </a></li> <li><a href="?page=About" rel="">ABOUT </a></li> <li><a href="?page=Services" rel="SERVICES">SERVICES </a></li> <li><a href="?page=Governance" rel="GOVERNANCE">GOVERNANCE </a></li> <li><a href="?page=Events">EVENTS </a></li> <li><a href="?page=Contact">CONTACT </a></li> </ul> <ul id="SERVICES" class="ddsubmenustyle"> <li><a href="?page=Health">Health/Dental</a></li> <li><a href="?page=Identification">International Student Identification Card</a></li> <li><a href="?page=Employment">Student Employment</a></li> <li><a href="?page=Saver">Student Saver</a></li> <li><a href="#">Other Services</a> <ul> <li><a href="#">Emergency Student Loan Fund</a></li> <li><a href="#">Legal Services</a></li> <li><a href="#">Parking Permits</a></li> <li><a href="#">Homes4Students</a></li> </ul> </li> </ul> <ul id="GOVERNANCE" class="ddsubmenustyle"> <li><a href="?page=Council">Your Council</a></li> <li><a href="?page=Executive">Executive</a></li> <li><a href="?page=Committees">Committees</a></li> <li><a href="?page=Constitution">Constitution/By-Laws</a></li> <li><a href="?page=Minutes">Minutes</a></li> <li><a href="?page=Elections">Elections</a></li> </ul> </div> I am trying to populate this from a database list the results come ordered like this Code: [Select] 1.0 2.0 3.0 3.1 3.2 3.3 3.4 3.4-1 3.4-2 3.4-3 3.4-4 4.0 4.1 4.2 4.3 4.4 4.5 4.6 5.0 6.0 where the "." show the 1st childs and the "-" show the 2nd child I tried to do this by splting each line and determining if it is a zero or not if it was a zero i put that paticular one into an array to be used in the sub menu however this did not work out. Any ideas? This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=317320.0 The following code works, but I need to take it a step further and I'm not sure how. What I'd like to do is sort the output so the highest point totals get printed first (along with the associated information). Can anyone help? Here's the site: http://www.beat-the-spread.net/seasontotals.php Here's the code: Code: [Select] $i=1; $w=1; $result = mysql_query( " SELECT team_name, owner FROM teams" ); while ($row = mysql_fetch_array($result)) { echo "<tr>\n", "</td><td>", $row['owner'], "</td><td>", $row['team_name']; $result1 = mysql_query( " SELECT bye, owner_pts FROM schedule WHERE team = $i"); $num_rows = mysql_num_rows($result1); while ($row1 = mysql_fetch_array($result1)) { $totalpts = $totalpts + $row1['owner_pts']; if (empty($row1['bye'])) { echo "</td><td>", $row1['owner_pts'], "</tr>\n"; } else { echo "</td><td>","0","</tr>\n"; } } while ($num_rows<=16) { echo "</td><td>","","</tr>"; $num_rows++; } echo "</td><td>","$totalpts","</tr>"; $totalpts=0; $w++; $i++; } echo "</table>\n"; mysql_close($con); Thanks! |