Jump to content

Problem with mysql retrieval


Go to solution Solved by requinix,

Recommended Posts

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>";

?>

 

Link to comment
https://forums.phpfreaks.com/topic/312137-problem-with-mysql-retrieval/
Share on other sites

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 by kenoli
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.