PHP - How To Retrieve The Highest Score From A Set Of Array Values Of A 2d Array.
I have mysql select query shown below retrieving data from a database:
$sql = " SELECT student, sum( test_score ) as score FROM test INNER JOIN level ON test.level_id = level.level_id GROUP BY student" $result = $mysqli->query($sql, MYSQLI_STORE_RESULT); if($result) { while ($row = $result->fetch_array(MYSQLI_ASSOC)) { var_dump($row); } }On inspection of the retrieved array with var_dump(), i have these result below: array (size=2) 'John' => string 'English' (length=2) 'Score' => string '20' (length=3) array (size=2) 'Mary' => string 'Math' (length=3) 'Score' => string '35' (length=3) array (size=2) 'Samuel' => string 'Physics' (length=3) 'Score' => string '5' (length=3)How do I get at and print out the highest score from this set of array values within this context. I tried this echo max($row['count']) but i understandably got this feedback: Warning: max(): When only one parameter is given, it must be an array Thanks. Similar Tutorials(1) I need to remove the lowest and higest values from an array. I need to actually remove the two lowest and two highest. I suppose the best thing would be to sort the array and then use a function that just drops the first and last values (twice). Is this the best way? Which function would drop the lowest / highest values? (2) I then need to get the remaining first and last (highest and lowest) values. $array[0] would get first, and revesing the order and $array[0] again would get the last. Is this the best way? I am trying to iterate through a 3 dimensional array and echo out all the details. I am having a trouble with the following: Array ( [DT_Intrinsic_mob7] => Array ( [0] => Array ( [cli] => 11111111111 [min] => 533 ) [1] => Array ( [cli] => 2222222222 [min] => 536 ) [2] => Array ( [cli] => 33333333333 [min] => 541 ) ------- SNIP ----- [46] => Array ( [cli] => 5555555555 [min] => 5471 ) ) [DT_belltel_mob7] => Array ( [0] => Array ( [cli] => 999999999 [min] => 508 ) [1] => Array ( [cli] => 8888888888 [min] => 519 ) [2] => Array ( [cli] => 7777777777 [min] => 602 ) [3] => Array ( [cli] => 7975757375 [min] => 701 ) ) ) My code looks like this: foreach ($cli_data as $key => $value){ foreach ($cli_data[$key] as $key2 => $value2){ foreach($cli_data[$key][$key2] as $key3 => $value3){ echo "key3 is $key3 \n"; echo "value is $value3['cli']"; } } echo "\n\n"; } I keep getting the following error PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/index.php on line Thanks To generate the stockroom drop down list function einv_generateStockrmSelectDropdown($Stockrm,$field,$dropdown) { //connect to database base_connectDatabase(); echo "<select id=\"stockrm\" name=\"".$field."[]\" multiple=\"multiple\" style=\"align:left\" class=\"form-control\">"; if (isset($Stockrm) && ($Stockrm != "")) { $stockrmname = einv_getStockrmDetail($Stockrm); echo "<option value=\"". $Stockrm ."\">". $stockrmname['einv_stockrm_name'] ."</option>"; } else { $Stockrm = 0; } $getStockrmSQL = base_executeSQL("SELECT * FROM einv_stockroom WHERE einv_stockrm_id<>" . $Stockrm . " ORDER BY einv_stockrm_name"); while ($Stockrmdata_row = base_fetch_array($getStockrmSQL)) { if (base_num_rows($getStockrmSQL)!= 0) { echo "<option value=\"".$Stockrmdata_row['einv_stockrm_id']."\">".$Stockrmdata_row['einv_stockrm_name']."</option>"; } } echo "</select>"; echo "<script src=\"../terms_base/js/jquery.multiple.select.js\"></script>"; //Input some codes to split the dropdown and make it into the setSelects. By default, the first time = AutoSelectAll if(isset($dropdown) && ($dropdown != "")) { //dropdown = 1;2;3 $SDDArrays = explode(";", $dropdown); $countTrap0 = count($SDDArrays); $drop = "$('#stockrm').multipleSelect(\"setSelects\", ["; $counting = 1; foreach ($SDDArrays as &$value) { if ($countTrap0 != $counting) { $drop .= "'". $value . "',"; } else { $drop .= "'". $value . "'"; } $counting++; } $drop .= "]);\n"; } elseif (isset($dropdown)) { //dropdown= $drop = "$('#stockrm').multipleSelect(\"uncheckAll\")"; } else { // $drop = "$('#stockrm').multipleSelect(\"checkAll\")"; } echo "<script>\n"; echo "$(function() {\n"; echo "".$drop.""; echo "});\n"; echo "$(\"#stockrm\").multipleSelect({ onClose: function() { document.getElementById('search').click(); }});\n"; echo "$(\"#stockrm\").multipleSelect();\n"; echo "</script>"; //close the database base_closeDatabase(); }add stockroom function //This function is use to add new stock room //code = stock room code //name = stock room name //desc = stock room description //remark = stock room remark //cat = stock room category function einv_addStockrm($code,$name,$desc,$remark,$cat) { //connect to database base_connectDatabase(); $User = base_getUserDetail($_SESSION['uID']); base_executeSQL("INSERT INTO einv_stockroom (einv_stockrm_code, einv_stockrm_name, einv_stockrm_desc, einv_stockrm_remark, einv_stockrm_cat) VALUES ('" . $code . "', '" . $name . "', '" . $desc . "', '" . $remark . "', '" . $cat . "')"); base_addTransactionLog('Manage Stock Room', 'Add', " Stock Room Code = " . $code . " || Stock Room Name = " . $name . " || Stock Room Description = " . $desc . " || Stock Room Remark = " . $remark . " || Stock Room Category = " . $cat . " "); //go to stock room page echo '<script type="text/javascript">' . "\n"; echo 'window.location="../einventory/stockrm_list.php";'; echo '</script>'; //close the database base_closeDatabase(); } Edit stockroom function einv_editStockrm($srid,$code,$name,$desc,$remark,$cat) { //connect to database base_connectDatabase(); $User = base_getUserDetail($_SESSION['uID']); $Stockroom = einv_getStockrmDetail($srid); base_executeSQL("UPDATE einv_stockroom SET einv_stockrm_code='" . $code . "', einv_stockrm_name='" . $name . "', einv_stockrm_desc='" . $desc . "', einv_stockrm_remark='" . $remark . "', einv_stockrm_cat = '" . $cat . "' WHERE einv_stockrm_id=" . $srid . ""); base_addTransactionLog('Manage Stock Room', 'Edit', " Stock Room Code = " . $code . " || Stock Room Name = " . $name . " || Stock Room Description = " . $desc . " || Stock Room Remark = " . $remark . " || Stock Room Category = " . $cat . " "); //go to stock room page echo '<script type="text/javascript">' . "\n"; echo 'window.location="../einventory/view_stockrm.php?id='. $srid .'";'; echo '</script>'; //close the database base_closeDatabase(); } I have a dropdown list named **Stockroom** where it displays an array of values. Example: **Stockroom** 1. [A] 2. [b] 3. [C] When user clicks on [A], it will display relevant data fields that [A] possess (appears below stockroom ddl). And as user clicks on [b], there is an onchange function that will then show [b] data fields (fields in A is deleted and replaced with B). I am able to add the initial values however, as i want to edit and change the stockroom from [A] to [b] which will result in a whole new data to be stored, i am unable to do so. Any ideas? I believe i have to amend my edit stockroom function where i require a set of coding such as If the array is selected, i have to delete existing data and add new data in accordance to the selected ID. Edited by mac_gyver, 14 January 2015 - 07:05 AM. code tags around posted code please Hi all I have some code that displays the high scores for a game. Unfortunately, if a user has more than 1 high score in the table all scores for that user are displayed. I would like to only display the highest score per user. My Current Code Code: [Select] $sql_query = sprintf("SELECT * FROM `highscores` WHERE `gameID` = '106' ORDER BY `score` DESC"); //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { //output as long as there are still available fields while($row = mysql_fetch_row($result)) { echo ("$row[3] Scored :$row[5] <br>"); } } //if no fields exist else { echo "no values in the database"; } mysql_close($con); OutPut User1 300 User1 298 User 2 297 User1 296 User3 295 User2 290 I would like the output to be User1 300 User 2 297 User3 295 Any help is much appreciated Hi folks, i have a complex problem (for me anyway) but i am sure with your help this can be sorted. Problem number 1: I have a simple while loop, but its only showing 4 results when i know there are 5 I am missing something very simple i know: $sql = ("SELECT * FROM postcode WHERE unid='1'")or die ('<p>There seems to be a problem, please try again soon.</p>'); $result = mysql_query($sql,$con); $row = @mysql_fetch_array($result); $i=0; while ($row = @mysql_fetch_assoc($result)){ echo "newpoints[". $i++ ."] = new Array({$row['lat']}, {$row['long']}, icon0, '{$row['postcodename']}', '{$row['postcodename']}'); \n"; } What am i missing here? Problem number 2: I have a bunch of latitude and longitude codes stored in the database. On each page there will be a varied amount of these codes used, but with a max of 20. I need to find the highest number and the lowest number of each lat and long then come up with a code that is in the middle, the idea of this is to center a map. So for example there will be an array like this: 50.852293 -1.76088 51.252938 -0.76128 51.259583 -0.727168 51.274 -0.837 51.123106 -0.970657 First i need to find the highest number of the first code (51.274) then the lowest number (50.852293) and then the highest number of the second code (-1.76088) then the lowest number (-0.727168) Then work out an inbetween code using the highest and lowest codes for each. Does anyone have a clue how to go about this? I am not the worlds best array technition or mathematician I currently have an array that I've built that dumps like this:
0 => array:11 [▼ "category_code" => "123" "category_name" => "Testing" "category_description" => "This is a test category" 19738 => array:5 [▼ "identifier" => "720368842943" "description" => Test Description One "count" => 4 "details" => array:2 [▼ 0 => array:3 [▼ "detail_code" => "2751" "detail_code2" => "43" "detail_specifier" => "Detail One" ] 1 => array:3 [▼ "detail_code" => "2681" "detail_code2" => "9" "detail_specifier" => "Detail Two" ] ] "prices" => array:1 [▼ "01" => "1129.00" ] ] 19739 => array:5 [▼ "identifier" => "720368844121" "description" => "Test Description Two" "count" => 4 "details" => array:2 [▼ 0 => array:3 [▼ "detail_code" => "2751" "detail_code2" => "43" "detail_specifier" => "Detail One" ] 1 => array:3 [▼ "detail_code" => "2681" "detail_code2" => "9" "detail_specifier" => "Detail Two" ] ] "prices" => array:1 [▼ "01" => "1490.00" ] ] I'm using laravel excel in order to export that as an excel file, but it's not quite working the way I intend When it exports to excel I only get the top level info: 123 | Testing | This is a test category But I want to get that info as a header and then each subsequent product for that category as a row, so with the example above it would look like:
123 | Testing | This is a test category Here's the excel code with the array I'm using, which is dumped above: $allCategoryResult= array(); foreach($prices->categories as $category){ $categoryItem = array(); $categoryItem["category_code"] = $category->category_code; $categoryItem["category_name"] = $category->category_name; $categoryItem["category_desc"] = $category->category_desc; foreach($category->skus as $sku){ $skuItem = array(); $skuItem["identifier"] = $sku->sku_info->identifier; $skuItem["description"] = $sku->sku_info->item->description; $skuItem["count"] = $sku->sku_info->item->item_type->count; $skuItem["details"] = array(); foreach ($sku->sku_info->details as $details) { $detailsItem = array(); $detailsItem["detail_code"] = $details->detail_code; $detailsItem["detail_code2"] = $details->detail_code2; $detailsItem["detail_specifier"] = $details->detail_specifier; $skuItem["details"][] = $detailsItem; } $skuItem["prices"] = get_object_vars($sku->prices); $itemCode = $sku->sku_info->item->item_code; $categoryItem[$itemCode] = $skuItem; } $allCategoryResult[] = $categoryItem; } $name = 'Test Export'; $build = Excel::create($name, function ($excel) use ($allCategoryResult) { $excel->setTitle('Test Export'); $excel->sheet('Test Export', function ($sheet) use ($allCategoryResult) { $sheet->fromArray($allCategoryResult);
Hi there, Basic question, but I can't seem to find a page in the PHP docs that answers (though I'm sure such a one exists, I just can't seem to think up the right search terms - anyway) My question is: is there a short-hand way to use a value from an associative array as the key in another associative array? So for example, given this array: $the_array = array(0 => array('name': 'the_name', 'value' : 'the_value'), 1 => etc....); then this kind of foreach loop doesn't work Code: [Select] $new_data = array(); foreach($the_array as $element){ $new_data[$element['name']] = $element['value']; } Obviously I can just save out the values, like $name = $element['name'] --- but I was just wondering if there was a more efficient way to do it? Cheers, PS. I tried encapsulating with {} - i.e. $new_data[{$element['name']}] --- but that also fails. Hello all, I have yet again trouble finding a logical solution to my problem. I'm fetching an array which can hold 1 or more values. The problem is, I want these values to ouput in my json_encode function, but this also needs to happen dynamically depending on the amount of values. I can't explain it further, so here's the code so far: Code: (php) [Select] $files = mysql_fetch_array($get_files); $a = count($files); $i = 1; while ($files) { $variablename = 'fileName' . $i; $$variablename = $files['fileName']; $i++; } $output = array( OTHER VALUES , 'fileName1' => $fileName1, 'fileName2' => $fileName2, 'fileName3' => $fileName3, ............); // How do I add the fileNames dynamically depending on how many there are? This got me thinking, I also need to dynamically GET the values with jQuery. How would I do that, when the above eventually works? Thank you. I need to some how pull comma separated images $data[23] from this $data array and then put them into there own array so I can insert them into separate rows in a database. This is the provided array: $data[0] => VIN $data[1] => StockNumber ...(all the other number here) $data[23] => Image_URLs (comma seperated) $data[24] => Equipment // I need something like this (obviously doesn't work?!@#) $delimiter = ","; $img = explode($delimiter, $data[23]); foreach($img as $pic){ $sqlPic = "insert into class_prodimages (pid image rank) values('".$LastId['id']."', '$pic', '".rand(1,20)."')"; } Any help here? I have the following array structu Code: [Select] [0] => Array ( [id] => Array ( [$t] => http://www.google.com/mate/ ) [updated] => Array ( [$t] => 2011-08-31T11:43:05.942Z ) [category] => Array ( [0] => Array ( [scheme] => http://schemas.google.com/g/ [term] => http://schemas.google.com/contact/ ) ) [title] => Array ( [type] => text [$t] => Name ) [link] => Array ( [0] => Array ( [rel] => http://schemas.google.com/contacts/2008/rel#edit-photo [type] => image/* [href] => https://www.google.com/mate/feeds/photos/media/ ) [1] => Array ( [rel] => self [type] => application/atom+xml [href] => https://www.google.com/mate/feeds/contacts ) [2] => Array ( [rel] => edit [type] => application/atom+xml [href] => https://www.google.com/mate/feeds/ ) ) [gd$email] => Array ( [0] => Array ( [rel] => http://schemas.google.com/g/2005#other [address] => email_address@gmail.com [primary] => true ) ) ) I am tried to display name and email address. I am using following method, can anyone tell me is there any better way? Thank u 4u help. NAME $name=( $emp_det[0]['title'][t]); $email =( $emp_det[0]['gdemail'][0][address]); I have an array created to control the down states of the my buttons in my navigation. Which is working well. This array will have quite a few strings in it before I'm done. I then want to conditionally load a CSS file for all the files in that array with the exception of two, is this possible? In plain in english I want to say If in array apart from these values then load my css file. My array (will have more values when complete) Code: [Select] $otherTitles = array('Product Selector', 'Avon Range', 'Knightsbridge Range', 'Kingston Range' ); My code to load a css file Code: [Select] <?php if (in_array($title, $otherTitles)) { ?> <link rel="stylesheet" type="text/css" href="homepage.css"/> <?php } ?> I want all titles in the otherTitles array to get this CSS file apart from two Product Selector and Avon Range. Thanks Richard Hello there again!
I have the following construct of array now (schematics):
array[0] array[id] = "1" array[title] = "title" array[1] array[id] = "3" array[title] = "another title"Now what i want to do, is to assign the parent-array keys to the IDs of it's contents. This is what it should look like: array[1] array[id] = "1" array[title] = "title" array[3] array[id] = "3" array[title] = "another title"How do I do that again? I know I did this some years ago, but I can not remember how. Hello, im new here, and i have little experience to php and mysql as i started for 2 weeks ago. I started out with some tutorials and feeling im getting the hang of it. Enough of me, lets get to the point: <?php $con = mysql_connect('localhost',$user,$pass)or die(mysql_error()); $selectdb = mysql_select_db($selectdb)or die(mysql_error()); $sql = "SELECT * From table"; $result = mysql_query($sql); $num = mysql_num_rows($result); $myarray = array($result); $i =0; while ($i < $num){ echo $myarray[$i]; $i++; } ?> Here i have written a dummyscript that does what the original script does, it tries to fetch the keys from the table and then trying to loop it and echo out the results. The output in the browser is this: Resource id #3 I know this probably is a simple fix but i cant seem to get it sorted out. Hope some of you could help me get this baby work, or maybe have another way of doing it more "simple". Thanks in advance! Dan-Levi Hi all, I'm a first time poster here and I would really appreciate some guidance with my latest php challenge! I've spent the entire day googling and reading and to be honest I think I'm really over my head and need the assistance of someone experienced to advise the best way to go! I have a multi dimensional array that looks like (see below); the array is created by CodeIgniter's database library (the rows returned from a select query) but I think this is a generic PHP question as opposed to having anything to do with CI because it related to working with arrays. I'm wondering how I might go about searching the array below for the key problem_id and a value equal to a variable which I would provide. Then, when it finds an array with a the matching key and variable, it outputs the other values in that part of the array too. For example, using the sample data below. How would you recommend that I search the array for all the arrays that have the key problem_id and the value 3 and then have it output the value of the key problem_update_date and the value of the key problem_update_text. Then keep searching to find the next occurrence? Thanks in advance, as above, I've been searching really hard for the answer and believe i'm over my head! Output of print_r($updates); CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 5 [row_data] => ) Output of print_r($updates->result_array()); Array ( [0] => Array ( [problem_update_id] => 1 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Some details about a paricular issue [problem_update_active] => 1 ) [1] => Array ( [problem_update_id] => 4 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Another update about the problem with an ID of 3 [problem_update_active] => 1 ) [2] => Array ( [problem_update_id] => 5 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of four [problem_update_active] => 1 ) [3] => Array ( [problem_update_id] => 6 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of 6 [problem_update_active] => 1 ) [4] => Array ( [problem_update_id] => 7 [problem_id] => 3 [problem_update_date] => 2010-10-12 [problem_update_text] => Some new update about the problem with the ID of 3 [problem_update_active] => 1 ) ) I'm trying to split a url into segments so that a url would be stored in an array. Example: A url like this http://localhost/application/blog/view/Test-Blog-Entry/1 Would look like this in an array: Code: [Select] array('blog', 'post', 'Test-Blog-Entry', '1'); It's an MVC url so 'blog' would be controller, 'post', would be method and the last two would be variables. I want to display the variable values of the array. Is there an easy way to do this? Basically I am pulling data from an XML feed on wowarmory.com Everything is working as far as getting the item names and even a list of the item levels. What I am trying to do now is add together all of the item levels in to one value that I will call $calc (I will then divide this by 16 to find the average item level). I am using a foreach loop to echo the Item Name and it's corresponding item level. I am now trying to grab the item level on each loop so I can add them all up and store them in $calc for further manipulation outside of the loop. I am a complete novice but learning, How would I go about achieving this? Of course the code I have atm is re-defining $calc every loop, so naturally it isn't working. Here is my current code: //Get the UID for each item the character has //Then look up the name for that item foreach($char_xml->characterInfo->characterTab->items->item as $item) { //get the item id $item_id = $item->attributes()->id; //get the xml doc for that item from wow armory $url = "http://www.wowarmory.com/item-info.xml?i=" . $item_id; $data = fetchXML($url); //create a SimpleXML object to parse the xml $item_xml = new SimpleXmlElement($data); //print the item's name echo "<b> Item Name: </b>" . $item_xml->itemInfo->item->attributes()->name . "</br>"; echo "<b><i> iLvL: </i></b>" . $item_xml->itemInfo->item->attributes()->level . "</br>"; //obviously this is wrong, because It is redefining $calc every loop $calc=$item_xml->itemInfo->item->attributes()->level; } //print the total item level echo $calc; I am working in wordpress and things are going good. I made a form, filled it with values and have been able to store those values in a database using a wordpress function. Now my issue is that I want learn how to write them into an array and store them that way. I have been looking at several different ways but can't figure out how to code it. This is my code now Code: [Select] function add_slider_box(){ global $post; $imageurl = get_post_meta( $post->ID, 'imageurl', true ); $imagelink = get_post_meta( $post->ID, 'imagelink', true ); $imagecap = get_post_meta( $post->ID, 'imagecap', true ); ?> <div style="width: 50%" class="sliderbox"> <p><label for="imageurl">Image Url: <br /> <input type="text" class="widefat" id="imageurl" name="imageurl" value="<?php if( $imageurl ) { echo $imageurl; } ?>" /></label></p> <p><label for="imagelink">Image Link: <br /> <input type="text" class="widefat" id="imagelink" name="imagelink" value="<?php if($imagelink) { echo $imagelink; }?>" /></label></p> <p><label for="imagecap">Image Caption: <br /> <input type="text" class="widefat" id="imagecap" name="imagecap" value="<?php if( $imagecap ) { echo $imagecap; } ?>" /></label></p> <button class="remove_slide button-secondary">Remove This Slide</button> </div> <?php } function bigBusiness_save_slider_options($post_id){ global $post; if( $_POST ) { update_post_meta( $post->ID, 'imageurl', $_POST['imageurl'] ); update_post_meta( $post->ID, 'imagelink', $_POST['imagelink']); update_post_meta( $post->ID, 'imagecap', $_POST['imagecap'] ); } } so the update_post_meta function is what is saving the information into the database. How do I put that into an array? I was thinking Code: [Select] foreach($_POST as $slides) $slides[] = array( 'imageurl' => '$_POST['imageurl'], 'imagelink' => $_POST['imagelink'], 'imagecap' => $_POST['imagecap']; ); I have been able to use the data out of the database by creating a function Code: [Select] function get_half_slider_slides() { global $post; $imageurl = get_post_meta( $post->ID, 'imageurl', true ); $imagelink = get_post_meta( $post->ID, 'imagelink', true ); $imagecap = get_post_meta( $post->ID, 'imageurl', true ); return array( $imageurl, $imagelink, $imagecap ); } and then calling that function in my code like this $slide = get_half_slider_slides(); I thought since it returned an array that I would be able to do this $slides['imagelink'] $slides['imageurl'] but it doesn't work. What I am trying to do is populate the nivo-slider ( http://nivo.dev7studios.com ) with images from the database. I have been following a tutorial but since the license on the tutorial doesn't cover reusing the code, I am trying to rewrite it in a way that doesn't violate the license agreement. This code is so far is hacked together but completely different from the tut. Can you help? Thanks Hi, I have this $_POST array coming from a paypal transaction Code: [Select] Array ( [address_city] => San Jose [address_country] => United States [address_country_code] => US [address_name] => Test User [address_state] => CA [address_status] => confirmed [address_street] => 1 Main St [address_zip] => 95131 [business] => test1_biz@gmail.com [charset] => windows-1252 [custom] => [first_name] => Test [item_name1] => Product Name 1 [item_name2] => Product Name 6 [item_name3] => Product Name 8 [item_number1] => 1 [item_number2] => 6 [item_number3] => 8 [last_name] => User [mc_currency] => USD [mc_fee] => 0.82 [mc_gross] => 18.00 [mc_gross_1] => 14.00 [mc_gross_2] => 2.00 [mc_gross_3] => 2.00 [mc_handling] => 0.00 [mc_handling1] => 0.00 [mc_handling2] => 0.00 [mc_handling3] => 0.00 [mc_shipping] => 11.00 [mc_shipping1] => 11.00 [mc_shipping2] => 0.00 [mc_shipping3] => 0.00 [notify_version] => 3.4 [num_cart_items] => 3 [payer_email] => test_biz@gmail.com [payer_id] => TRCLJTHLNCJ7Q [payer_status] => verified [payment_date] => 22:52:56 Jan 27, 2012 PST [payment_fee] => 0.82 [payment_gross] => 18.00 [payment_status] => Completed [payment_type] => instant [protection_eligibility] => Eligible [quantity1] => 1 [quantity2] => 1 [quantity3] => 1 [receiver_email] => test_biz@gmail.com [receiver_id] => 74PV23B8KSK84 [residence_country] => US [tax] => 0.00 [tax1] => 0.00 [tax2] => 0.00 [tax3] => 0.00 [test_ipn] => 1 [transaction_subject] => Shopping CartProduct Name 1Product Name 6Product Name 8 [txn_id] => 7BS85664SB906284D [txn_type] => cart [verify_sign] => AJ2IuqHp8G0lIxhedAqrwRQbv8fVA4-Gum9e7DMZmEWIFrljEwFCJDfP ) 1 as you can see, there are key value pairs like this, Code: [Select] [items_name1] => Product Name 1 [items_name2] => Product Name 2 [items_name3] => Product Name 3 those keys aren't constant, I mean, it came from a shopping cart, so the item name depends on how many items were placed in the shopping cart to be purchased.. now my question is, How to loop to that post array, and get only the item_names plus their corresponding values ?, because I need them and save in a db table How do you get the values in an array and name them as variables? Lets say I want the 0 and the 2... Array ( => 02.02.2011 [1] => 97% [2] => 538 [3] => 20 [4] => 63,247 (2.20) [5] => 77,639 [6] => 195,617 [7] => 09.13.2010 ) Hello, I need to set a CSS class for the highest number in a MySQL column, and the second highest. So for instance I have a column named scores. I would want the <td> with highest scores to be <td.Winner> and the second highest to be <td. RunnerUp>. I know how to set the css part up, so just need help with creating a function. I did something similar to set the background of table cells based on the text data and that looked like this. function cssfromdate($date) { $class = array('December_January' => 'January', 'March_April' => 'March'); return $class[$date]; } while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['last_name'] . "</td>\n"; echo "<td>" . ucwords($row['first_name']) . "</td>\n"; echo "<td class=\"".cssfromdate($row['Class_Date'])."\">".$row['Class_Date']."</td>\n"; echo "</tr>"; } I am hoping I can accomplish what I need to doing something similar. |