PHP - Sorting Through Multiple Arrays...i Think?
I have a table called members. Each member located within the members table has a unique id field called ID
I have a second table called user_program in which also contains the id number of the member from the members table Each member has 5 entries in the table user_program using the field called program_id which has a value of either 1, 2, 3, 4 or 5 Additionally there is a user_status field within the same user_program table The value of user_status is either Active, Comped, Temp-Comped or Unpaid What I am trying to do is determine is which is the highest program_id that a specific member holds a user_status equal to Active and then assign the program_id to a variable. Here is the structure of the user_program table user_program_id program_id user_status auto incrementing number 1 Active auto incrementing number 2 Active auto incrementing number 3 Unpaid auto incrementing number 4 Unpaid auto incrementing number 5 Unpaid Here is the code I have been working with trying to figure it out.....any help would be appreciate :-) Code: [Select] $r1 = mysql_query("SELECT * FROM members WHERE Username='".$_SESSION['loggedin']."'"); $buffer_r1 = mysql_fetch_assoc($r1); $usrid = $buffer_r1['ID']; $r2 = mysql_query("SELECT * FROM user_program WHERE ID='".$usrid."'"); $buffer_r2 = mysql_fetch_assoc($r2); $level_id = $buffer_r2['program_id']; $user_status = $buffer_r2['user_status']; $grace_start = $buffer_r2['grace_start']; while(!$user_status ==("Comped" || "Unpaid")){ if($level_id == "1" && ($user_status == "Active")){ $level_name = "Professional"; }elseif($level_id == "2" && ($user_status == "Active")){ $level_name = "Gold"; }elseif($level_id == "3" && ($user_status == "Active")){ $level_name = "Diamond"; }elseif($level_id == "4" && ($user_status == "Active")){ $level_name = "Platinum"; }elseif($level_id == "5" && ($user_status == "Active")){ $level_name = "Elite"; } } I know the code within the while state is correct to assign the end variable, but my problem is that its only looking at the first program_id returned from the database that matches the user ID and does loop through the rest of the entries for that person. Thanks in advance :-) Similar TutorialsHello,
I've been struggling to get array_multisort to work...
If I have this array output...
I'd like to sort on the product sub-array.
The array is called orders and that number 15 is the specific order id.
Array ( [15] => Array ( [clientId] => 1 [clientName] => Bob [o_date] => 2014-01-02 [o_number] => 1 july-append [o_notes] => order on 1 july-append [i_date] => 2014-01-17 [i_number] => 18072014-append [i_notes] => invoiced on 18 july 14 -append [products] => Array ( [0] => Array ( [id] => 37 [prod_id] => 1 [product] => door [qty] => 2 [cost] => 12.121 ) [1] => Array ( [id] => 38 [prod_id] => 2 [product] => window [qty] => 3 [cost] => 22.5 ) [2] => Array ( [id] => 36 [prod_id] => 3 [product] => chair [qty] => 1 [cost] => 300 ) ) ) )So, I've tried a number of variations of this... array_multisort($orders[$theOrder]['products'], SORT_DESC, SORT_NUMERIC, $orders[$theOrder]['products'], SORT_ASC, SORT_STRING); array_multisort($orders[$theOrder]['products']['id'], SORT_DESC, SORT_NUMERIC);etc. etc. - but I seem to get no-where. Can some-one kindly point out my error, please? Thank you. Hi everyone I have 2 queries which are pulling out results into arrays I think they are right I then insert a new column into each array one with [typeofdonation] as "cash" and one as "card" this is to be used later when outputting the results I then need to combine the 2 arrays into 1 array and then sort the combined array by date showing the latest ones first I then need to output the top 3 results The way the results are outputted is dependant on what [typeofdonation] is as they are outputting and styled differently Here is my code below I have got upto the combining the 2 arrays but am having difficulty doing this Once I have done this I then need to sort the results but I think my code I have tested on each array works ok and so will work once I have the combined array. Final part I am not sure on how to find and use what is in [typeofdonation] to determine the styling and way each of the 3 results is outputted Thankyou in advance for everyone who can hopefully help me in the right direction Peter Code: [Select] <b>Card Donations</b><br><br> <?php $getcarddonations = $wpdb->get_results("SELECT wp_supporters_donations.SFMemberNumber, wp_supporters_donations.KickbackAmount, wp_supporters_donations.MerchantName, wp_supporters_donations.SpendDate from supporter_2_cause RIGHT JOIN wp_supporters_donations ON supporter_2_cause.supp_id=wp_supporters_donations.SFMemberNumber WHERE supporter_2_cause.caus_id = '54' ORDER BY wp_supporters_donations.SpendDate"); //UNION SELECT id, amout, cause, date FROM cashdepo WHERE cause='Lisas charity' AND status='2' ORDER BY id DESC foreach($getcarddonations as $getcarddonations){ $i = 0; while($i < 100) { $data[$i]['member'] = $getcarddonations->SFMemberNumber; $data[$i]['ammount'] = $getcarddonations->KickbackAmount; $data[$i]['merchant'] = $getcarddonations->MerchantName; $data[$i]['date'] = $getcarddonations->SpendDate; $data[$i]['typeofdonation'] = 'card'; $i++; } } function compareItems($a, $b) { if ( $a->date < $b->date ) return -1; if ( $a->date > $b->date ) return 1; return 0; // equality } uasort($data, "compareItems"); print_r( $data ); ?> <br><br><br><b>Cash Donations</b><br><br> <?php $getcashdonationsdb = $wpdb->get_results("SELECT * FROM cashdepo WHERE cause='Lisas charity' AND status='2' ORDER BY id DESC"); foreach($getcashdonationsdb as $getcashdonationsdb){ $i = 0; while($i < 11) { $dataa[$i]['member'] = $getcashdonationsdb->id; $dataa[$i]['ammount'] = $getcashdonationsdb->amout; $dataa[$i]['merchant'] = $getcashdonationsdb->cause; $dataa[$i]['date'] = $getcashdonationsdb->date; $dataa[$i]['typeofdonation'] = 'cash'; $i++; } } uasort($dataa, "compareItems"); print_r( $dataa ); ?> <br><br><br> <b>Combined</b><br><br> <?php $datar1 = ($data); $datar2 = ($dataa); $finalarray = array_combine($datar1, $datar2); //sort uasort($finalarray, "date"); //Print the output print_r($finalarray); ?> I am having trouble with a small PHP program. I have to load item and amount data from table cells into an array, and then be able to sort and reverse sort the items in the cells. I also have to track the errors when non-numeric data is entered a s an amount, and total the numeric amounts (These parts I think I have coded correctly.). I am having trouble with the array part. I don't think item values are being loaded into the array. I debugged it as much as I could. My code is here-- http://pastie.org/1084621 . I am completely new to this, having only done little PHP/JavaScript programs like this for some classes in the last few months. Any help would be greatly appreciated. I have code that queries two tables for example... Code: [Select] $checkfordue = mysql_query("SELECT stuID FROM ".$conf['tbl']['homework']." , ".$conf['tbl']['homeworktable']." WHERE ".$conf['tbl']['homework'].".TID = '$newID' && ".$conf['tbl']['homeworktable'].".TID = '$newID' && ".$conf['tbl']['homeworktable'].".ID = '$ID' && ".$conf['tbl']['homework'].".turnin = '2' && ".$conf['tbl']['homework'].".homeworkID = ".$conf['tbl']['homeworktable'].".ID ORDER BY stufirstname, stulastname"); WHILE($checkdue = mysql_fetch_array($checkfordue)) {etcAnd the above code has been working fine. The question really is about using JOIN instead of what I did. And if you could please explain join left as well. What are the benefits of using join rather then writing the query like I did. I am very grateful for any input. I have a field in a database that contains references (pattern: authorYYYY), such as the following string:
"authorA1989; authorB1978a; authorB1984; authorC1999; authorC2000a; authorC2000b; authorC2002; authorD2009"
What I want is an output as the following in order to create a proper bibliography (therefore accessing another table and picking out the respective reference details):
authorA
1989
authorB
1978a
1984
authorC
1999
2000a
2000b
2002
authorD
2009
I somewhat fail to group the values (years) per author. I know that keys are unique, but is there a way to work around this?
Many thanks for any help!
hello guys moving on from inserting multiple records im now stuck with updating multiple records. i can get most of the details nailed but i need it to match the id's for the table the code i have in the sql part are Code: [Select] if (isset($_POST['submit'])) { //Assign each array to a variable $StaffMember = $_POST['StaffMember']; $referrer = $_POST['referrer']; $referred = $_POST['referred']; $SentOut = $_POST['SentOut']; $today = date("y.m.d H:i:s"); $user_id = $_SESSION['user_id']; $IssueNum = $_POST['Referrerid']; $limit = count($StaffMember); $values = array(); // initialize an empty array to hold the values for($k=0;$k<$limit;$k++){ $msg[] = "$limit New KPI's Added"; $values[$k] = "( '{$StaffMember[$k]}', '{$referrer[$k]}', '{$referred[$k]}', '{$SentOut[$k]}', '{$today}', '{$user_id}' )"; // build the array of values for the query string } $query = "UPDATE `Referrer` (StaffMember, referer, referred, SentOut, SentOutDate, SentOutBy) VALUES " . implode( ', ', $values ) . " WHERE IssueNum= '{$IssueNum[$k]}'"; echo $query; } i obviously want the records updating where the issuenumber is the same and if the check box in the form is ticked help with this one? Let me explain my problem. I have an array with dates and numbers in format ($cronograma) Ex: Array ( [2020-09-21] => Array ( [0] => 2020-09-21 [1] => 2 [2] => 2 [3] => 2 ) [2020-09-28] => Array ( [0] => 2020-09-28 [1] => 2 [2] => 2 [3] => 4 ) Then i have another array with 2 ids (in this case 58,60) ($id) Finally i have a third array with numbers only (in this case 34,34) $tot So what i want is cross information beween them, for example for id 58 I must get dates (first element and last element when $tot = 34) for id 60 I must get dates (first element after $tot =34 and last element of array) Whath i have so far is this foreach ($id as $idPlan) { foreach ($cronograma as $c) { $t1 = 0; foreach ($tot as $d) { $t1 += (int)$d['tempos']; if ($c[3] == $t1) { $newAr[] =$idPlan; $newAr[] = $c[0]; } } } } My response array(8) { [0]=> string(2) "58" [1]=> string(10) "2021-02-01" [2]=> string(2) "58" [3]=> string(10) "2021-06-14" [4]=> string(2) "60" [5]=> string(10) "2021-02-01" [6]=> string(2) "60" [7]=> string(10) "2021-06-14" } null So it's clear that i have all repeated I should have a line like: 58 - 2020-09-21 -2021-02-01 Any help? In my form I have this: Code: [Select] <div class="confSub {conferences.confClass}"> <div> <input type="hidden" name="confPK" value="{conferences.confPK}"> <label>Conference Attended:</label><input size="85" name="conference[{conferences.confCounter}]" type="text" value="{conferences.conference}"/> <label>Date:</label><input size="20" name="confDate[{conferences.confCounter}]" type="text" value="{conferences.confDate}"/> <span class="example left"> ( YYYY-MM-DD )</span> <label class="fullLabel clearfix">Description and Benefit to the University:</label> <textarea name="confDesc[{conferences.confCounter}]" cols="90" rows="5">{conferences.confDesc}</textarea> <input class="checkbox clearfix" name="confPres[{conferences.confCounter}]" value="yes" type="checkbox" {conferences.checkedConf}/> <label class="midLabel">Conference Presentation?</label> <label class="clearfix">Title of Presentation:</label> <input class="pushLeft" size="85" name="confPresTitle[{conferences.confCounter}]" type="text" value="{conferences.ConfPresTitle}"/> </div> </div> I need to take the values of the same index for eachof five arrays ($_POST['conference'], $_POST['confDate'], $_POST['confDesc'], etc...) and insert/update them into a mysql table. So conference[0], confDate[0], confDesc[0], confPres[0], and confPresTitle[0] all need to go into the same index of their respective fields in the DB table. If it was one array I could just do something like: foreach($_POST['conference'] as $conference) { // Update Conference $degreeQuery = "UPDATE CONFERENCES SET Conference = '".$conference."', StaffPK1 = '".$getPK1."' WHERE ConferencePK1 ='".$confID."'"; $degreeQuery = mysql_query($degreeQuery); } I'm having trouble with how to add a value from each array into the sql table. I could do it through a different foreach loop for each array and iterate through all foreach loops with another loop, but that doesn't seem very efficient. I'd like to do it with one sql statement for each set of "conference" data. Thanks in advance, Shannon I have a really confusing question. I dynamically generate arrays, but for the simplicity of the example we can just use two arrays. Code: [Select] Array 1 ( [0] = 1 [1] = 5 ) Array 2 ( [0] = 2 [1] = 6 ) How can I make the arrays multiple based on the same key value? array 1[0] * array 2[0] = 2 array 1[1] * array 2[1] = 30 I then want to sum the total of the multiplication. $total = 2 + 30; I need to do this to calculate covariance for a statistics procedure I am trying to run but I can't wrap my head around how to do the logic. As the title says, how can i check if multiple arrays exist inside an array or not? Any help is greatly appreciated!
I am attempting to submit a form that includes multiple check boxes for one data field. I have set it up the implode the data and make it a comma delimited array. I am able to echo the results, yet I have not been able to post the information to the database. I believe that I have just one simple thig to do, yet I am not being successful. Here is my code I have attached the .txt file also: <?php require_once('Connections/rotarysantarosa.php'); ?> <?php if (isset($_POST['submit'])) { if (isset($_POST['currentClubPosition'])) { $strcurrentClubPosition = implode(",", $_POST['currentClubPosition']); } else { $strcurrentClubPosition = ""; } } ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "frmMemberInsert")) { $insertSQL = sprintf("INSERT INTO members (firstName, lastName, photo, pastPresident, currentClubPosition, classification, workPosition, company, workAddress, workCity, workState, workZip, officePhone, fax, homePhone, cellPhone, email, website, homeAddress, homeCity, homeState, homeZip, birthdayMonth, birthdayDay, spouse, yearJoined) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['photo'], "text"), GetSQLValueString($_POST['pastPresident'], "text"), GetSQLValueString($_POST['currentClubPosition'], "text"), GetSQLValueString($_POST['classification'], "text"), GetSQLValueString($_POST['workPosition'], "text"), GetSQLValueString($_POST['company'], "text"), GetSQLValueString($_POST['workAddress'], "text"), GetSQLValueString($_POST['workCity'], "text"), GetSQLValueString($_POST['workState'], "text"), GetSQLValueString($_POST['workZip'], "text"), GetSQLValueString($_POST['officePhone'], "text"), GetSQLValueString($_POST['fax'], "text"), GetSQLValueString($_POST['homePhone'], "text"), GetSQLValueString($_POST['cellPhone'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['website'], "text"), GetSQLValueString($_POST['homeAddress'], "text"), GetSQLValueString($_POST['homeCity'], "text"), GetSQLValueString($_POST['homeState'], "text"), GetSQLValueString($_POST['homeZip'], "text"), GetSQLValueString($_POST['birthdayMonth'], "text"), GetSQLValueString($_POST['birthdayDay'], "int"), GetSQLValueString($_POST['spouse'], "text"), GetSQLValueString($_POST['yearJoined'], "int")); mysql_select_db($database_rotarysantarosa, $rotarysantarosa); $Result1 = mysql_query($insertSQL, $rotarysantarosa) or die(mysql_error()); $insertGoTo = "members.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_rotarysantarosa, $rotarysantarosa); $query_rsStates = "SELECT * FROM states ORDER BY stateName ASC"; $rsStates = mysql_query($query_rsStates, $rotarysantarosa) or die(mysql_error()); $row_rsStates = mysql_fetch_assoc($rsStates); $totalRows_rsStates = mysql_num_rows($rsStates); mysql_select_db($database_rotarysantarosa, $rotarysantarosa); $query_rsMemberInsert = "SELECT * FROM members ORDER BY lastName ASC"; $rsMemberInsert = mysql_query($query_rsMemberInsert, $rotarysantarosa) or die(mysql_error()); $row_rsMemberInsert = mysql_fetch_assoc($rsMemberInsert); $totalRows_rsMemberInsert = mysql_num_rows($rsMemberInsert); mysql_select_db($database_rotarysantarosa, $rotarysantarosa); $query_rsClubPosition = "SELECT * FROM clubpositions ORDER BY `Club Position` ASC"; $rsClubPosition = mysql_query($query_rsClubPosition, $rotarysantarosa) or die(mysql_error()); $row_rsClubPosition = mysql_fetch_assoc($rsClubPosition); $totalRows_rsClubPosition = mysql_num_rows($rsClubPosition); mysql_select_db($database_rotarysantarosa, $rotarysantarosa); $query_rsClassification = "SELECT * FROM classifications ORDER BY Classification ASC"; $rsClassification = mysql_query($query_rsClassification, $rotarysantarosa) or die(mysql_error()); $row_rsClassification = mysql_fetch_assoc($rsClassification); $totalRows_rsClassification = mysql_num_rows($rsClassification); mysql_select_db($database_rotarysantarosa, $rotarysantarosa); $query_rsBirthMonth = "SELECT * FROM birthdaymonth"; $rsBirthMonth = mysql_query($query_rsBirthMonth, $rotarysantarosa) or die(mysql_error()); $row_rsBirthMonth = mysql_fetch_assoc($rsBirthMonth); $totalRows_rsBirthMonth = mysql_num_rows($rsBirthMonth); mysql_select_db($database_rotarysantarosa, $rotarysantarosa); $query_rsBirthDay = "SELECT * FROM birthdayday ORDER BY birthdayday ASC"; $rsBirthDay = mysql_query($query_rsBirthDay, $rotarysantarosa) or die(mysql_error()); $row_rsBirthDay = mysql_fetch_assoc($rsBirthDay); $totalRows_rsBirthDay = mysql_num_rows($rsBirthDay); ?> I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? 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. 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 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 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 |