-
Posts
24,605 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
And normalize your tables. When you have fields named xxx1, xxx2, xxx3, ..., xxxN, you are doing it wrong.
-
Telling us what you don't want isn't helpful, we need to know what you are expecting.
-
How do you show php foreach loop results as ajax mousehover?
Barand replied to imgrooot's topic in PHP Coding Help
You also need a mouseout to set the display back to "none" -
You probably want something along these lines SELECT dep.month , deptotal , baltotal , deptotal + baltotal as total FROM ( SELECT EXTRACT(YEAR_MONTH FROM date_deposit_paid) as ym MONTHNAME(date_deposit_paid) as month , SUM(deposit_paid) as deptotal FROM projects GROUP BY ym ) dep JOIN ( SELECT EXTRACT(YEAR_MONTH FROM date_rembl_paid) as ym , SUM(rembl_paid_amount) as baltotal FROM projects GROUP BY ym ) bal USING (ym)
-
Paste variables onto a Word doc on order submission
Barand replied to jimleeder123's topic in PHP Coding Help
Another approach is use Word's mail merge feature and create a data file (.csv perhaps) with the data that needs to be inserted. -
If they're talking about me, it's probably nothing good. I'd rather not know.
-
HINT: if you are using print_r, put it between <pre>..</pre> tags. It makes it so much easier to understand the array structure. print_r($array); /* OUTPUT : Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [1] => Array ( [0] => 2 [1] => 2 [2] => Array ( [0] => 45 [1] => 22 [2] => 34 ) ) [2] => Array ( [0] => 4 [1] => 5 [2] => 6 [3] => 7 ) ) */ echo '<pre>' . print_r($array, true) . '</pre>'; /* OUTPUT : Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [1] => Array ( [0] => 2 [1] => 2 [2] => Array ( [0] => 45 [1] => 22 [2] => 34 ) ) [2] => Array ( [0] => 4 [1] => 5 [2] => 6 [3] => 7 ) ) */
-
I can't understand why more people don't do that instead of using free tools like Workbench.
-
$age = (new DateTime($dob))->diff(new DateTime())->y; should work with PHP 5.3 or later. What is in $dob? Has the format that is being passed in $dob changed?
-
Since the query is aggregating totals, individual gametimes are irrelevant, so why the useless ORDER BY? You should also note that the data is currently not limited to a specific season. I don't know what your method queryForColumn() returns but this looks a little odd to me $missingPreds = " " . $this->dbo->queryForColumn($query) . ")";
-
Similarly, for the last part SELECT userid , lastgame - lastprediction as missed FROM ( SELECT MAX(id) as lastgame FROM games ) games CROSS JOIN ( SELECT userid , MAX(gameid) as lastprediction FROM prediction GROUP BY userid ) users
-
You would use a subquery to combine EG SELECT p.userid , COUNT(*) as predictions , totgames - COUNT(*) as missing , totgames FROM prediction p CROSS JOIN ( SELECT COUNT(*) as totgames FROM games ) tot GROUP BY p.userid
-
It's a recursive solution I had both open at once and meant to link to this other one - with a very similar title. http://forums.phpfreaks.com/topic/292827-display-data-in-tabular-format-by-year-and-month/?do=findComment&comment=1498183
-
You could apply a method similar to this one http://forums.phpfreaks.com/topic/301314-displaying-data-in-tabular-form/?do=findComment&comment=1533481 I'd also start by tidying up the SQL code. You wouldn't write your php in one single line. $sql = "SELECT student_exam.id as sid , student_exam.student_id , student_exam.enroll_no , student_exam.exam_id , student_exam.subject_id , student_exam.obtained_marks , exam_time_table.exam_name , exam_time_table.class , exam_time_table.section , exam_time_table.total_marks , subjects.subject , exam_type.exam , student.enroll_no , student.stud_name FROM student_exam INNER JOIN exam_time_table ON student_exam.exam_id=exam_time_table.id INNER JOIN subjects ON student_exam.subject_id=subjects.sub_id INNER JOIN exam_type ON exam_time_table.exam_name=exam_type.eid INNER JOIN student ON student_exam.enroll_no=student.enroll_no WHERE exam_time_table.class='$class' AND exam_time_table.section='$section' AND student_exam.enroll_no='$enroll_no' ";
-
Display Distinct data with each related data
Barand replied to samuel_lopez's topic in PHP Coding Help
The method (1) proposed by Jacques is certainly simpler. OTOH, storing in an array (method 2) gives added flexibility. For example, the ability to count prior to output. Method 1 code $sql = "SELECT brand, category, product FROM product ORDER BY brand, category"; $res = $mysqli->query($sql); $prevbrand = ''; $prevcat = ''; $tdata1 = ''; while (list($brand,$cat,$prod) = $res->fetch_row()) { $cat_output = $brand_output = ''; if ($brand != $prevbrand) { $brand_output = $brand; $cat_output = $cat; } elseif ($cat != $prevcat) { $cat_output = $cat; } $prevbrand = $brand; $prevcat = $cat; $tdata1 .= "<tr><td>$brand_output</td><td>$cat_output</td><td>$prod</td></tr>\n"; } Method 2 code $sql = "SELECT brand, category, product FROM product"; $res = $mysqli->query($sql); while (list($brand,$cat,$prod) = $res->fetch_row()) { $data[$brand][$cat][] = $prod; } // prepare output table $tdata2=''; foreach ($data as $brand => $bdata) { $kb = 0; foreach ($bdata as $cdata) { $kb += count($cdata); } $firstb=1; foreach ($bdata as $cat => $cdata) { $kc = count($cdata); if ($firstb) { $tdata2 .= "<tr><td rowspan='$kb'>$brand</td>"; } $firstc=1; foreach ($cdata as $prod) { if ($firstc) { if (!$firstb) $tdata2 .= "<tr>"; $tdata2 .= "<td rowspan='$kc'>$cat</td>"; } if (!$firstb && !$firstc) $tdata .= "<tr>"; $tdata2 .= "<td>$prod</td></tr>\n"; $firstc = 0; } $firstb = 0; } } -
Yes. If they choose "videos" or "images" then you have SELECT ... WHERE type = :type If they select "All" then you just omit the WHERE clause
-
Display Distinct data with each related data
Barand replied to samuel_lopez's topic in PHP Coding Help
Firstly, don't run queries inside loops, use a single query SELECT brand, category, product FROM tblproducts Store the results in a multidimensional array, EG $data[brand][category] = [product1, product2] Now you can loop through the array to build your output table. -
A single SQL query can do all the work for you, no need to mess with arrays. A potential problem is that there may be weeks with credits and no debits and vice versa. A way round this is to use a table subquery with a union to gather all the data, then total that subquery. Suppose you have this data CREDIT table DEBIT table +-----------+------------+--------+ +----------+------------+--------+ | credit_id | cr_date | amount | | debit_id | db_date | amount | +-----------+------------+--------+ +----------+------------+--------+ | 1 | 2015-12-25 | 50.00 | | 1 | 2015-12-15 | 30.00 | | 2 | 2015-12-26 | 40.00 | | 2 | 2015-12-15 | 35.00 | | 3 | 2015-12-27 | 60.00 | | 3 | 2015-12-22 | 55.00 | | 4 | 2015-12-28 | 20.00 | | 4 | 2015-12-30 | 30.00 | | 5 | 2016-01-04 | 30.00 | | 5 | 2016-01-05 | 25.00 | | 6 | 2016-01-05 | 45.00 | | 6 | 2016-01-06 | 50.00 | | 7 | 2016-01-06 | 55.00 | | 7 | 2016-01-07 | 45.00 | | 8 | 2016-01-11 | 25.00 | | 8 | 2016-01-12 | 20.00 | | 9 | 2016-01-13 | 70.00 | | 9 | 2016-01-14 | 65.00 | | 10 | 2016-01-18 | 65.00 | | 10 | 2016-01-16 | 70.00 | | 11 | 2016-01-21 | 55.00 | | 11 | 2016-01-17 | 30.00 | | 12 | 2016-01-25 | 50.00 | | 12 | 2016-01-30 | 80.00 | +-----------+------------+--------+ +----------+------------+--------+ then SELECT DATE_FORMAT(date,'%x') as yr , DATE_FORMAT(date,'%v') as wk , MIN(date - INTERVAL WEEKDAY(date) DAY) as startdate , SUM(credit) as credit , SUM(debit) as debit , SUM(credit - debit) as diff FROM ( SELECT cr_date as date , amount as credit , 0 as debit FROM credit UNION ALL SELECT db_date as date , 0 as credit , amount as debit FROM debit ) data GROUP BY yr,wk; gives you +------+------+------------+--------+--------+--------+ | yr | wk | startdate | credit | debit | diff | +------+------+------------+--------+--------+--------+ | 2015 | 51 | 2015-12-14 | 0.00 | 65.00 | -65.00 | | 2015 | 52 | 2015-12-21 | 150.00 | 55.00 | 95.00 | | 2015 | 53 | 2015-12-28 | 20.00 | 30.00 | -10.00 | | 2016 | 01 | 2016-01-04 | 130.00 | 120.00 | 10.00 | | 2016 | 02 | 2016-01-11 | 95.00 | 185.00 | -90.00 | | 2016 | 03 | 2016-01-18 | 120.00 | 0.00 | 120.00 | | 2016 | 04 | 2016-01-25 | 50.00 | 80.00 | -30.00 | +------+------+------------+--------+--------+--------+ Job done.
-
You don't want the "form=" after the "?".
-
Are the debit and credit items from a database?
-
If you have the data in a database, sort it when you retrieve the date using an ORDER BY clause. Otherwise, don't use variables like $JOBDISPLAY10, $JOBDISPLAY11, use an array and sort the array. EG <?php $jobdisplay = [ 10 => [ 'title' => 'Job title 10', 'company' => 'Company name 10', 'country' => 'Somewhere', 'start' => '2016-05-01', 'finish' => 'present', 'duties' => 'description of duties ...' ], 11 => [ 'title' => 'Job title 11', 'company' => 'Company name 11', 'country' => 'Somewhere else', 'start' => '2014-01-01', 'finish' => '2014-12-31', 'duties' => 'another description of duties ...' ], 12 => [ 'title' => 'Job title 12', 'company' => 'Company name 12', 'country' => 'Somewhere', 'start' => '2016-04-01', 'finish' => 'present', 'duties' => 'yet another description of duties ...' ], 13 => [ 'title' => 'Job title 13', 'company' => 'Company name 13', 'country' => 'Somewhere other', 'start' => '2015-01-01', 'finish' => '2016-03-31', 'duties' => 'and yet another description of duties ...' ] ]; function customSort($a, $b) { $finA = $a['finish']=='present' ? date('Y-m-d') : $a['finish']; $finB = $b['finish']=='present' ? date('Y-m-d') : $b['finish']; $x = strcmp($finB, $finA); // if same finish dates, sort by start date if ($x==0) { return strcmp($b['start'], $a['start']); } return $x; } usort($jobdisplay, 'customSort'); echo '<pre>'; foreach ($jobdisplay as $j) { printf('%-20s | %-15s | %-15s<br>', $j['title'], $j['start'], $j['finish']); } echo '</pre>'; ? Gives Job title 10 | 2016-05-01 | present Job title 12 | 2016-04-01 | present Job title 13 | 2015-01-01 | 2016-03-31 Job title 11 | 2014-01-01 | 2014-12-31
-
Have error_reporting ON in both environments In development, have display_errors ON In production, have log_errors ON instead.
-
Use a hidden field in the form for the goalie value form.php <?php $goalie = 'someCalculatedValue'; // calculate the goalie value ?> <html> <body> <form method="post" action="penalty.php"> <input type="hidden" name="goalie1" value="<?=$goalie?>"> <!-- store the goalie value in a hidden field --> <input type="checkbox" name="angle" value="1"> <input type="submit" name="btnSubmit" value="Submit"> </form> </body> </html> penalty.php <?php $goalie = $_POST['goalie']; $angle = $_POST['angle'] ... ?>
-
You will need to process the query results differently if you are not using PDO. Try <?php $sqlsn = "SELECT system_name FROM tbl_sub_systems WHERE section=\"21a\""; $rssn = mssql_query( $sqlsn, $conn) or die ("Cannot execute"); // // read data into an array first // $rows = []; while ($row = mssql_fetch_row($rssn)) { $rows[] = $row[0]; } // // now chunk this array // $data = array_chunk($rows,2); echo "<table border=\"1\">"; foreach ($data as $row) { echo "<tr>"; if (count($row)==2) { foreach ($row as $n) echo "<td>".$n."</td>"; } else { echo "<td colspan=\"2\">".$row[0]."</td>"; } echo "</tr>"; } echo "</table>"; ?>