kenoli Posted February 12, 2021 Share Posted February 12, 2021 I'm going bananas with one of those issues where it looks like everything is right but the code won't work. I've included a script below that fetches data from a database and creates a drop down menu. I'm trying to use a field called "gone" and enter 'gone' in that field when I want to delete the row but be able to retrieve it by making the field empty. There is something in the WHERE clause of my sql that is screwing things up. I get nothing retrieved with any of the WHERE clauses below. Interestingly, when I take the where clause out completely, I get the rows that have no 'gone' in them. The code is below. None of the following in the included code get me a result. All of them return nothing. I also don't get any errors. Just nothing. WHERE gone != 'gone' WHERE gone <> 'gone' WHERE gone = '' WHERE gone = 'gone' Without the WHERE clause it runs fine. As a work around I tried using if($row['gone'] == 'gone') { continue;} In the while.. function at the end of the file to bypass rows with 'gone' in the field. It also stopped the script. Here's my code: <?php // person_selectall.php /** Create new pdo object */ require 'Db.php'; //$sql = "SELECT person_id, fname, lname FROM Persons"; $sql = "SELECT * FROM Persons WHERE gone = ''"; $stmt = $pdo->prepare($sql); $stmt->execute(); echo "<p><select class=\"select-field\" name=\"person_id\" >\n"; while ($row = $stmt->fetch()) { $name = $row['fname'] . ' ' . $row['lname']; echo "<option value=\"" . $row['person_id'] . "\">" . $name . "</option>\n"; } echo "</select>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/312137-problem-with-mysql-retrieval/ Share on other sites More sharing options...
Solution requinix Posted February 12, 2021 Solution Share Posted February 12, 2021 Is "gone" nullable? 30 minutes ago, kenoli said: It also stopped the script. Meaning what, exactly? Quote Link to comment https://forums.phpfreaks.com/topic/312137-problem-with-mysql-retrieval/#findComment-1584421 Share on other sites More sharing options...
kenoli Posted February 12, 2021 Author Share Posted February 12, 2021 (edited) 1 hour ago, requinix said: Is "gone" nullable? I think so. I was wondering if it had something to do with the issue, but not sure how to handle it. I went through the table and deleted all the NULLs. Meaning what, exactly? Nothing gets extracted from the table. My dropdown select menu has no data. Edited February 12, 2021 by kenoli Quote Link to comment https://forums.phpfreaks.com/topic/312137-problem-with-mysql-retrieval/#findComment-1584425 Share on other sites More sharing options...
kenoli Posted February 12, 2021 Author Share Posted February 12, 2021 I figured out how to make that column not nullable and now it is working. Thanks, that solved the problem. --Kenoli Quote Link to comment https://forums.phpfreaks.com/topic/312137-problem-with-mysql-retrieval/#findComment-1584426 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.