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
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
Share on other sites

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 by liongold
Link to comment
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
Edited by Barand
Link to comment
Share on other sites

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.