PHP - Set A Css Class For Highest Number, Second Highest In Mysql Field
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. Similar TutorialsHey, I have an array which stores a bunch of numbers lets say: Code: [Select] [0] = 1[1] = 6 Now a second array has: Code: [Select] [0] = 5 [1] = 6 What im trying to do - is find the first highest number from the second array that is not found in the first array.Both arrays are sorted already by the way using sort(). What is the best way to do this? Hi Guys
I'm a bit stuck on a query and hoping someone can help. I'm sure this has a really simple solution.
Below is a simplified representation of a table and I'm trying to select all of the data but where there are instances of the same postID I want to only select the row with the highest version number.
So for instance in a select all on the table below I would expect to get IDs of 2,3 and 4.
id | postID | version 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 have a row in a MySQL table called id, which auto-increments. I was wondering if anyone knows a PHP solution to find out what the highest number in the row is? I am thinking perhaps execute a MySQL query that will list the highest number, and then echo the result, like $row[id] in PHP? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351005.0 hey all how would I do this.. I'm guessing I need to go four different SELECT queries I have prices in my DB I need to select the highest price one echo it select the second highest price echo it select third highest echo it then select everything else and echo them I have this so far but i dont know how to get the second, third, ext highest. $result = mysql_query("SELECT * FROM stuff ORDER BY price DESC LIMIT 1"); while($row = mysql_fetch_array($result)) { echo $row['image'] . " " . $row['link']; echo "<br />"; } Hi,
Please can someone point me in the right direction to solving this.
The following code set the postage rate on a basket. It selects the lowest postage assigned to a product and set that as the postage rate.
I now need this to work the opposite way round and select the highest postage rate of the added products.
The postage rates are stored in the database as:
0=0.00
1=4.95
2=7.95
3=12.95
So it looks like somewhere there has been something added that tells it to always give preference to the "0" of any products giving the lowest postage but I'm sure on this....
Thanks.
//set default postage value outside loop $postagerate = 15.00; This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321437.0 (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? 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 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);
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. I have a code to sum up a field called quantityHand in MySQL, in my example below, the value always return 40 as a positive number instead of 40.00- 0.00 0.00 40.00- I have used intval() or floatval() function to convert the type of variable from string to int/float but still not working. Any help please? Here is the code Code: [Select] $sql = mysql_query("SELECT DISTINCT itemNumber, itemDesc, quantityHand, SUM(quantityHand) AS quantityHand FROM inventory where itemNumber like '%$term%' GROUP BY `itemNumber` ORDER BY `itemNumber`"); while ($row = mysql_fetch_array($sql)){ echo "<b>"; echo "</td><td style=\"text-align: center;\"><b>"; echo $row['itemNumber']; echo "</td><td style=\"text-align: center;\"><b>"; echo $row['itemDesc']; //echo "</td><td style=\"text-align: right;\">"; echo "</td><td style=\"text-align: center;\"><b>"; echo $row ['quantityHand']; echo "</td></tr>"; echo "</b>"; Hi: I'm going crazy trying to do the following: I'm making a job registration process where the user registers on one php page to the website, must acknowlege and email receipt using an activate php page, then is directed to upload their C.V. (resume) based on the email address they enter in the active page output. I then run an upload page to store the resume in teh MySQL db based on the users email address in the same record. If I isolate the process of the user registering to the db, it works perfectly. If I isolate the file upload process into the db, it works perfect. I simply cannot upload teh file to the existing record based on teh email form field matching the user_email field in the db. With the processes together, teh user is activated, but teh file is not uploaded. Maybe I've simply been at this too long today, but am compeled to get through it by end day. If anyone can help sugest a better way or help me fix this, I will soo greatly appreciate it. My code is as follows for the 2 pages. ---------activate.php------- <?php session_start(); include ('reg_dbc.php'); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } $rsCode = mysql_query("SELECT activation_code from subscribers where user_email='$_GET[usr]'") or die(mysql_error()); list($acode) = mysql_fetch_array($rsCode); if ($_GET['code'] == $acode) { mysql_query("update subscribers set user_activated=1 where user_email='$_GET[usr]'") or die(mysql_error()); echo "<h3><center>Thank You! This is step 2 of 3. </h3>Your email is confirmed. Please upload your C.V. now to complete step 3.</center>"; } else { echo "ERROR: Incorrect activation code... not valid"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Job application activation</title> </head> <body> <center> <br/><br/><br/> <p align="center"> <form name="form1" method="post" action="upload.php" style="padding:5px;"> <p>Re-enter you Email : <input name="email" type="text" id="email"/></p></form> <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="4000000"> Upload your C.V.: <input name="userfile" type="file" id="userfile"> <input name="upload" type="submit" id="upload" value="Upload your C.V."/></form> </p> </center> </body> </html> --------upload.php---------- <?php session_start(); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $email = $_POST['email']['user_email']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include 'reg_dbc.php'; $query = "UPDATE subscribers WHERE $email = user_email (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); mysql_close($dbname); } ?> <center> <br/> <br/> <br/> <br/> Thank you for uploading your <?php echo "$fileName"; ?> file, completing your registration, and providing us your C.V. for this position. <br/> <br/> <br/> We will contact you if your canditature qualifies. </center> Dear All PHP Master, Kindly need your help (I'm sorry my Bad English), I'm new in PHP and OOP in PHP please help to check I have class to convert number to words below, but when I'm running it the result in browser is error with error message : Notice: Undefined variable: str in C:\xampp\htdocs\latihan\oop.php on line 16 Notice: Undefined variable: str in C:\xampp\htdocs\latihan\oop.php on line 14 Notice: Undefined variable: str in C:\xampp\htdocs\latihan\oop.php on line 16 seratus dua puluh tiga juta empat ratus lima puluh enam ribu tujuh ratus delapan puluh sembilan here it's my code to convert number to words : <?php Class Terbilang { Public function terbilang() { $this->dasar = array(1=>'satu','dua','tiga','empat','lima','enam','tujuh','delapan','sembilan'); $this->angka = array(1000000000000,1000000000,1000000,1000,100,10,1); $this->satuan = array('triliun','milyar','juta','ribu','ratus','puluh',''); } Public function eja($n) { $i=0; while($n!=0){ $count = (int)($n/$this->angka[$i]); if($count>=10) $str .= $this->eja($count). " ".$this->satuan[$i]." "; else if($count > 0 && $count < 10) $str .= $this->dasar[$count] . " ".$this->satuan[$i]." "; $n -= $this->angka[$i] * $count; $i++; } $str = preg_replace("/satu puluh (\w+)/i","\\1 belas",$str); $str = preg_replace("/satu (ribu|ratus|puluh|belas)/i","se\\1",$str); return $str; } } $bilangan = new Terbilang; echo $bilangan -> eja(123456789); //shouldbe show :seratus dua puluh tiga juta empat ratus lima puluh enam ribu tujuh ratus delapan puluh sembilan ?> Hey guys, I m not yet an experienced coder. SO faced alot of problems. Here, I'm trying to generate a UNIQUE RANDOM NUMBER set between two numbers. Repetative occurance must be avoided by all means as I want every number so generated bears a unique value. In other words, every values that made entry into the field of my database should be differant from each others. <?php $conN=mysql_connect("localhost","root",""); if(!$conN) { die('error'.mysql_error()); } mysql_select_db("freebie_allusers",$conN); $UIN=mt_rand(1,5); $locateUIN="SELECT UIN FROM user_info WHERE UIN='".$UIN."'"; $fetchUIN=mysql_query($locateUIN); $resultUIN=mysql_num_rows($fetchUIN); if($resultUIN>0) { WHAT CODE IS REQUIRED HERE SO AS TO GENERATE UNIQUE RANDOM NUMBER? } else echo $UIN; ?> Thanx in advance Hi, Newbie! I need to generate a unique number and put it in a field called "intInstD" value ="123456" to send to Paypoint to initiate an order. They insist each order from my website has a unique number. Can anyone help with a bit of code that does this please? Much appreciated zzdave I am doing some practice with classes. MY class below echoes out input and radio fields based on the instantiation of the Form class (the code below is working!), but I am trying to resolve how to get my form radio fields so they are not in between every other form field as they are supposed to be next to eachother. If you run the below, you will see what I mean. And also is my approach at all sensible? I am only doing this for learning experience, so any advice please. <?php class Form { private $fields = array(); private $radios = array(); private $actionValue; private $submit = "Submit Form"; private $Nradios = 0; private $Nfields = 0; function __construct($actionValue, $submit) { $this->actionValue = $actionValue; $this->submit = $submit; } function displayForm() { echo "<form action='{$this->actionValue}' method='post'>\n\n"; for ($j = 1, $i = 1; $j <= sizeof($this->fields), $i <= sizeof($this->radios); $j++, $i++) { echo "<p>\n<label>{$this->fields[$j-1]['label']} : </label>\n"; echo "<input type='text' name='{$this->fields[$j-1]['name']}'>\n</p>\n\n"; echo "<p>\n<label>{$this->radios[$i-1]['rlabel']} : </label>\n"; echo "\n<input type='radio' name='{$this->radios[$i-1]['rname']}' value='{$this->radios[$i-1]['rvalue']}'>\n</p>\n\n"; } echo "\n\n<input type='submit' value='{$this->submit}'>\n</form>"; } function addField($name, $label) { $this->fields[$this->Nfields]['name'] = $name; $this->fields[$this->Nfields]['label'] = $label; $this->Nfields = $this->Nfields + 1; } function addRadio($rname, $rvalue, $rlabel) { $this->radios[$this->Nradios]['rname'] = $rname; $this->radios[$this->Nradios]['rvalue'] = $rvalue; $this->radios[$this->Nradios]['rlabel'] = $rlabel; $this->Nradios = $this->Nradios + 1; } } ?> <?php $contact_form = new Form("process.php", "Submit Data >>"); $contact_form->addField("first_name", "First Name"); $contact_form->addField("last_name", "Last Name"); $contact_form->addRadio("gender", "male", "Male"); $contact_form->addRadio("gender", "femail", "Female"); $contact_form->displayForm(); ?> I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? I need to create a custom PK similar to 000111-GH. whe 0001 is the counter 11 is the year GH i need randomly generated with either numbers/letters once 2012 occurs, i need the counter to be reset to 000112-DF How would i increment 0001 until 2012, then reset the first few digits back to 0001? similarly, i will have a linked table but will have a different autonumber format for client 1 the linked data would look look like this 000111-GH-001 for record 1 000111-GH-002 for record 2 but then for client 2 000211-DS-001 00211-DS-002 Can anyone provide any assistance on how to accomplish this? thank you. |