Jump to content

Barand

Moderators
  • Posts

    24,607
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. Not your best idea to publish a password in a public forum. I've obscured it but you should consider changing it. Try <select name="lorry" id="lorry" class="custom-select select-2"> <option value="all">All Lorries</option> <?php $mysqli = new mysqli('localhost', 'wwwbeechwoodsolu_collrystmusr', '********', 'wwwbeechwoodsolu_coal-lorry-system'); $sql = "SELECT id, lorry FROM lorries"; $result = $mysqli->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $sel = ($row['lorry'] == $_GET['lorry']) ? 'selected' : ''; echo "<option $sel >{$row['lorry']}</option\n"; } } ?> </select>
  2. You need to use a custom sort function with usort() usort($array['wh2d'], fn($a,$b)=>$a[1]<=>$b[1]); or, if you are uncomfortable with that syntax, ... usort($array'wh2d', 'mysort'); function mysort($a, $b) { return $a[1] <=> $b[1]; }
  3. You can't reference alias in the field list part of the query (they aren't allocated until the later output phase of the query. For instance, you can order by final), You need SELECT v.Total AS total, SUM(vt.numberofstudents) AS alunos, (v.Total/SUM(vt.numberofstudents)) AS final ... [edit] P.S. To summarize +---------+---------------------------+ | I/O | Query Clauses | +---------+---------------------------+ | | | | INPUT | SELECT ... | Column aliases | | FROM ... | defined but not | | WHERE ... | referenced | | | +---------+---------------------------+ | | | | | GROUP BY ... | Column aliases | OUTPUT | HAVING ... | can be referenced | | ORDER BY ... | here | | | +---------+---------------------------+
  4. Well, one use would be to identify which cells are in each 9x9 square
  5. If the individual cells are numbered 0 - 80 in 9 rows of 9 Then the index (0-8) of the large 3x3 square is given by function gridSquare($n) { return floor(floor($n/9) / 3) * 3 + floor($n % 9 / 3); } where $n i the nunber of the individual cell (0-80)
  6. If both databases are on the same server then you only need a single connection (A connection is made to the server, not a specific database. The database name in the connect function is just the default to use). This allows you you access two databases in a single query. Specify the database.tablename when referencing the tables. Suppose you want to copy tableA from DB1 to DB2... CREATE TABLE DB2.tableA LIKE DB1.tableA; INSERT INTO DB2.tableA SELECT * FROM DB1.tableA; If DB1 is the default, it can be omitted EG INSERT INTO DB2.tableA SELECT * FROM tableA;
  7. How is your data expected to look when received by the API? You've shown two separate sets of data so far - is that just to confuse us?
  8. What you have there won't report mysql errors, only php
  9. Have told mysql to report errors? ... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); just before you connect to your DB
  10. Shouldn't $user_id be $_SESSION['user_id'] in your bind_param() call? Do you have error reporting on? Why don't you just ... UPDATE users SET is_logged_in = 0 WHERE user_id = ? ... instead of creating another variable to bind?
  11. When something is "unexpected" the cause is usually whatever came before it. But you haven't shown us that.
  12. Welcome - enjoy your swim.
  13. Yes, don't use select * ... Also, there is no need to close a connection at the end of a page - php does this automatically for you.
  14. the id is unique, so you can't insert a second id of 26. Omit the id column from the query then the rest of the columns can be inserted (unless any are defined UNIQUE in which case you need to omit those too) $sql = "INSERT INTO $table (company_name) SELECT company_name FROM $table WHERE id = 26"; You can call a lastInsertId() function to get the id of the new record.
  15. The basic code is /* Current user data +----+----------+--------------+ | id | username | fullname | +----+----------+--------------+ | 1 | lucy | Lucy Lastik | | 2 | hugh | Hugh Jass | | 3 | tom | Tom DiCanari | +----+----------+--------------+ */ try { $stmt = $pdo->prepare("INSERT INTO user (username, fullname) VALUES (?, ?) "); $stmt->execute( [ 'lucy', 'Lucy Smith' ] ); // attempt duplicate insert } catch (PDOException $e) { if ($stmt->errorInfo()[1] == 1062) { // duplicate key error code $_SESSION['errors']['username'] = 'username already exists'; // error message to display to user when form redisplayed } else throw $e; // let php handle the error } Just convert it to Laravelese.
  16. The best way is to define the username as a unique key in your user table. That way you can't add another with the same name (an exception with be thrown if you attempt to add a second). Then check for duplicate key errors when adding users in you code.
  17. I cannot comment as I have absolutely no idea what your data looks like Then do that... $dt = new DateTime($match['matchDateTime']);
  18. Telling us that some thing isn't working tells us nothing. What should happen that isn't? What shouldn't happen that is? Your topic title mentions a database update. Where and what is that code? NOTE - use the code button (<>) when posting code.
  19. A. echo '<pre>' . print_r($match, true) . '</pre>'; B. $dt = new DateTime('2024-10-06T09:19:53.660Z'); echo $dt->format('D, d.m - h:i'); // Sun, 06.10 - 09:19
  20. Contact the printer manufacturer, they may aleady have android software and cable available for this purpose.
  21. I'm guessing the assignment deadline has passed, so for the sake of others reading the thread, here's one solution... <?php $a = 1; $b = 2; $c = []; $d = []; $N = 8; $tdata1 = $tdata2 = ""; $vals = []; for ($i=1, $a=1, $b=2; $i<=$N; $i++, $a+=2, $b+=2) { $c[] = $a; $d[] = $b; $exp = '<u>' . join('.', $c) . "</u><br>" . join('.', $d); $tdata1 .= "<td>$exp</td>"; $val = number_format(array_product($c) / array_product($d), 5) ; $tdata2 .= "<td>$val</td>"; } ?> <table border='1'> <tr><th>Fraction</th> <?=$tdata1?> </tr> <tr><th>Decimal</th> <?=$tdata2?> </tr> </table>
  22. FYI - 8 queens solution... The Pythagorean numbers were as much use as a chocolate teapot
  23. <!DOCTYPE html> <html lang="en"> <head> <title>4 Queens</title> <meta charset="utf-8"> <style type='text/css'> table { border-collapse: collapse; } td { width: 40px; height: 40px; text-align: center; font-size: 16pt; } tr:nth-child(odd) td:nth-child(even), tr:nth-child(even) td:nth-child(odd) { background-color: lightgreen; } </style> </head> <body> <?php echo '<table border="1">'; for ($i = 1; $i <= 4; $i++) { echo "<tr>"; for ($j = 1; $j <= 4; $j++) { echo '<td>' . pow($i,2) + pow($j,2) . '</td>'; } echo '</tr>'; } echo "</table>\n"; ?> </body> </html> Dear Supreme Being, Can you put aside your arrogance for a moment and assume that we are 5 year olds (not a wall) and explain the theory behind your Pythagorean solution to the problem and why it "works" explain how the above square then tells us where the four queens should be positioned? I've found the 5s but there are no "opposite 10s", only 20s opposite the 5s, so the description is somewhat vague.. Having found the 5s, 10s, 20s and 25s (why those values in particular?), I now have 8 squares. Given that these are the candidates, the code then needs to find which 4 of these 8 fit the bill.
  24. INSERT INTO user (fname,sex) values (inname, NULLIF(insex, '') );
×
×
  • 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.