-
Posts
24,609 -
Joined
-
Last visited
-
Days Won
832
Everything posted by Barand
-
Instead of two history data tables (champhorses and champhorses2014) which have identical structure, combine and extract this year and previous year stats based on the date. However, as you currently have it you need a union of the two table to get the max values Something like this SELECT t1.Horse , t1.Track , t1.Race , t1.Jockey , t1.Trainer , t1.Owner , t1.Date , t2.perStart , t2.rank , t2.speedFigure , t3.perStart2014 , t3.rank2014 , t3.speedFigure2014 , maxps , maxrank , maxsf FROM champsintoday t1 LEFT JOIN champshorses t2 ON t1.HorseRef = t2.referenceNumber LEFT JOIN champshorses2014 t3 ON t1.HorseRef = t3.referenceNumber2014 INNER JOIN ( SELECT referenceNumber , MAX(perStart) as maxps , MAX(rank) as maxrank , MAX(speedFigure) as maxsf FROM ( SELECT referenceNumber , perStart , rank , speedFigure FROM champshorses UNION SELECT referenceNumber2014 , perStart2014 , rank2014 , speedFigure2014 FROM champshorses2014 ) as bothtbls GROUP BY referenceNumber ) as t4 ON t1.HorseRef = t4.referenceNumber WHERE t1.Date = CURDATE() ORDER BY t1.Date ASC, t1.track ASC, t1.Race ASC, t2.speedFigure DESC
-
Sorting and/or grouping so certain status always at end
Barand replied to sKunKbad's topic in MySQL Help
Explanation: The boolean expression "Status='expired'" evaluates to 0 or 1 SELECT variety , expiry , status , status='expired' as demo FROM vegetable ORDER BY status='expired', expiry; +----------+---------------------+---------+------+ | variety | expiry | status | demo | +----------+---------------------+---------+------+ | sprouts | 2015-07-05 21:53:57 | fresh | 0 | | cabbage | 2015-07-10 21:53:57 | rotten | 0 | | lettuce | 2015-07-11 21:53:57 | fresh | 0 | | cucumber | 2015-07-12 21:53:57 | rotten | 0 | | potato | 2015-07-08 21:53:57 | expired | 1 | | totmato | 2015-07-14 21:53:57 | expired | 1 | +----------+---------------------+---------+------+ -
Sorting and/or grouping so certain status always at end
Barand replied to sKunKbad's topic in MySQL Help
ORDER BY status='expired' , arrival_time -
Congratulations. Mine's a gin'n'tonic
-
Your problem seems similar to this thread http://forums.phpfreaks.com/topic/296962-looping-is-making-me-loopy/
-
Sorry about the form/fieldset. I spotted that after posting and moved the form tags. (It worked as it was but I noticed a warning when I viewed the html source in my IDE) <?=$example?> is shortcode for <?php echo $example;?> and is available from 5.4 list() requires a numerically indexed array, not an associative array. And yes, I omitted the error handling as my objective with the example was to show you how to handle the data.
-
get_magic_quotes_gpc() deprecated please help
Barand replied to Rebelfriik009's topic in PHP Coding Help
Read this thread http://forums.phpfreaks.com/topic/297236-get-magic-quotes-gpc-function-is-deprecated-some-help-please/ -
Some explanation of the whole process would help. For example, is that data the result of a single call to the url or accumulated from several calls. If several, how are you storing it? Do you want individual total for every second or is it that the data comes in every second but you want the accumulated totals for the day/hour or whatever time period? That is JSON data so you might want to start by looking at json_decode()
-
Compare one set of data to an entire array and find matchs
Barand replied to gearsgod's topic in PHP Coding Help
How to accomplish what? If the code isn't working (whatever not working means) it only shows us what you don't want too do. -
The section of code you posted above selects the profile record matching the user record. If there is no matching profile then those fields are null in the results. So if the userprofileid is found, the current data is displayed for editing. If not found, a blank form is displayed to add a profile. Line 11 is just to display "Add Profile" or "Edit Profile" in the fieldset legend. The getSkillset() function runs a query to get all the skillset descriptions and matches the skillset_id against the user_skillset to get the current levels for the user for each skillset. It then loops through the results creating a new div for each specialization, and these divs contain the list of skillsets for the specialisation with their radio buttons (the buttons checked according to the users current level) The javascript is to hide/show the div relating to the selected specialization. I am attaching a dump of my test database Dump20150709.txt
-
It may look more complicated but if your coding follows the db structure it's easier and requires far less code. I have attached a sample form and update using the proposed structure. As you can see it saves you hundreds of lines of repetitive coding. I don't what you want in the portfolio table but it sounds as though you treat it the same way as have with the user_skillset records (one image name per row, each with the user_id). For brevity, I omitted the picture upload. beginner_profile.php beginner_update.php
-
If you only want to send a single SMS, why are fetching records for everyone that has due due dates then checking each one for the $current_visitor? Make it a condition in the WHERE clauses so you only get the data you need. BTW, $current_visitor doesn't appear to be defined anywhere.
-
Given the structure of the data in your form, I would suggest that that your DB structure should be +----------+ +-----------------------+ | user | | specialization | +----------+ +-----------------------+ | id (PK) | | specialization_id(PK) | | name | | description | | email | +-----------------------+ | username | | | password | +-------------------+ +-------------------+ | +----------+ | user_profile | | skillset | | | +-------------------+ +-------------------+ | | | userProfileId(PK) | | skillset_id(PK) | | | | user_id | | specialization_id |>---------------+ +-----------------| picname | | description | | introduction | +-------------------+ | contactno | | +-------------------+ | | | | | | | | +-----------------------+ | | | user_skillset | | | +-----------------------+ | +--------<| user_id(PK) |>-----+ | skillset_id(PK) | | level | +-----------------------+
-
Your form is missing the "Submit" button. When I added that there were no problems. I did not get your timeout error.
-
Works fine for me. Post the whole code from your "index.php"
-
The select needs to be inside <form> tags (hence my previous link to php forms). When the form is submitted the contents are passed in the $_GET or $_POST arrays depending on the form method. (Use POST when sending data to perform an update and GET when you just want to get information) include("class.php"); if (isset($_GET['year'])) { $f = new february((int)$_GET['year']); $days = $f->numdays(); echo "There were $days days in February {$_GET['year']}<hr>"; } $cutoff = date(1900); $now = date('Y'); ?> <html> <body> <form method='get' action=''> <?php echo '<select name="year">' . PHP_EOL; for ($y=$now; $y>=$cutoff; $y--) { echo ' <option value="' . $y . '">' . $y . '</option>' . PHP_EOL; } echo '</select>' . PHP_EOL; ?> <input type='submit' name='btnSubmit' value='Submit'> </form> </body> </html>
-
http://uk1.php.net/manual/en/tutorial.forms.php
-
This should get all the info you need with a single query instead of all those separate ones SELECT id, sloc.name as start, startcompany, eloc.name as end, endcompany, cargoweight, dc.name as cargo, cargotype, time, cargodamage, drate.name as rating, distance, price, costs, screenshot, status price - costs - cargodamage as profit FROM drive_routes as dr INNER JOIN drive_locations as sloc ON dr.start = sloc.id INNER JOIN drive_locations as eloc ON dr.end = eloc.id INNER JOIN drive_cargo as dc ON dr.cargo = dc.id INNER JOIN drive_rating as drate ON dr.rating = drate.id WHERE driver = ". $_GET['id'] ."
-
The only loop I can see in the code is foreach($rows3 as $row){ Where is $rows3 defined?
-
html <img src='green-up-arrow.png' alt='normal'> <img src='im_rotate.php?fn=green-up-arrow.png' alt='rotated'> im_rotate.php <?php $fn = $_GET['fn']; $im = imagecreatefrompng($fn); $bg = imagecolorat($im, 0,0); $rot = imagerotate($im, 90, $bg); header("Content-type: image/png"); imagepng($rot); imagedestroy($im); imagedestroy($rot); ?> output
-
Looking at that code one would think you had never heard of JOINS. However, I know differently. http://forums.phpfreaks.com/topic/296174-trying-to-get-a-several-rows-and-colums-with-data/?do=findComment&comment=1511474 Not open to advice are you?
-
To use array_merge you need to decode the data as an array. Set second parameter of json_decode() to true $data = json_decode(file_get_contents($playlist), 1);
-
Given your array looks like this: $data = Array ( 0 => Array ( 'text' => '96.1 km', 'value' => 96113 ), 1 => Array ( 'text' => '52.1 km', 'value' => 52096 ), 2 => Array ( 'text' => '102 km', 'value' => 102064 ), 3 => Array ( 'text' => '30.0 km', 'value' => 29992 ), 4 => Array ( 'text' => '43.9 km', 'value' => 43864 ), ); then using ksort() will merely sort on the keys I highlighted in red. You will need a custom sort, using usort() to sort on the text values $data = Array ( 0 => Array ( 'text' => '96.1 km', 'value' => 96113 ), 1 => Array ( 'text' => '52.1 km', 'value' => 52096 ), 2 => Array ( 'text' => '102 km', 'value' => 102064 ), 3 => Array ( 'text' => '30.0 km', 'value' => 29992 ), 4 => Array ( 'text' => '43.9 km', 'value' => 43864 ), ); usort($data, function($a, $b) { return strnatcmp($a['text'], $b['text']); }); echo '<pre>',print_r($data, true),'</pre>'; which gives Array ( [0] => Array ( [text] => 30.0 km [value] => 29992 ) [1] => Array ( [text] => 43.9 km [value] => 43864 ) [2] => Array ( [text] => 52.1 km [value] => 52096 ) [3] => Array ( [text] => 96.1 km [value] => 96113 ) [4] => Array ( [text] => 102 km [value] => 102064 ) ) Alternatively, you can sort on the "value" values using usort($data, function($a, $b) { return $a['value'] - $b['value']); });
- 16 replies
-
- php
- sort array
-
(and 1 more)
Tagged with:
-
Is this what you're wanting? class february { private $year; public function __construct($year) { $this->year = $year; } public function numDays() { $d = new DateTime("{$this->year}-02-01"); return $d->format('t'); } } $f = new february(1900); echo $f->numdays(); // 28 $f = new february(2000); echo $f->numdays(); // 29