Jump to content

Barand

Moderators
  • Content count

    18,246
  • Joined

  • Last visited

  • Days Won

    297

Barand last won the day on June 17

Barand had the most liked content!

Community Reputation

1,148 Excellent

About Barand

Profile Information

Recent Profile Visitors

54,858 profile views
  1. The single quotes around the variable are treating it as a literal string, and not a value $var = 'Some text' echo $var; //--> Some text echo '$var'; //--> $var
  2. Barand

    PHP Gallery - Sorting newest images first

    Alternatively function get_files($qt_folder_name,$exts = array('jpg')) { $files = array(); if($handle = opendir($qt_folder_name)) { while(false !== ($file = readdir($handle))) { $extension = strtolower(get_file_extension($file)); if($extension && in_array($extension,$exts)) { $files[$file] = filemtime($qt_folder_name . '/' . $file); } } closedir($handle); } arsort($files); return array_keys($files); }
  3. Barand

    PHP Gallery - Sorting newest images first

    No. use rsort($files) as I said, instead of array_multisort().
  4. Barand

    PHP Gallery - Sorting newest images first

    Instead of $files[] = $file; $times[] = filemtime($images_dir . '/' . $file); have a single array $files[] = [ filemtime($images_dir . '/' . $file), $file ]; Then all you need is a simple descending sort rsort($files); which will sort on the first element of each subarray.
  5. Barand

    Import csv from ftp and display user meta

    Have you tried any debugging? for instance $files = glob("*.csv") ; echo '<pre>', print_r($files, 1), '</pre>';;
  6. Barand

    Import csv from ftp and display user meta

    As I do not have your folder structure or files (and therefore cannot run the code), and I cannot see your screen, you need to give a little more information about what is happening when you run it. In what way is it failing? What happens that shouldn't? What shouldn't happen that does?
  7. Barand

    Import csv from ftp and display user meta

    You could use something like the glob() function to loop through the directory and process individual csv files
  8. Barand

    multiple select statements

    I don't know if this is close to your situation. Consider this scenarion. We have a set of customer accounts account table +------------+-----------+-------------+ | account_id | name | email | +------------+-----------+-------------+ | 1 | Company A | a@gmail.com | | 2 | Company B | b@gmail.com | | 3 | Company C | c@gmail.com | +------------+-----------+-------------+ When they buy from us we raise invoices and store the dates and amounts payment_due table +----------------+------------+------------+------------+--------+ | payment_due_id | account_id | invoice_id | due_date | amount | +----------------+------------+------------+------------+--------+ | 1 | 1 | 101 | 2018-04-15 | 100.00 | | 5 | 2 | 102 | 2018-04-15 | 200.00 | | 2 | 1 | 103 | 2018-05-15 | 100.00 | | 4 | 3 | 104 | 2018-06-01 | 300.00 | | 3 | 1 | 105 | 2018-06-15 | 100.00 | +----------------+------------+------------+------------+--------+ The customers make payments (hopefully) against these invoices payments_recd table +-----------------+------------+------------+------------+---------+ | payment_recd_id | account_id | invoice_id | recd_date | payment | +-----------------+------------+------------+------------+---------+ | 1 | 1 | 101 | 2018-04-15 | 100.00 | | 5 | 2 | 102 | 2018-06-15 | 150.00 | | 4 | 3 | 104 | 2018-06-10 | 300.00 | +-----------------+------------+------------+------------+---------+ After 30 days we want to sent a reminder that any unpaid moneys are due. After 60 days we send the "red frightener" letters. So a single query like this will show the overdue payments. SELECT a.name , a.email , d.due_date , d.invoice_id , due , IFNULL(paid, 0) as paid , due - IFNULL(paid, 0) as owed , DATEDIFF(CURDATE(), d.due_date) as days_overdue FROM account a INNER JOIN ( SELECT account_id , invoice_id , due_date , SUM(amount) as due FROM payment_due GROUP BY account_id, invoice_id ) d USING (account_id) LEFT JOIN ( SELECT account_id , invoice_id , SUM(payment) as paid FROM payment_recd GROUP BY account_id, invoice_id ) p ON d.invoice_id = p.invoice_id WHERE due_date <= CURDATE() - INTERVAL 30 DAY AND due > IFNULL(paid,0) Query results +-----------+-------------+------------+------------+--------+--------+--------+--------------+ | name | email | due_date | invoice_id | due | paid | owed | days_overdue | +-----------+-------------+------------+------------+--------+--------+--------+--------------+ | Company A | a@gmail.com | 2018-05-15 | 103 | 100.00 | 0.00 | 100.00 | 33 | | Company B | b@gmail.com | 2018-04-15 | 102 | 200.00 | 150.00 | 50.00 | 63 | +-----------+-------------+------------+------------+--------+--------+--------+--------------+ (You would also need to record when the two types of email were sent and use this information to prevent multiple copies being sent to customers.)
  9. Barand

    multiple select statements

    No that isn't your problem - that is how you are trying to solve your problem. We need to know the business problem. What are the 30 and 10 days relative to? (Unless those 30 and 10 days are relative to the same date for everyone, then tomorrow you need another two files, and the day after another two, and so on ad absurdum.)
  10. Barand

    multiple select statements

    Now we have seen your proposed solution, what is the problem you are trying to solve?
  11. Barand

    Counting unique records

    Assuming you have an "ethnicity" definition table, for example +----------+-----------------------------------------------+ | ethnicid | description | +----------+-----------------------------------------------+ | 1 | English/Welsh/Scottish/Northern Irish/British | | 2 | Irish | | 3 | Gypsy or Irish Traveller | | 4 | Any other White background | | 5 | White and Black Caribbean | | 6 | White and Black African | | 7 | White and Asian | | 8 | Any other Mixed/Multiple ethnic background | | 9 | Indian | | 10 | Pakistani | | 11 | Bangladeshi | | 12 | Chinese | | 13 | Any other Asian background | | 14 | African | | 15 | Caribbean | | 16 | Any other Black/African/Caribbean background | | 17 | Arab | | 18 | Any other ethnic group | +----------+-----------------------------------------------+ I would SELECT ethnicid , count(clientid) as clients FROM ethnicity e LEFT JOIN ( SELECT DISTINCT c.clientid , c.ethnicid FROM advice a JOIN client c USING (clientid) WHERE advicedate BETWEEN '2018-01-01' AND '2018-03-31' ) ca USING (ethnicid) GROUP BY ethnicid
  12. Barand

    Firebase create Topic

    http://lmgtfy.com/?q=php+json
  13. Barand

    Looking for Donut Chart code

    It's just like pie charts. Make the second smaller than the first and so on. Finish off with a smaller centre circle
  14. Barand

    Resource id#51

    If you decide to take my advice in my earlier reply to hash your passwords, this script will update your current contrasena plain-text values to their hashed values <?php /*********************************************************** ** PDO CONNECTION ** ************************************************************/ $host = 'localhost'; $username = '?'; $password = '?'; $database = '?'; $dsn = "mysql:dbname=$database; host=$host; charset=utf8"; $db = new pdo($dsn, $username, $password, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); /***********************************************************/ // Make sure contrasena column big enough for hash value $db->exec("ALTER TABLE `usuario` CHANGE COLUMN `contrasena` `contrasena` VARCHAR(100) NULL DEFAULT NULL"); // prepare a statememt to update the usuario records $updt = $db->prepare("UPDATE usuario SET contrasena = ? WHERE id_usu = ? "); // get existing usuario records and update contrasena column with hash value $res = $db->query("SELECT id_usu, contrasena FROM usuario"); foreach ($res as $r) { $hash = password_hash($r['contrasena'], PASSWORD_DEFAULT); $updt->execute( [ $hash, $r['id_usu'] ] ); } ?> Then your current code might now look like this session_start(); unset($_SESSION['usuario'], $_SESSION['puesto']); /*********************************************************** ** PDO CONNECTION ** ************************************************************/ $host = 'localhost'; $username = '?'; $password = '?'; $database = '?'; $dsn = "mysql:dbname=$database; host=$host; charset=utf8"; $db = new pdo($dsn, $username, $password, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); /************************************************************/ if ($_SERVER['REQUEST_METHOD'] == 'POST') { $usuario = $_POST['nomUsuario']; $contrasena = $_POST['inContra']; $stmt = $db->prepare("SELECT contrasena, puesto FROM usuario WHERE usuario = ?"); $stmt->execute( [$usuario] ); if($valores = $stmt->fetch()){ if (password_verify($contrasena, $valores['contrasena'])) { //El logueo es exitoso y se crea la sesion $_SESSION['usuario'] = $usuario ; $_SESSION['puesto'] = $valores['puesto']; echo '<pre>', print_r($_SESSION, 1), '</pre>'; // !!! DEBUG only -- remove switch ($valores['puesto']) { case 'A': header("Location: ../indexMenu.php"); exit; case 'B': header("Location: ../../../alumnos/php/indexMenu.php"); exit; } } } echo 'No se ha podido iniciar sesion, por favor vuelva a intentarlo.'; } Note the "exit;" statements after the redirect calls. This prevents the script from continuing execution (even though you won't see it) and creating unwanted side effects (such as db updates etc.)
  15. Barand

    Resource id#51

    Your code doesn't output anything (except the added check to see the contents of the session). All it does is check the user and password and update session variables. It then shoud transfer to another page. As it transfers before you do the print_r() you don't see anything. Comment out those header calls while you are testing.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.