Reply to Re: [PHP] select statement with variables ???

Your name:

Reply:


Posted by Jochem Maas on 12/21/05 16:17

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация