Jump to content

Barand

Moderators
  • Posts

    24,573
  • Joined

  • Last visited

  • Days Won

    824

Everything posted by Barand

  1. Are you sure you have matching postcode values? No hidden whitespace. And records that match the lidnummer?
  2. I am wondering if the lack of primary keys in your tables is a contributing factor Set up the tables and tried it - deletion worked when run manually. mysql> insert into lid values -> (1, 'A', 'B','C','D'), -> (2, 'A', 'B','F','D'); Query OK, 2 rows affected (0.07 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> insert into postcode values -> ('C', 'aaa', 'bbb'), -> ('F', 'ccc', 'ddd'); Query OK, 2 rows affected (0.04 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> DELETE lid, postcode FROM lid INNER JOIN postcode WHERE lid.postcode = postcode.postcode AND lid.lidnummer = 2; Query OK, 2 rows affected (0.05 sec) mysql> select * from lid; +-----------+----------+------------+----------+------------+ | lidnummer | voornaam | achternaam | postcode | huisnummer | +-----------+----------+------------+----------+------------+ | 1 | A | B | C | D | +-----------+----------+------------+----------+------------+ 1 row in set (0.00 sec) mysql> select * from postcode; +----------+-------+------------+ | postcode | adres | woonplaats | +----------+-------+------------+ | C | aaa | bbb | +----------+-------+------------+ 1 row in set (0.00 sec)
  3. Can you post the structures of your "lid" and "postcode" tables for us.
  4. The purpose of using prepared statements is so you don't put values directly into the query itself. Instead you use a "placeholder" for the value and pass the value in the execute statement. $query = " SELECT * FROM task_list WHERE user_id = ? ORDER BY task_list_id DESC "; $statement = $connect->prepare($query); $statement->execute( [ $_SESSION["user_id"] ] ); There is another commonly used convention when using a database: if you want to produce a list of data items from a table then execute a query against that table. Querying the task_list table in order to get a list of lockups ain't going to work too well.
  5. foreach ($data as $name => $paid_arr) { $tdata .= "<tr><td>$name</td>"; foreach ($paid_arr as $p) { $cls = $p=='N' ? 'hilite' : ''; $tdata .= "<td class='$cls'>$p</td>"; } $tdata .= "</tr>\n"; }
  6. Give your tables meaningful names that describe the entity being stored in the table. Looking at the XML then perhaps the name would be "lockup". There is a requirement that each row in a table should have unique identifier otherwise you cannot edit/delete rows. The easiest way is use an auto_incrementing value that guarantees uniqueness. CREATE TABLE lockup ( lockup_id int not null auto_increment primary key, mediaurl varchar(60), imagename varchar(60), title varchar(60) );
  7. https://dev.mysql.com/doc/refman/5.7/en/char.html
  8. You need to rewrite this line ... $tdata .= "<tr><td>$name</td><td>" . join('</td><td>', $paid_arr) . "</td></tr>\n"; so you output the name then loop through the $paid_array.
  9. Looks like you've got some debugging to do. We can't do that for you.
  10. 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.
  11. Databases like "yyyy-mm-dd" format for dates
  12. $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
  13. 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>
  14. 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?
  15. 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
  16. 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.
  17. $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"; }
  18. 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
  19. 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>&nbsp;</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>"; } ?>
  20. Is that really your code? An insert query that won't work and an html table with no rows.
  21. 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)
  22. Without any context I haven't a clue what you are talking about.
  23. 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\" )
  24. I don't use phpMyAdmin, but have you tried http://localhost/phpmyadmin in your browser?
×
×
  • 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.