Jump to content

Barand

Moderators
  • Posts

    24,345
  • Joined

  • Last visited

  • Days Won

    795

Everything posted by Barand

  1. Solution posted in your other topic with this code https://forums.phpfreaks.com/topic/302251-mysql-query-not-working-with-drop-down-boxes/?do=findComment&comment=1537892
  2. It isn't difficult - add three lines of code, as I told you $total = 0; // initialise total while($record = mysql_fetch_array($myData)){ echo "<tr>"; echo "<td>" . $record['id'] . "</td>"; echo "<td>" . $record['author'] . "</td>"; echo "<td>" . $record['title'] . "</td>"; echo "<td>" . $record['publisher'] . "</td>"; echo "<td>" . $record['year'] . "</td>"; echo "<td>" . $record['genre'] . "</td>"; echo "<td>" . $record['sold'] . "</td>"; echo "<tr />"; $total += $record['sold']; // accumulate total } echo "<tr><td colspan='6'>Total:</td><td>$total</td></tr>"; // output total echo "</table>";
  3. I see your while loop still doesn't calculate a total of the 'sold' column. Was your previous post https://forums.phpfreaks.com/topic/302198-summing-up-the-values-in-an-array/ just to waste our time?
  4. 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']; }
  5. 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.
  6. 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 }
  7. 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.
  8. 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
  9. 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
  10. 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 | +---------+
  11. 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?
  12. 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?
  13. 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.
  14. 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?
  15. I've given you two methods of getting the total. How many more do you want?
  16. http://lmgtfy.com/?q=android%2Bphp%2Beditor
  17. 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
  18. 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
  19. Did you forget the date_default_timezone_set("Europe/London"); ?
  20. {..} 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"; }
  21. 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
×
×
  • 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.