Paul
Paul

Reputation: 551

MySQL PHP Database and String Comparison

In php I am comparing a file name to a file on a database which keeps coming up false and I am unsure why. Here is some code. Any idea why this may be happening or how I can redo the code? Thanks

EDIT: In the picture we have the filename at the top with an array of files outputting from the DB and as you can see both filename and the array index match up. Is this a conversion error of some sort?

        $cols = Array ("filename");
        $audioFiles= $db->get ("AudioFiles", null, $cols);
        $dbFile = "";

        echo $fileName;
        if ($db->count > 0)
        {
            foreach ($audioFiles as $audioFile) 
            { 
                echo "<pre>";
                var_dump ($audioFile);
                echo "</pre>";
                if ($audioFile == $fileName)
                {
                    echo "yes";
                }
                else
                {
                    echo "NOPE!";
                }
            }
        }

enter image description here

Upvotes: 0

Views: 45

Answers (1)

meda
meda

Reputation: 45490

You cannot compare an array to a string try this:

if ($audioFile['filename'] === $fileName)

Upvotes: 3

Related Questions