Jump to content

soycharliente

Members
  • Posts

    1,416
  • Joined

  • Last visited

Everything posted by soycharliente

  1. I don't need help anymore. I spent the last 30-45 minutes painstakingly laying out my problem only to figure it out just before hitting submit while reading it over one final time. So, thank you for continuing to offer this forum as a resource online so I could do some rubber duck debugging. I haven't been active on here in quite a while, so I am glad to be doing some programming again so I can start contributing content/answers more. Solution: I copied some code from the PHP manual and forgot to change the variable being referenced by mysqli_commit from the example variable to my database connection reference. (And didn't notice over the course of ~2 hours.) When borrowing code, don't forget to use your variables everywhere! I cannot figure out why my mysqli prepared statement is not inserting into the database. I am not showing any errors anywhere. AUTO_INCREMENT is advancing by 1 each time which is strange. I can't view the prepared statement, but a manual INSERT in phpMyAdmin with what I believe is a valid query works fine. I am completely stuck and have no idea which way to go. Any help is much appreciated. PHP version: 7.4.19 MySQL version: 5.6.48-88.0 index.php database.php phpMyAdmin SQL dump
  2. Ahhhh. I am teaching myself JOIN and I found example code that I tried to rewrite. That totally makes sense. The IFNULL part was something I read on SO and they said it was needed. I couldn't ever get 0 to show up when I used COUNT alone. Maybe I made more than one change at the same time without realizing and adding the INFULL combined with some other change got it working. When I added it the 0 counts started showing up. I still don't fully understand what the IFNULL part was doing, but my code isn't live yet and I was still trying to understand it before pushing it out. Guess I don't have to worry about that now. lol. Thanks for this rewrite.
  3. Hello! I'm trying to display a list of clients and count the number of items they have in another table including clients that have a count of 0. The structure of my two tables looks like this: clients ---------- id name items ---------- id client_id item_id The query I have so far is: SELECT c.*, IFNULL(COUNT(i.item_id), 0) as numItems FROM clients c LEFT JOIN items i on c.id = i.client_id GROUP BY i.client_id ORDER BY c.name I'm close, but it stops at the first client with 0 items and doesn't show anymore clients. If that client with 0 items finally gets some items, the next client with 0 items appears in the list. I'm not sure what I'm missing. This is the closest I've gotten and I'm now stumped from reading around here and SO. Thanks for a fresh pair of eyes.
×
×
  • 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.