Jump to content

Barand

Moderators
  • Posts

    24,338
  • Joined

  • Last visited

  • Days Won

    795

Everything posted by Barand

  1. print_r() is a debugging tool for viewing an array, it does not produce an array. This will give you the desired array. $id_array = []; // initialize array foreach ($data['opportunity_items'] as $k => $item) { $id_array[$k] = $item['id']; }
  2. No need for kinky three-person relationships. You would get the info from persons p1 and persons p2. Store it and use it in the same way that the name is used.
  3. it is passed as a parameter to the function $processed=[]; listAssociates(1, $data, $processed, 0); | | +---- 'level' value then incremented on subsequent calls foreach ($data[$pid]['assocs'] as $aid=>$adata) { echo "$indent{$adata['rel']} <b>{$adata['name']}</b><br>\n"; listAssociates($aid, $data, $processed, $level+1); <---- CALL AGAIN }
  4. If you worked for me and my requirement was and you came up with that as a solution, then you wouldn't be getting paid.
  5. c) if the image already uses black, get the index of that color ($black = imagecolorexact($jpg_image,0,0,0)) and use it for the text
  6. You could try something like this, storing the data into an array then processing that array recursively //********** DATA ********************************* SELECT person_id,fname,lname FROM person; +-----------+-------+------------------+ | person_id | fname | lname | +-----------+-------+------------------+ | 1 | Curly | Phillips | | 2 | Larry | Barnes | | 3 | Mo | Moore | | 4 | Peter | de Mohrenschildt | | 5 | Paul | Oswald | | 6 | Mary | Hunt | | 7 | Tom | Sturgis | +-----------+-------+------------------+ SELECT * FROM assoc; +----------+------+------+-------------------+------------------+ | assoc_id | p_id | a_id | p_to_a | a_to_p | +----------+------+------+-------------------+------------------+ | 1 | 1 | 2 | employs | works for | | 2 | 2 | 3 | knows | knows | | 3 | 3 | 4 | worked with | worked with | | 4 | 4 | 5 | knows | knows | | 5 | 1 | 6 | brother-in-law to | sister-in-law to | | 6 | 6 | 7 | wife of | husband of | | 7 | 7 | 3 | knows | knows | +----------+------+------+-------------------+------------------+ The processing $db = new mysqli(HOST,USERNAME,PASSWORD,DB); $sql = "SELECT p_id , a_id , CONCAT(p1.fname,' ',p1.lname) as name1 , p_to_a as association , CONCAT(p2.fname,' ',p2.lname) as name2 FROM assoc a INNER JOIN person p1 ON p1.person_id = a.p_id INNER JOIN person p2 ON p2.person_id = a.a_id"; $data = []; $res = $db->query($sql); while (list($pid, $aid, $n1, $ass, $n2) = $res->fetch_row()) { if (!isset($data[$pid])) { $data[$pid] = [ 'name' => $n1, 'assocs' => [] ]; } $data[$pid]['assocs'][$aid] = ['name' => $n2, 'rel' => $ass]; } $processed=[]; listAssociates(1, $data, $processed, 0); function listAssociates($pid, &$data, &$processed, $level) { if (!isset($data[$pid])) { return; } if (in_array($pid, $processed)) return; // prevent circular references $processed[] = $pid; if ($level==0) { echo "<b>{$data[$pid]['name']}</b><br>"; } $indent = str_repeat(' ', $level*10); foreach ($data[$pid]['assocs'] as $aid=>$adata) { echo "$indent{$adata['rel']} <b>{$adata['name']}</b><br>\n"; listAssociates($aid, $data, $processed, $level+1); } } The results Curly Phillips employs Larry Barnes knows Mo Moore worked with Peter de Mohrenschildt knows Paul Oswald brother-in-law to Mary Hunt wife of Tom Sturgis knows Mo Moore
  7. SELECT drinker FROM frequents WHERE bar IN ( SELECT bar FROM frequents WHERE drinker = 'Joe' ) GROUP BY drinker HAVING COUNT(bar)=1; +---------+ | drinker | +---------+ | Erik | | Herb | | Jesse | | Justin | | Mike | | Vince | +---------+
  8. Perhaps you could get rid of the error the same way as you did when you previously had a problem like that earlier this year. https://forums.phpfreaks.com/topic/300771-from-to-date-search-form-php-mysqli/?do=findComment&comment=1530935 Do we have to keep helping you repeatedly with the same type of error?
  9. So far you have posted code that makes no sense at all, and a description of the problem that makes even less sense. Do you want to start again?
  10. I don't see your problem - your code only has one while() loop. As in my pseudocode (which shows how your program should work), initialize the total to 0 before the loop. Inside the loop you accumulate the total. After the loop output a row containing the total As for your search problem, you only include a condition in the WHERE clause if a value is provided for that condition.
  11. Show us what you have now. The pseudocode I posted (repeated below) showed you exactly where it goes. total=0; while fetch next row total += row value output the table row end while output total Or did you post the whole code so I could do the amendments for you?
  12. I've given you two methods of getting the total. How many more do you want?
  13. http://lmgtfy.com/?q=android%2Bphp%2Beditor
  14. Not if it is a multidimensional array, and it probably would be. $rows = [ ['name'=>'aaa', 'value'=>55.00], ['name'=>'bbb', 'value'=>25.00], ['name'=>'ccc', 'value'=>100.00], ['name'=>'ddd', 'value'=>255.00], ['name'=>'eee', 'value'=>65.00] ]; echo array_sum(array_column($rows, 'value')); //--> 500
  15. Do you put the rows from the database into an array before outputting to the html table? If so, you could get the total from that array. If not, and you output each table row as you process the query results then you can accumulate the total as output each row. total=0; while fetch next row total += row value output the table row end while output total
  16. Did you forget the date_default_timezone_set("Europe/London"); ?
  17. {..} always need to be in pairs. So both these are correct if (is_paged()) echo "Página 1"; if (is_paged()) { echo "Página 1"; }
  18. date_default_timezone_set("Europe/London"); $now = new DateTime(); echo 'Time now: ' . $now->format('Y-m-d H:i:s') . '<br>'; //--> 2016-09-15 11:50:01 $now->setTimezone(new DateTimeZone('UTC')); echo 'Time UTC: ' . $now->format('Y-m-d H:i:s') . '<br>'; //--> 2016-09-15 10:50:01
  19. Possibly a permissions problem? I think that, when running from IIS, the user is "IUSR_computername".
  20. You have a a single quote after OUTFILE which does not appear to have a corresponding closing quote
  21. Your exec() parameters use $Email and $CompanyName but you put the values into $user and $company
  22. There is no prepare statement in your code. Sorry, but if you you can't understand that what I said in my last post could pose a problem, then you are beyond any help I could offer.
  23. In an earlier post on this forum (http://forums.phpfreaks.com/topic/302132-page-php-how-include-input-and-type-to-search-in-my-table/?do=findComment&comment=15372780) you had So why are you using the `coffee` table with a form for entering firstname, lastname and age? Or are all your tables named `coffee`?
×
×
  • Create New...

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.