Re: select statement with variables ???

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<side-question>
Jay how come you though concating would give
a different result to interpolation?
</side-question>

Jay Blanchard wrote:
[snip]

$query=" SELECT title FROM $cat WHERE id='$id'";

[/snip]

echo $query; // does it look right to you?
Alway throw an error when in question

if(!($result = mysql_query($query, $connection))){
   echo mysql_error() . "<br>\n";
   exit();
}


up to here I agree with Jay 100%, especially the 'echo' part (also get
familiar with var_dump() and print_r() functions to help debug your problems...

My bet is that you need to concatenate

$query = "SELECT title FROM " . $cat . " WHERE id = '". $id ."' ";

now unless either $cat or $id is actually an object with a 'magic'
__toString() method defined and the engine has been changed to fully/properly
support 'magic' object2string casting I don't agree that concat'ing will help
(even all of what I sAid was true I don't think it would help either),
the reaosn being that AFAICT the following 2 statements leave you with the same
string:


$cat = "mytable";
$id  = 1234;
$one = "SELECT title FROM $cat WHERE id='$id'";
$two = "SELECT title FROM ".$cat." WHERE id = '".$id."'";

var_dump( ($one === $two) ); // <-- will show you that this equates to TRUE.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux