Jump to content

PHP MySQL Problem


liongold

Recommended Posts

I have a problem with a part of a function I have built. This part basically gets selects from the database those rows which have field1 as equal to $r['fieldx'] and echo them. When I try mysql_error() nothing gets put but when I do die("Error"), it gives Error so there is a problem with mysql_fetch_array(). Please help me because I've been trying to find the error for ages but still can't.

$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
                };
Link to comment
https://forums.phpfreaks.com/topic/284350-php-mysql-problem/
Share on other sites

A while loop not executing could be the result of no matching data.

 

Try simplifying the query

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

(judging by those column names it looks like that table is a good candidate for normalization)

Link to comment
https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460507
Share on other sites

The query you are running is not the same as the one I suggested

 

Mine

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

Yours

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

If you echo my version you get

SELECT * FROM TBL WHERE confirmed = '1' 
        AND 'TST' IN (test1, test2, test3, test4)

If you echo your version you get

SELECT * FROM TBL_USERS WHERE confirmed = '1' 
        AND '{TST}' IN (test1, test2, test3, test4)

This because {..} has special significance when embedding variables in a double-quoted string. See http://www.php.net/manual/en/language.types.string.php

 

EG

$var = 'World';
echo "Hello $var!";     //--> Hello World!
echo "Hello {$var}!";   //--> Hello World!
echo "Hello {".$var."}!"; //--> Hello {World}!     - your version equivalent
Link to comment
https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460770
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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