Jump to content

Archived

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

ICEcoffee

what's wrong with my select statement?

Recommended Posts

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

Share this post


Link to post
Share on other sites
[code]$qualyq = ("SELECT * FROM t_qualy_results WHERE t_qualy_results.RaceID = '".$row['RaceID']."'") or die(mysql_error());
[/code]

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
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'

Share this post


Link to post
Share on other sites

×

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.