Jump to content


Photo

what's wrong with my select statement?


  • Please log in to reply
4 replies to this topic

#1 ICEcoffee

ICEcoffee
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 24 April 2006 - 05:01 PM

Hi all

I 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

#2 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 24 April 2006 - 05:06 PM

$qualyq = ("SELECT * FROM t_qualy_results WHERE t_qualy_results.RaceID = '".$row['RaceID']."'") or die(mysql_error());

Everything you want to know is here.

#3 ICEcoffee

ICEcoffee
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 24 April 2006 - 05:23 PM

Thanks Guru, it worked - but can you tell my why your code worked and mine didn't

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 April 2006 - 05:25 PM

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".

#5 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 24 April 2006 - 05:35 PM

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 errors
error_reporting(E_ALL);

$fruits = array('strawberry' => 'red', 'banana' => 'yellow');

// Works but note that this works differently outside string-quotes
echo "A banana is $fruits[banana].";

// Works
echo "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'].";

// Works
echo "A banana is " . $fruits['banana'] . ".";

// Works
echo "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'
Everything you want to know is here.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users