-
Posts
24,603 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
If only PHP had a way you could increment a count. $i = 0; $content = ' <style> td { font-weight: normal; font-size: 8px; line-height: 12px; color: #000000; } </style> <table id="receiptTable" style="max-height: 1000px;" > <tr> <td width = "7%" > '. ++$i .' </td> <td width= "8%" > '.'xxxxxx'.' </td> <td width= "10%" > '.'xxxxxx'.' </td> <td width= "30%"> '.'123'.' '.'Kg'.' </td> <td width= "20%" > RM '.'123.45'.' </td> <td width= "20%" > RM '.'123.45'.' </td> </tr> <tr> <td width = "7%" > '. ++$i .' </td> <td width= "8%" > '.'xxxxxx'.' </td> <td width= "10%" > '.'xxxxxx'.' </td> <td width= "30%"> '.'123'.' '.'Kg'.' </td> <td width= "20%" > RM '.'123.45'.' </td> <td width= "20%" > RM '.'123.45'.' </td> </tr> <tr> <td width = "7%" > '. ++$i .' </td> <td width= "8%" > '.'xxxxxx'.' </td> <td width= "10%" > '.'xxxxxx'.' </td> <td width= "30%"> '.'123'.' '.'Kg'.' </td> <td width= "20%" > RM '.'123.45'.' </td> <td width= "20%" > RM '.'123.45'.' </td> </tr> </table> '; OUTPUT
- 1 reply
-
- 1
-
-
PHP runs on the server, javascript runs on the client after the PHP has finish running and sent the page to the client. Store $PAGE in a hidden field in your html <input type="hidden" id="page-name" value="<?=$PAGE?>" > In your script you can then access it with var page = $("#page-name").val() then send it i your ajax request $.post( "script.php", {"page":page}, // data function(content) { $("#notif").html(content) }, "TEXT" ) In script.php, access the page from $_POST['page]
-
It would appear that some CSS is implemented (such as font-size, line-spacing, color and other basics) but others are not. Your counter appears to be in those that are not. Those that do work can be in a <style> section or in-line. There may be a list in the documentation, who knows? If there were a prize for the worst documentation, tcpdf would win it outright. I have to resort to examining the source code to find out what arguments each method requires and what it does. For the counter you may have to resort to the age-old method of outputting an incremented counter variable.
-
Another way is to give the checkbox form input the value you actually want when it is set (ie "1") <input class="form-check-input" type="checkbox" id="a201" name="a201" value="1"> then $score = $_POST['a201'] ?? 0; which means "if the checkbox exists and is not null, use its value, otherwise default to "0". (See Null Coalesce operator)
-
Why can it not be as simple as ... $res = $db->query("SELECT user_id , month , year , description , CASE is_UBC WHEN 1 THEN 'Yes' ELSE '' END as ubc FROM dbert ORDER BY year, month "); $tdata = ''; foreach ($res as $r) { $date = sprintf("%02d/%4d", $r['month'], $r['year']); $tdata .= "<tr><td>{$r['user_id']}</td> <td>{$r['description']}</td> <td>{$r['ubc']}</td> <td>$date</td> </tr>\n"; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf8"> <title>Sample</title> <style type='text/css'> table { width: 800px; border-collapse: collapse; } th, td { padding: 5px; } </style> </head> <body> <table border="1"> <tr><th>User ID</th> <th>Description</th> <th>UBC</th> <th>Date</th> </tr> <?=$tdata?> </table> </body> </html>
-
Strange I know, but I couldn't get that picture of your code to execute. Also, this looks suspiciously like homework - read the guidelines
-
Something like ... $appID = 1; $statement = $conn->prepare("SELECT f.survey_date , r.firstname , f.feel , f.cough , f.fever , f.headache , f.tired , f.appetite , f.swelling FROM tb_feedback f INNER JOIN tb_register r ON r.id = f.user_id WHERE f.app_ID = ? "); $statement->bind_param('i', $appID); $statement->execute(); $res = $statement->get_result(); $data = []; foreach ($res as $r) { if (!isset($data[$r['survey_date']])) { $data[$r['survey_date']] = [ 'datetime' => $r['survey_date'], 'history' => [] ]; } $data[$r['survey_date']]['history'][] = array_slice($r, 1); } $jdata = json_encode( ['Data' => array_values($data)] ); echo $jdata;
-
First of all, don't run queries inside a loop like that. Just use a single query. When processing the query results put the data into an array with the structure required for your JSON data json_encode the array.
-
The function definition clearly shows that it takes only 3 arguments - table, field, condition. In your second call you are passing 5 so the final 2 are ignored. Try $count_long_trades_pos = $db->getQueryCount('tbl_trades','lg_short_trade',' AND lg_short_trade="Long" AND pnl_trade > 0 AND num_bot_trade="'.$_REQUEST['editId'].'"'); Secondly, I don't know what the other functions in your database class are like but that one should be consigned to the trash bin... Incorrect use of prepared statements The query will wil return one row with one column (the count), so why return fetchAll() which is for multiple rows?, and why not just return the record count? The if() condition in the middle is waste of code
-
Curiously your table structure (from phpMyAdmin) shows year and month in separate columns yet your code is exploding datecolumn using "/"? What does this output... echo '<pre>'; var_export($data); echo '</pre>';
-
None with out knowing what the data you are processing looks like.
-
I have no idea how the function getQueryCount() is defined or what arguments it expects, but you appear to be passing 3 arguments in the one that works and 4 5 in the one that fails. Check your reference manual. Arguments... Array ( [0] => tbl_trades [1] => lg_short_trade [2] => AND lg_short_trade="Long" AND num_bot_trade="42" ) Array ( [0] => tbl_trades [1] => lg_short_trade [2] => AND lg_short_trade="Long" [3] => pnl_trade [4] => AND pnl_trade > 0 AND num_bot_trade="42" )
-
Take your pick, sql or php solution? $theDate = '2021-04-18 10:45:26'; $d1 = new DateTime($theDate); $elapsed = $d1->diff(new DateTime())->days; echo $elapsed; //--> 23 or SELECT datestarted , datediff(CURDATE(), datestarted) as elapsed FROM ...
-
1 ) Use code tags ("<>" button in the toolbar). I have edited your posts so far; in future I'll delete any vast tracts of code.. 2 ) Post relevant code - I doubt anyone will bother wading through all the code you posted. https://forums.phpfreaks.com/guidelines/
-
It is slightly different from yours A set of selections is valid only for a selected game, whereas yours is valid for 19 games. I update the database with each selection as soon as it is clicked (recording game_id/user_id/square_id) There is no on-line monetary collection. You paid the club treasurer in cash. One problem was that no-one wanted to bet on my team's score ending (or starting) with anything other than zero, even though I remember we did score once.
-
Oh right. It's one of those. I wrote an application like that about three years ago. If you want to display what has been selected then hidden fields don't seem the best option to me
-
Probably one of his other clients caught up with him In which case, sqNum_64 is the only one out of the hundred that won't give you an error. Do as mac_gyver suggested and name your inputs ... name="sqNum[n]" where n is a number from 1 to 100. You can then process the input withsomething like ... foreach ($_POST['sqNum'] as $i => $val) { // process $i } Out of curiosity, what does the input form code look like and what is it supposed to do?
-
What does your POST array actually contain? Put this before the for() loop. echo '<pre>' . print_r($_POST, 1) . '</pre>';
-
Open the txt file before the loop and close it after the loop.
-
Use the "<>" button when posting code. All I can tell you from the information given is "Something went wrong". Whey don't you get mysqli to tell you what went wrong. The easiest way is to put this line of code just above the line where you create your mysqli connection mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
-
You were complaining that the code sample I gave you didn't use the functions in your CMS. As I don't have your CMS, or even the function documentation for it, there would be no way I could test the code before posting. You are not being denied help. I am saying that under those restrictions, I personally cannot help. There are plenty of others on this forum willing to help. Also, any solutions I post here are not just for you but for others who may come along later looking for a solution to a similar problem, and they too will probably not use your CMS.