-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
checking for duplicates when writing to text file
Barand replied to cobusbo's topic in PHP Coding Help
Perhaps a combination of file(), to read the csv file into an array and array_unique(), to remove any duplicates -
Also: firstly, you could have simplified your arrays by using xxx_fetch_assoc() or xxx_fetch_row. By using xxx_fetch_array() you get the values twice. second, you could probably have done the matching with your query instead of having to create the two arrays.
-
First, a comment or three on your current model. Person table contains the country_id twice. Person table should not contain the country currency and currency code fields. They should only be in the country table. Country-person is a one-to-many relationship, not on-to-one (one country has many persons) Notes on my model (I only included the key fields for brevity): An incident will have several statuses over its lifetime. I included from and to dates so that historical data is available (how many open cases were there each month, for instance) The "to_date" field in the current status record would contain 9999-12-31. This enables you find the current status as the one where the current date is between the two dates in the record. Is it possible that one agency is in charge of an incident but later an other agency takes control? If so you may need to take that same approach with the agency-incident relationship. Incidents may require several keywords. For example, take the "Jack the Ripper" murders in 19th century London. Several incidents all with keywords "Murder, mutilation, prostitute"
-
do you mean like this? <?php function test1() { echo "Test 1<br>"; } function test2() { echo "Test 2<br>"; } for ($i=0; $i<4; $i++) { $f = $i%2 ? 'test1' : 'test2'; $f(); // call function $f } ?>
-
Combine 2 elements from 2 different arrays to same record
Barand replied to PHP_Idiot's topic in PHP Coding Help
I experienced a feeling of deja vu when looking at your code. If the questions you are asking in this post were not the same ones that you asked (and I and others answered) at the end of January this year I might be inclined to help further, but I fear I would be wasting my time, again -
Combine 2 elements from 2 different arrays to same record
Barand replied to PHP_Idiot's topic in PHP Coding Help
The creation of your first array can be reduced to while($r = mysql_fetch_array($result)){ unset($r[0]); // you don't use that field $arr[] = $r; } However, as you later want to match on a the value $r[1].$r[2].$r[3] then use that as the array key, so you would have while($r = mysql_fetch_array($result)){ unset($r[0]); // you don't use that field $key = $r[1].$r[2].$r[3]; $arr[$key] = $r; } You can now easily get the required matcthing $r[9] value using $val = $arr[$row3[1].$row3[2].$row3[3]][9]; PS I don't know the rest of your code but all this would probably be better achieved by using a JOIN in your db query i the first place -
(Third attempt at this post in the last hour, so if it eventually appears several times blame the board) According to the above you changed the start point from outside (original) to Room A and displayed map from A to B But you say you cannot change the start point. So no, I do not understand your problem and therefore cannot help.
-
.. or the OP marked it as answered two years ago
-
https://developers.google.com/maps/documentation/javascript/tutorial
-
Use explicit JOIN syntax and not "FROM A,B,C WHERE..." It separates the structure of your query from the selection criteria and it is more efficient. I have incorporated the subquery for you get the counts SELECT Player.MembershipNo , num.MembershipCount , Player.FirstName , Player.LastName , Venue.VenueName as Venue , Results.MemCard , Results.EarlyReg , Position.Points as Venue_Points , Results.Date FROM Player INNER JOIN Results ON Player.MembershipNo = Results.MembershipNo INNER JOIN Position ON Results.Position = Position.Position INNER JOIN Venue ON Venue.VenueID = Results.VenueID INNER JOIN ( SELECT MembershipNo , COUNT(*) as MembershipCount FROM Results GROUP BY MembershipNo ) num ON Player.MembershipNo = num.MembershipNo WHERE Results.Date BETWEEN '2014-07-01' AND '2014-09-30' ORDER BY Player.MembershipNo, Venue;
-
Fetch Categories and Get Their Last Article In Same Query
Barand replied to ScottLacey's topic in MySQL Help
It did when it left the factory. RESULTS +-------------+-----------+-------------+------------+---------------+------+ | category_id | cat_title | description | article_id | article_title | tot | +-------------+-----------+-------------+------------+---------------+------+ | 1 | Cat 1 | Desc 1 | 3 | Art 1 3 | 3 | | 2 | Cat 2 | Desc 2 | 5 | Art 2 2 | 2 | | 3 | Cat 3 | Desc 3 | 9 | Art 3 4 | 4 | | 4 | Cat 4 | Desc 4 | NULL | NULL | NULL | +-------------+-----------+-------------+------------+---------------+------+ My test data mysql> SELECT * FROM categories; +-------------+-------+-------------+ | category_id | title | description | +-------------+-------+-------------+ | 1 | Cat 1 | Desc 1 | | 2 | Cat 2 | Desc 2 | | 3 | Cat 3 | Desc 3 | | 4 | Cat 4 | Desc 4 | +-------------+-------+-------------+ mysql> SELECT * FROM articles; +------------+-------------+---------+ | article_id | category_id | title | +------------+-------------+---------+ | 1 | 1 | Art 1 1 | | 2 | 1 | Art 1 2 | | 3 | 1 | Art 1 3 | | 4 | 2 | Art 2 1 | | 5 | 2 | Art 2 2 | | 6 | 3 | Art 3 1 | | 7 | 3 | Art 3 2 | | 8 | 3 | Art 3 3 | | 9 | 3 | Art 3 4 | +------------+-------------+---------+ -
You require a similar solution to this http://forums.phpfreaks.com/topic/291228-fetch-categories-and-get-their-last-article-in-same-query/?do=findComment&comment=1491852
-
let the dateTime and dateInterval classes do the work for you $fuel = 18480; $fuelUse = 40; $hrs = $fuel/$fuelUse; $dt1 = new DateTime("+$hrs hours"); $dif = $dt1->diff(new DateTime()); // $dif is a dateInterval object echo $dif->d . ' days '; echo $dif->h . ' hours '; echo $dif->m . ' minutes';
-
Fetch Categories and Get Their Last Article In Same Query
Barand replied to ScottLacey's topic in MySQL Help
If you need "latest" records then you should be using timestamps rather relying on id sequences, however, given your data, your solution is to use table subqueries to determine the latest id and join on that latest (MAX) id to get the matching article. You can pick up the count of articles at the same time SELECT c.category_id , c.title as cat_title , c.description , a.article_id , a.title as article_title , tot FROM categories c LEFT JOIN ( SELECT t.category_id , t.article_id , title , t.tot FROM articles JOIN ( SELECT category_id , MAX(article_id) as article_id , COUNT(article_id) as tot FROM articles GROUP BY category_id ) t USING (category_id, article_id) ) a USING (category_id) ORDER BY c.title ASC; -
For the benefit of those not members of the other forum ... RTFM re SELECT query syntax. $sql="select month='$m', year='$y', sectn='$sec' from attendance "; should be $sql="select <whatever> from attendance WHERE month='$m' AND year='$y' AND sectn='$sec'"; Also: stop using mysql_ functions and use mysqli_ or PDO functions don't put user data directly into your queries. Use prepared statements.
-
GD Library - Colorize Non-transparent areas in image
Barand replied to mouseywings's topic in PHP Coding Help
That was fun! Using GD I managed to get the set of four images from your two files (mask and rabbit). The second image was using image colorize filter with same values as bunny #4. (I used the blue background so I could check the transparent areas) It may need some refining but at least it's a start. the HTML for the four images is <img src='mousy2_img.php?r=200&g=120&b=120' border='0' width='200' height='200' alt='output'> <img src='mousy2_img.php?r=0&g=155&b=0' border='0' width='200' height='200' alt='output'> <img src='mousy2_img.php?r=0&g=0&b=155' border='0' width='200' height='200' alt='output'> <img src='mousy2_img.php?r=0&g=150&b=150' border='0' width='200' height='200' alt='output'> and code for mousy2_img.php <?php $colourToAdd = array ('red'=>$_GET['r'], 'green'=>$_GET['g'], 'blue'=>$_GET['b'], 'alpha'=>0); $im = imagecreatefrompng('mousyorig.png'); // your rabbit $mask = imagecreatefrompng('mousy.png'); // your mask overlay $w = imagesx($im); $h = imagesy($im); $mk = imagecolorat($mask,100,100); $trans = imagecolorallocate($im,1,1,1); imagecolortransparent($im, $trans); imagealphablending($im,0); // // scan mask image // for ($y=0; $y<$h; ++$y) { for ($x=0; $x<$w; ++$x) { if (imagecolorat($mask, $x, $y) != $mk) { imagesetpixel($im,$x,$y,$trans); // if transparent in mask } // ensure transparent in image else { addColour($im,$x,$y,$colourToAdd); // apply chosen color to pixel } // using same intensity as original } } function addColour($image, $x, $y, $add) { $col = imagecolorat($image, $x, $y); $c = imagecolorsforindex($image, $col); foreach ($c as $k=>&$v) { $v = $k!='alpha' ? $add[$k]*$v/255 : $add[$k]; } $z = imagecolorallocatealpha($image,$c['red'], $c['green'], $c['blue'], $c['alpha']); imagesetpixel($image,$x,$y,$z); } header("Content-Type: image/png"); imagepng($im); imagedestroy($im); imagedestroy($mask); ?> -
To clarify, I meant step 7, not step 10, in my previous question. You are in the wrong room (A instead of B) and you scan a picture. Somehow this now knows you are in room A so gives you a map from A to room B. How does it know you want to go to room B? What are the pictures? What is the relationship between pictures and QR codes? Now you are B and want to go to C why can't you do exactly the same as you did in room A when you wanted to go to room B? (Which apparently was to scan a picture)
-
OK for me as far as step 5, but then I have a couple of questions. You now have map to show you how to get from the start to room B, but in step 6 you are now in room A. So my first question is "If users cannot read maps, why bother?". However, that aside, you say the same QR codes are at the start and in every room, so in step 10, when you scan QR code B again it displays the map from A to B. Second question "How did it know you were in room A, especially as you shouldn't be there, and if it can do that why can't do it when you scan QR code C in room B (which is where you should be)?"
-
And FPDF has a manual, something I was unable to locate for TCPDF
-
If that data is coming from a database why don't you just query for the most recent record for each user. If not, use usort() with a custom function to sort by id ASC, approval_date DESC then loop through the array ignoring all but the first element for each user.
-
http://uk1.php.net/manual/en/mysqli.construct.php See example #1
-
Calculating an older date/time based on a desired interval
Barand replied to FreakingOUT's topic in PHP Coding Help
Use MySQL's functions ...WHERE submitted > NOW() - INTERVAL 60 MINUTE edit: To calculate using PHP $pastdatetime = date('Y-m-d H:i:s', strtotime('-60 minutes')); -
This may help http://www.phpfreaks.com/tutorial/data-joins-unions