ICEcoffee Posted April 24, 2006 Share Posted April 24, 2006 Hi allI am having a problem with the following statement - ie it doesn't work.$qualyq = ('SELECT * FROM t_qualy_results WHERE t_qualy_results.RaceID = "$row[RaceID]"') or die(mysql_error());$qualyr = mysql_query($qualyq) or die(mysql_error()); echo "<br> Driver and Points <br>"; while($qualyrow = mysql_fetch_array($qualyr)) { echo $qualyrow['Driver']; } If I substitute "$row[RaceID]" for the number 1, I get expected results, which also veryfies faild names and data are all intact, so I think it has something to do with the accepting of the variable, which I test with an echo statement a few lines before this one and it returns the value of 1, as expected.Any ideas? it's driving me nuts.Cheers Quote Link to comment https://forums.phpfreaks.com/topic/8276-whats-wrong-with-my-select-statement/ Share on other sites More sharing options...
Ferenc Posted April 24, 2006 Share Posted April 24, 2006 [code]$qualyq = ("SELECT * FROM t_qualy_results WHERE t_qualy_results.RaceID = '".$row['RaceID']."'") or die(mysql_error()); [/code] Quote Link to comment https://forums.phpfreaks.com/topic/8276-whats-wrong-with-my-select-statement/#findComment-30173 Share on other sites More sharing options...
ICEcoffee Posted April 24, 2006 Author Share Posted April 24, 2006 Thanks Guru, it worked - but can you tell my why your code worked and mine didn't Quote Link to comment https://forums.phpfreaks.com/topic/8276-whats-wrong-with-my-select-statement/#findComment-30180 Share on other sites More sharing options...
wildteen88 Posted April 24, 2006 Share Posted April 24, 2006 I believe it was becuase you was using single quotes around your query and so PHP wasn't replacing the variable with its value it held as PHP treats variables inside single quotes "as-is". Quote Link to comment https://forums.phpfreaks.com/topic/8276-whats-wrong-with-my-select-statement/#findComment-30182 Share on other sites More sharing options...
Ferenc Posted April 24, 2006 Share Posted April 24, 2006 Your query uses a array ($row['RaceID'])[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php// These examples are specific to using arrays inside of strings.// When outside of a string, always quote your array string keys// and do not use {braces} when outside of strings either.// Let's show all errorserror_reporting(E_ALL);$fruits = array('strawberry' => 'red', 'banana' => 'yellow');// Works but note that this works differently outside string-quotesecho "A banana is $fruits[banana].";// Worksecho "A banana is {$fruits['banana']}.";// Works but PHP looks for a constant named banana first// as described below.echo "A banana is {$fruits[banana]}.";// Won't work, use braces. This results in a parse error.echo "A banana is $fruits['banana'].";// Worksecho "A banana is " . $fruits['banana'] . ".";// Worksecho "This square is $square->width meters broad.";// Won't work. For a solution, see the complex syntax.echo "This square is $square->width00 centimeters broad.";[/quote]since your query is a string, I simply 'broke out of it' Quote Link to comment https://forums.phpfreaks.com/topic/8276-whats-wrong-with-my-select-statement/#findComment-30188 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.