-
Posts
24,615 -
Joined
-
Last visited
-
Days Won
835
Everything posted by Barand
-
Remembering Tabulator $_GET vars in a Session
Barand replied to mongoose00318's topic in PHP Coding Help
Looks like you've got some debugging to do. We can't do that for you. -
https://www.php.net/manual/en/mysqli-stmt.bind-param.php https://www.php.net/manual/en/mysqli-stmt.execute.php or use a PDO connection as I did.
-
Databases like "yyyy-mm-dd" format for dates
-
Remembering Tabulator $_GET vars in a Session
Barand replied to mongoose00318's topic in PHP Coding Help
$setting = $_GET['setting'] ?? $_SESSION['setting'] ?? 'default'; $_SESSION['setting'] = $setting; … which does the following If the user has provided a value via GET, use that value. If there is no new GET value use the SESSION value if it exists If neither exist, use a default value Save the value -
Easiest way I know is first to store your query data in an array that has the same structure as your required output <?php $start = '2020-03-01'; // // Query to get column headings // $res = $conn->prepare("SELECT DISTINCT month(month) as mno , monthname(month) as mname FROM fee WHERE month >= ? ORDER BY mno "); $res->execute([$start]); $heads = []; foreach ($res as $row) { $heads[$row['mno']] = $row['mname']; } $empty_array = array_fill_keys(array_keys($heads), ''); // // now process the fee data and store in an array // $data = []; $res = $conn->prepare("SELECT name , month(month) as mno , paid FROM fee WHERE month >= ? ORDER BY name, month "); $res->execute([$start]); foreach ($res as $row) { if (!isset($data[$row['name']])) { $data[$row['name']] = $empty_array; } $data[$row['name']][$row['mno']] = $row['paid']; } // // now output the array // $theads = "<tr><th>Name</th><th>" . join('</th><th>', $heads) . "</th></tr>\n"; $tdata = ''; foreach ($data as $name => $paid_arr) { $tdata .= "<tr><td>$name</td><td>" . join('</td><td>', $paid_arr) . "</td></tr>\n"; } ?> <html> <head> <title>Sample</title> <style type="text/css"> body, table { font-family: verdana, sans-serif; font-size: 11pt; } table { width: 400px; } th { background-color: black; color: white; } td { text-align: center; } </style> </head> <body> <table> <?=$theads?> <?=$tdata?> </table> </body> </html>
-
Each section in the XML contains media url image name title By happy coincidence, the form code that you posted asks the user to input: media url image name title Given the above, what do you think your table should contain?
-
You have a form for the user to enter data for those sections of xml, so now you need a table to store them, code to process the form data and store it (including uploading the image files and storing those) code to retrieve those items from the and output the xml
-
Is there now a table in your database called "task_list" with those columns defined? If there is, you may assume it worked. If not, it didn't.
-
$res = $db->query("SELECT name , timestampdiff(MONTH, doj, curdate()) as sen , timestampdiff(YEAR, dob, curdate()) as age FROM MEMBER ORDER BY sen DESC, age DESC "); $members = $res->fetchAll(); $titles = ['Leader', 'Assistant', 'Member 1', 'Member 2', 'Member 3', 'Member 4', 'Member 5', 'Member 6', 'Member 7', 'Member 8']; I originally set out on the round-robin route to allocate the members to teams ... $teams = []; $t = 0; foreach ($members as $r) { $teams[$t%6][] = $r; $t++; } ... but the problem with this method is it's bias. Team 1 gets the most experienced Leader and Team 6 gets the least experienced. On the next cycle, Team 1 gets the most experienced Assistant and Team 6 again gets the least, and so on for all levels. Therefore I'd recommend an approach which gets the players for each level then shakes the bags before allocating to teams $ranks = array_chunk($members, 6); // get a chunk of 6 members for each rank $tdata = ''; foreach ($ranks as $r => $rmembers) { shuffle($rmembers); // shake the bag - random allocation to teams $tdata .= "<tr><td class='rank'>{$titles[$r]}</td>"; foreach ($rmembers as $m) { $tdata .= "<td>{$m['name']} <span class='years'>({$m['sen']}/{$m['age']})</span></td>"; } $tdata .= "</tr>\n"; }
-
Could be written as $updatedID = isset($_POST['IDs']) ? $_POST['IDs'] : 0; Which, in turn, could be written as if (isset($_POST['IDs']) { $updatedID = $_POST['IDs']; } else { $updatedID = 0; } A "ternary" expression is a conditional assignment $myvar = condition ? <value if condition is true> : <value if condition is false> https://www.php.net/manual/en/mysqli.prepare.php
-
Try here
-
Reorganised it a bit <?php $table = 'puptest'; $msg = ''; $updatedID = $_POST['IDs'] ?? 0; if ($_SERVER['REQUEST_METHOD']=='POST') { $sql = "UPDATE $table SET comment=? WHERE id=?"; $stmt = $conn->prepare($sql); $stmt->bind_param ('si', $_POST['comment'], $_POST['IDs']); if ($stmt->execute()) { $msg = '<br>SUCCESS'; } else { $msg = '<br>FAILED'; } } $sql = "SELECT id , firstname , other , comment FROM $table "; $result = $conn->query($sql); if ($result->num_rows > 0) { echo "<table border='1'> <tr><th>ID</th> <th>Name</th> <th>Other</th> <th>Comment</th> <th> </th> </tr>"; while ($row = $result->fetch_assoc()) { $message = $updatedID == $row['id'] ? $msg : ''; // is this the row that was updated? echo "<tr> <form method='POST'> <td>{$row['id']}</td> <td>{$row['firstname']}</td> <td>{$row['other']}</td> <td><textarea name='comment' cols='30' rows='5'>{$row['comment']}</textarea></td> <td> <input type='submit' name='submit' value='Save text' /> <input type='hidden' name='IDs' value='{$row['id']}'> $message </td> </form> </tr>"; } echo "</table>"; } ?>
-
Is that really your code? An insert query that won't work and an html table with no rows.
-
I understand now what you are trying to do. What I don't understand is why the **** you are using a js file to store data. If you don't want to use a category table in a database, use something like an ini file (easy to maintain), for example category.ini [itc_profile_update] 1="ITC Profile Update" 2="itc_profile_update_qt" [vehicle_sales] 1="Vehicle Sales" 2="Vehicle_Sales_qt" [general_non_finance] 1="gen_none_fin" 2="general_non_finance_qt" [legal] 1="Legal" 2="legal_qt" Then in php it's... $categories = parse_ini_file('category.ini', 1); $complaint_type = 'general_non_finance'; echo $categories[$complaint_type][1]; // --> gen_none_fin To use the data in js, use an ajax call which returns json_encode($categories)
-
Without any context I haven't a clue what you are talking about.
-
Easier to use file(). <?php $data = file('paulq.txt', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); $start = "sales_probability_dom"; $results = []; $pos = array_search($start, $data); // find start key while ($data[++$pos][0]=="\t") { // check for tab at start of line $results[] = trim($data[$pos]); } echo '<pre>', print_r($results, 1), '</pre>'; ?> giving Array ( [0] => @clear [1] => \"\": \"\" [2] => Closed Won: \"100\" [3] => Id. Decision Makers: \"40\" [4] => Needs Analysis: \"25\" [5] => Negotiation\/Review: \"80\" [6] => Perception Analasis: \"50\" [7] => Proposal\/Price Quote: \"65\" [8] => Prospecting: \"10\" [9] => Qualification: \"20\" [10] => Value Prospecting: \"30\" )
-
I don't use phpMyAdmin, but have you tried http://localhost/phpmyadmin in your browser?
-
Have you tried looking in the phpMyAdmin folder in that list?
-
I downloaded the class and gave it a try. This creates a pdf doc with a separate page (image and name) for each person. <?php require '../tcpdf/tcpdf.php'; $names = [ "ماشوت محمد علي علام" , "منى طه أبو العلا شعلان" , "وليد عبد العزيز السيد الشيخ" , "ابراهيم عبد السلام خلف" , "احمد حمدى نوار" ]; $pdf = new tcpdf(); $pdf->SetFont('aefurat', '', 30); $pdf->SetTextColor(255); foreach ($names as $name) { $pdf->AddPage(); $pdf->Image('images/snowman.png',15,15,180,180); $pdf->setY(40); $pdf->cell(0,15,$name,0,1,'C'); } $pdf->output('Sample.pdf', 'I'); ?> Output (greatly reduced)
-
MySQL / PHP - IF/AND/OR Statements - Getting Confused
Barand replied to djb2002's topic in PHP Coding Help
When mixing AND and OR in expressions, use parentheses to make the logic explicit. For example, instead of if (A AND B OR C) use one of these, depending on what you mean if ( (A AND B) OR C ) or if ( A AND ( B OR C ) ) -
If you want to print then I would take the pdf route, placing the png image in the output then, again, overwriting the text. TCPDF appears to support Arabic
-
Plan C - Embed the png image in the svg image and overlay with the name <?php $name = 'لقمان ابراهيم عباس عجلان'; $im = "<svg width='500' height='500'> <image x='0' y='0' width='500' height='500' xlink:href='images/snowman.png' /> <text x='250' y='110' text-anchor='middle' style='font-family:calibri; font-size:30pt; fill:#FFF;'>$name</text> </svg> "; echo $im; ?>
-
Plan B - vector graphics <?php $name = 'لقمان ابراهيم عباس عجلان'; $im = "<svg width='500' height='100'> <rect x='1' y='1' width='499' height='99' style='fill:#000; stroke:#000' /> <text x='20' y='60' style='font-family:calibri; font-size:30pt; fill:#FFF;'>$name</text> </svg> "; echo $im; ?>
-
Try a change of font. It works with "calibri" <?php $name = 'لقمان ابراهيم عباس عجلان'; $im = imagecreatetruecolor(500,100); $tcolor = imagecolorallocate($im,255,255,255); imagettftext($im, 20, 0, 20, 60, $tcolor, 'c:/windows/fonts/calibri.ttf', $name); header("Content-type: image/png"); imagepng($im); imagedestroy($im); ?> result
-
I guess it's true: "Test data is that data for which the query works", so mine only has the one overlap I put in deliberately to see if I could find it.