liongold Posted November 28, 2013 Share Posted November 28, 2013 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 }; Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/ Share on other sites More sharing options...
Barand Posted November 28, 2013 Share Posted November 28, 2013 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) Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460507 Share on other sites More sharing options...
liongold Posted November 29, 2013 Author Share Posted November 29, 2013 (edited) With this query: $getu = "SELECT * FROM ".TBL_USERS." WHERE confirmed = '1' AND '{."$fieldx['ShortVersion']."}' IN (test1, test2, test3, test4)"; it's still not working. No error messages. The query runs fine and reports no error. Edited November 29, 2013 by liongold Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460648 Share on other sites More sharing options...
Barand Posted November 29, 2013 Share Posted November 29, 2013 What do you get if you echo $getu; Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460651 Share on other sites More sharing options...
liongold Posted November 29, 2013 Author Share Posted November 29, 2013 Query was empty message. Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460652 Share on other sites More sharing options...
Barand Posted November 30, 2013 Share Posted November 30, 2013 $getu = "SELECT * FROM ".TBL_USERS." WHERE confirmed = '1' AND '{."$fieldx['ShortVersion']."}' IN (test1, test2, test3, test4)"; echo $getu; Post the output, it is not going to give that error message Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460675 Share on other sites More sharing options...
liongold Posted November 30, 2013 Author Share Posted November 30, 2013 SELECT * FROM table WHERE confirmed = '1' AND '{TST}' IN (test1, test2, test3, test4) Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460740 Share on other sites More sharing options...
liongold Posted November 30, 2013 Author Share Posted November 30, 2013 Since I want to be sure, you got me right. I am trying to make this a select statement to select all rows where $fieldx['ShortVersion'] is either in driver1 or driver2 or driver3 or driver4. The rows chosen also should have confirmed = 1 Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460745 Share on other sites More sharing options...
Barand Posted November 30, 2013 Share Posted November 30, 2013 The value you are searching for contains the curly braces ie "{TST}". Do any of your db table columns contain that value? Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460759 Share on other sites More sharing options...
liongold Posted November 30, 2013 Author Share Posted November 30, 2013 (edited) No they contain TST only. The { are from the query itself.. Edited November 30, 2013 by liongold Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460766 Share on other sites More sharing options...
Barand Posted November 30, 2013 Share Posted November 30, 2013 (edited) So now you know why it isn't working. '{TST}' != 'TST' Edited November 30, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460767 Share on other sites More sharing options...
Barand Posted November 30, 2013 Share Posted November 30, 2013 (edited) 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 Edited November 30, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460770 Share on other sites More sharing options...
liongold Posted December 1, 2013 Author Share Posted December 1, 2013 It now works. Thanks for helping. Quote Link to comment https://forums.phpfreaks.com/topic/284350-php-mysql-problem/#findComment-1460858 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.