-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
mysql query not working with drop down boxes
Barand replied to lindisfarne's topic in PHP Coding Help
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? -
Yes, you've got it
- 11 replies
-
- tables
- relational database
-
(and 1 more)
Tagged with:
-
Try $_POST['aid'] instead of $_GET.
-
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']; }
-
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.
-
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 }
- 11 replies
-
- tables
- relational database
-
(and 1 more)
Tagged with:
-
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.
-
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
-
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
- 11 replies
-
- 2
-
- tables
- relational database
-
(and 1 more)
Tagged with:
-
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 | +---------+
-
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?
-
http://lmgtfy.com/?q=themeforest
-
How do I track an integer for an unknown string?
Barand replied to kenw232's topic in PHP Coding Help
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? -
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.
-
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?
-
I've given you two methods of getting the total. How many more do you want?
-
http://lmgtfy.com/?q=android%2Bphp%2Beditor
-
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
-
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
-
Did you forget the date_default_timezone_set("Europe/London"); ?
-
{..} 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"; }
-
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
-
Passing from data to PHP to capture variables and run an exe
Barand replied to lynns's topic in PHP Coding Help
Possibly a permissions problem? I think that, when running from IIS, the user is "IUSR_computername". -
You have a a single quote after OUTFILE which does not appear to have a corresponding closing quote