-
Posts
24,609 -
Joined
-
Last visited
-
Days Won
832
Everything posted by Barand
-
Most of the cities in that sample begin with a space (or other non-printing character) and a "\n" In the example I picked out the length is 9 when it should be only 7. You need to trim() the elements in your data
-
... and is the file being opened? Check the value of $fil after opening to make sure it isn't = false.
-
foreach ($myarray as $yr => $yrdata) { echo $yr . '<br>'; foreach ($yrdata as $doc) { echo $doc['documentname'] . '<br>'; } }
-
execute the query and list the results. (I have use mysqli - which you should be using (or PDO) and not the deprecated mysql_ library) $mysqli = new mysqli(HOST,USERNAME,PASSWORD,'bikes'); $sql = "SELECT m.modell , m.antal , o.total , ROUND(o.total/m.antal*100, 1) as pc FROM modeller m LEFT JOIN ( SELECT mc as modell , COUNT(*) as total FROM owner GROUP BY modell ) o USING (modell) ORDER BY modell"; $res = $mysqli->query($sql); // execute the query while (list($model, $antal, $total, $pc) = $res->fetch_row()) { // list the results echo "We have $total pcs $model ( {$pc}% ) of produced $antal pcs in the database<br>"; }
-
this will give all models and their % in the database SELECT m.modell , m.antal , o.total , ROUND(o.total/m.antal*100, 1) as pc FROM modeller m LEFT JOIN ( SELECT mc as modell , COUNT(*) as total FROM owner GROUP BY modell ) o USING (modell) ORDER BY modell sample output +--------+-------+-------+------+ | modell | antal | total | pc | +--------+-------+-------+------+ | A50 | 20 | NULL | NULL | | B25 | 50 | 6 | 12.0 | | B40 | 50 | 6 | 12.0 | | B50 | 100 | 4 | 4.0 | | VH500 | 20 | 6 | 30.0 | +--------+-------+-------+------+
-
Monitor folder on webserver for new files with PHP to RSS feed
Barand replied to SavaSavanovic's topic in PHP Coding Help
Here's a function to return the N latest files in a folder $dir = "path/to/folder"; $latest = latestFiles($dir, 5); echo '<pre>',print_r($latest, true),'</pre>'; // view results function latestFiles($dir, $n) { $files = glob($dir.'/*.*'); // sort files by date DESC usort($files, function($a,$b) {return filemtime($b) - filemtime($a);}); // return latest n files return array_slice($files,0,$n); } -
I give up.
-
Also you are creating a lot of extra work for yourself At the moment you Select names from owners. User selects a name On submitting formselect o_id from owners where the name matches use o_id in the insert you should Select o_id and name from from owners set the id as the option value so user selects id Now when you process the form you have the o_id in the POST data and you don't need the extra query. You can do the insert straight away. (The same goes for the property)
-
then the query is still failing. try $result1 = mysqli_query($conn , $sql2); if ($result==false) { die ($conn->error); } ans see what the error is
-
A symptom that your query failed. Probably because $_POST['name'] is a string and therefore should be in single quotes SELECT Owner_ID FROM owners WHERE name = '$_POST[name]'
-
You are not reading the reply $own and $pro are not variables containing the ids, they contain query result objects. As secweb said, you need to fetch the row from the results and use the id value from the row. .
-
Here's a basic recursive glob() script $dir = 'c:/inetpub/wwwroot/'; // set start directory dirList($dir); // call the recursive function function dirList($dir, $level=0) { $files = glob($dir.'/*'); foreach ($files as $f) { if (is_dir($f)) continue; echo str_repeat('|---- ', $level) . basename($f) . '<br>'; } $files = glob($dir.'/*', GLOB_ONLYDIR); foreach ($files as $f) { if (is_dir($f)) { echo str_repeat('|---- ', $level) . "<strong>$f</strong><br>"; dirList($f, $level+1); } } }
-
for string fields, just use strcmp() in the function (that's what it's for) usort($output['data']['500020315']['members'],function($a, $b) { return strcmp($a['account_name'], $b['account_name']) ; }); For numeric sorts, return $a - $b (To sort DESC, reverse a and b in the comparisons)
-
Use a custom sort function with usort() http://forums.phpfreaks.com/topic/298103-how-to-sort-associative-array/?do=findComment&comment=1520543
-
You would do it in very much the same way that I showed you in your other post http://forums.phpfreaks.com/topic/298142-how-to-extract-this-dataset-xml-to-db/?do=findComment&comment=1520744
-
advise on getting dates in month/mini calendar
Barand replied to jonny512379's topic in PHP Coding Help
In the case above it is optional but in other cases it is required, with array elements embedded in a string "Today is {$dates['dayOfWeek']}" if there is no space between the $var and the next character "Price : {$price}GBP" and the next character could be part of a legitimate variable name. -
If it comes from a db query, why not go straight to the csv? $sql = "SELECT id, name, age FROM user"; $res = $mysqli->query($sql); $fp = fopen ('user.csv', 'w'); $row = $res->fetch_assoc(); // get first row fputcsv($fp, array_keys($row)); // write headers do { fputcsv($fp, $row); // write record } while ($row = $res->fetch_assoc()); fclose($fp);
-
Also, never store dates in d/m/y format - it is totally useless as a date storage format. Use DATE type column with format yyyy-mm-dd. Having done that you can then use CURDATE() to get the current date in your queries insted of generating in php first.
-
advise on getting dates in month/mini calendar
Barand replied to jonny512379's topic in PHP Coding Help
As Psycho's but using DateTime objects function getDatesForMonth($month, $year) { $int = new DateInterval('P1D'); // 1 day interval $dt1 = new DateTime("$year-$month-01"); $dt2 = (new DateTime($dt1->format('Y-m-t'))); // last day of month $dateper = new DatePeriod($dt1, $int, $dt2->add($int)); // create period from dt1 to dt2+1 $res = array(); foreach ($dateper as $d) { $res[$d->format('j')] = $d->format('D'); } return $res; } $dates = getDatesForMonth(9,2015); echo '<pre>',print_r($dates, true),'</pre>'; -
advise on getting dates in month/mini calendar
Barand replied to jonny512379's topic in PHP Coding Help
Have a look at the DateTime, DateInterval and DatePeriod classes DateTime DateInterval DatePeriod -
We have no knowledge of the structure of your data. Is there anything in the data to indicate that 4B, 8B and 9B are subsections of 3B, as in you second list above?
-
try $h = str_get_html($html); $res = $h->find("div.at_result[source=1215]"); foreach ($res as $r) { echo $r->category.'<br>'; } http://simplehtmldom.sourceforge.net/manual.htm
-
not difficult. $users = array ( array ('id' => 1, 'name' => 'Peters, John', 'age' => 22), array ('id' => 2, 'name' => 'Paul', 'age' => 22), array ('id' => 3, 'name' => 'Mary', 'age' => 22) ); $fp = fopen('users.csv', 'w'); $first = 1; foreach ($users as $udata) { if ($first) { // write header record to csv $heads = array_keys($udata); fputcsv($fp, $heads); $first = 0; } fputcsv($fp, $udata); } fclose($fp); Going the other way, use fgetcsv() to read each line of data into an array
-
Need help to select the funder with the second highest percentage
Barand replied to jmp98's topic in PHP Coding Help
You are not expected to just copy my code and paste it into yours. The purpose of the code was to set up a situation similar to yours and show you an example of how you can process it. -
Weird! I started with mysql> select * from logs order by usern,passwd,id,auth,date; +--------+---------+------+------+------------+--------+--------+ | usern | passwd | id | auth | date | active | number | +--------+---------+------+------+------------+--------+--------+ | aaaaaa | xxxxxxx | 1 | A | 2015-09-04 | 1 | 4 | | aaaaaa | xxxxxxx | 1 | C | 2015-09-01 | 1 | 1 | | aaaaaa | xxxxxxx | 1 | C | 2015-09-02 | 1 | 2 | | aaaaaa | xxxxxxx | 1 | C | 2015-09-03 | 1 | 3 | | aaaaaa | xxxxxxx | 1 | C | 2015-09-05 | 1 | 5 | | bbbbbb | yyyyyyy | 2 | A | 2015-09-01 | 1 | 6 | | bbbbbb | yyyyyyy | 2 | A | 2015-09-02 | 1 | 7 | | bbbbbb | yyyyyyy | 2 | A | 2015-09-03 | 1 | 8 | | bbbbbb | yyyyyyy | 2 | A | 2015-09-04 | 1 | 9 | | cccccc | zzzzzzz | 3 | A | 2015-09-06 | 1 | 10 | +--------+---------+------+------+------------+--------+--------+ then I ran your version of the query and was left with +--------+---------+------+------+------------+--------+--------+ | usern | passwd | id | auth | date | active | number | +--------+---------+------+------+------------+--------+--------+ | aaaaaa | xxxxxxx | 1 | A | 2015-09-04 | 1 | 4 | | aaaaaa | xxxxxxx | 1 | C | 2015-09-05 | 1 | 5 | | bbbbbb | yyyyyyy | 2 | A | 2015-09-04 | 1 | 9 | | cccccc | zzzzzzz | 3 | A | 2015-09-06 | 1 | 10 | +--------+---------+------+------+------------+--------+--------+