Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Use prepared statements instead of putting user-provided variables directly in to the query <?php $stmt = $con->prepare("SELECT DISTINCT size FROM size INNER JOIN inventory ON size.idSize = inventory.idsize WHERE id_item = ? ORDER BY size "); $stmt->bind_param('i', $idd); $stmt->execute(); $stmt->bind_result($size); $opts = ""; while($row = $stmt->fetch() { $opts .= "<option value='$size'>$size</option>\n"; } ?> <form action='' method="post"> <select name='size' id="size" class='size'> <?=$opts?> </select> </form>
  2. What, precisely, are the table structures here. Your second query of the UNION above seems to be getting litter dates from the owner table(???). Does your dog table hold every dog from every litter? How do know when an owner still holds a bitch from a particular litter? You mention breeder_id and owner_id - are these diffrerent entities or are the terms interchangeable?
  3. Given your initial table and your desire to find active kennels, then table: kennel +-----------+------------+--------------+-------------+--------------+----------------+ | kennel_id | kennelname | first_litter | last_litter | oldest_bitch | youngest_bitch | +-----------+------------+--------------+-------------+--------------+----------------+ | 1 | green | 2006-01-15 | 2020-08-02 | 2002-01-06 | 2020-08-02 | | 2 | red | 2007-11-19 | 2007-11-19 | 2005-01-29 | 2011-05-14 | | 3 | blue | 1997-11-26 | 2011-12-18 | 1994-10-22 | 2006-12-19 | | 4 | yellow | 2014-03-22 | 2019-06-29 | 2010-12-02 | 2013-10-07 | | 5 | silver | | | 2016-11-08 | 2016-11-08 | | 6 | black | | | 2002-02-23 | 2009-05-28 | +-----------+------------+--------------+-------------+--------------+----------------+ query SELECT kennelname , CASE WHEN timestampdiff(YEAR, last_litter, CURDATE()) < 8 OR timestampdiff(YEAR, youngest_bitch, CURDATE()) < 8 THEN 'Active' ELSE '' END as 'active' FROM kennel results +------------+--------+ | kennelname | active | +------------+--------+ | green | Active | | red | | | blue | | | yellow | Active | | silver | Active | | black | | +------------+--------+ But I am not sure that is solving your real problem.
  4. Is the table of data at the top of your post supposed to be any way related to the query at the bottom of the post? I don't see a connection.
  5. Or you can do it without any concatenation operators. $root = './dir1'; $structure = "$root/dir2/dir3/dir4/dir5/dir6";
  6. As far as I know, self closing tags have been consigned to history and are no longer required. Just use ">" instead of "/>"
  7. str_replace takes an array of search string and a corresponding array of replacement strings, so... $source = ' {% snippet "header" %} yada yada {% setting "X" %} yada yada {% collection "stamps" %} blah blah {% snippet "footer" %} '; $html = str_replace( [ '{% snippet ', '{% collection ', '{% setting ', '%}' ], [ '<x-snippet name=', '<x-collection name=', '<x-setting name=', '/>' ], $source ); echo '<pre>' . htmlentities($html) . '</pre>'; Giving... <x-snippet name="header" /> yada yada <x-setting name="X" /> yada yada <x-collection name="stamps" /> blah blah <x-snippet name="footer" />
  8. Try $html2 = str_replace( ['{% snippet ', '%}'], ['<x-snip name=', '/>'], $html);
  9. BTW,, the fopen() and fclose() are redundant if you are using file_get_contents()
  10. Or maybe opening your referral links in a new tab would help ... <a href="https://myWebsite/link.php?Referer=RefererCompany&SKU=XYZ" target="_blank">Sell Here</a> ... so that the page isn't replaced. As Gizmola stated, we have no idea of your user interface and processes so we can only stumble around in the dark
  11. Perhaps use AJAX to get the referred SKU so you you don't leave the page?
  12. Your problem is with $iduser It is the result of the first query yet you are attemping to insert it as a value in the second query. You need to fetch the id from the resultset to use its value.
  13. Try swapping $file1 and $file2 echo '<pre>' . print_r(array_diff($file1, $file2), 1) . '</pre>';
  14. In that case why is there a SELECT query again? All you need to do is UPDATE from the post data. You are posting data but trying to get the id from GET - put the id in a hidden form field and get it from the POST data
  15. Where has all the site's activity gone?. It is telling me there is none and there never has been any
  16. My code is the whole script to compare 2 text files and show the differences. Run it on its own but you will have to adjust for the names of your text files.
  17. At what point in the above process is the form supposed to be displayed to the user for editing? You have a SELECT query presumably to get the data to display for editing. You then launch immediatley into updating with the posted data
  18. Perhaps... FILE 1 FILE 2 --------------------------------- --------------------------------- Twas brillig and the slithy toves Twas brillig and the slithy toves did gyre and gimble in the wabe. did gyre and gimble in the wabe. All mimsy were the borogoves All mimsy were the borogoves and the mome raths outgrabe. and the mome raths outgrabe. additional line 1. additional line 2. then $file1 = file('file1.txt', FILE_IGNORE_NEW_LINES); $file2 = file('file2.txt', FILE_IGNORE_NEW_LINES); echo '<pre>' . print_r(array_diff($file2, $file1), 1) . '</pre>';
  19. I would recommend that, while developing, you should use E_ALL with no suppression of the other levels.
  20. If you have the settings that you want in the ini file, why override them with E_ALL in your webpage?
  21. If your query returns no results then the while() loop doesn't execute. $table is defined only when the loop does execute.
  22. I created an "images" table like yours. Here is basic working code sample. The folder containing the script has a subfolder "images". <?php include 'config.php'; $res = $db->query("SELECT file_name , game FROM images "); ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Test</title> <style type='text/css'> .wrapper { text-align: center; padding: 20px; border-bottom: 2px solid gray; } </style> </head> <body> <?php foreach ($res as $row) { echo "<div class='wrapper'> <img src='images/{$row['file_name']}' alt='Game image'> <br> {$row['game']} </div> "; } ?> </body> </html>
  23. Perhaps the path to the image is missing (we can't see your data). Does this work... <img class='w-100 mb-2 bg-dark' src=\"images/{$row['file_name']}\">
  24. Also, you have a button element inside a form. That will cause the form to be submitted and your page to reload when the button is clicked. Remove the <form> tags, or change the button element to a span element styled to look like a button, or suppress the default action when the button is clicked
  25. The biggest obstacle to that approach is that PHP does not have a CURRENT_DATE() function - it's a MySql function. If you had error reporting on, or used the reference manual, that would have given you a clue. date('Y-m-d') will use the current date by default so all the extra code above is redundant - which takes us back to the original solution you were given, yet ignored.
×
×
  • 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.