mysql_fetch_array() problem

I have this code as part of a function but for any reason the while loop is not running. This is the code:

$get = "SELECT * FROM ".TBL." WHERE test = '1' && (test = '".$fieldx['ShortVersion']."' || test2 = '".$fieldx['ShortVersion']."' || test3 = '".$fieldx['ShortVersion']."' || test4 = '".$fieldx['ShortVersion']."')";
                $getprocess = mysql_query($get) or die(mysql_error());
                echo "<br>Awarding ...";
                //Debug ready till here
                while($getup = mysql_fetch_array($getprocess)) {
                    // This does not run
                };  

When I add or die(“error”.mysql_error()) to the mysql_fetch_array(), it shows “error” but nothing related to mysql. Can someone help please?

Well try not to use MySQL extensions such as mysql_query and mysql_fetch_array as they are deprecated. Instead, use mysqli or PDO classes/objects will significantly improve your script.

For your problem, it seems that the query did not return any results. Either there is no record with the criterion you specify, or that there is a syntax error in SQL string.

Is TBL realy your table name?

I would write FROM “.TBL.” WHERE as FROM TBL WHERE

What is the result of echo $get; and echo mysql_error();

I fixed it by doing this:

$get = "SELECT * FROM ".TBL." WHERE test = '1'
        AND '{$fieldx['ShortVersion']}' IN (test1, test2, test3, test4)";

. I researched a little to find it out but it’s running fine.

MySQL doesn’t support ||, use OR instead.
Though I do like your second variant with IN better because it’s shorter and more readable.

Aah, thanks to you I found the reason why the first version was not working. Yeah, the new one is much better.

Where you concatenate the table name into your query ( $get = "SELECT * FROM ". TBL . "WHERE…) it does not have a $ symbol in front of the TBL variable. Maybe that is causing a problem.

Nevermind, TBL must be a constant so my suggestion is irrelevant…