I'm attempting to set up a simple MySQL SELECT which uses a variable to identify the row it selects.
If I use the following (using an actual id rather than a variable) it works perfectly:
<?php
// Request text for page
$content = @mysql_query('SELECT text FROM page_text WHERE id="9"');
if (!$content) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display text for page
while ($row = mysql_fetch_array($content)) {
echo $row['text'];
}
?>
However as soon as I try to introduce a variable such as:
<?php $id = 9; ?>
<?php
// Request text for page
$content = @mysql_query('SELECT text FROM page_text WHERE id="$id"');
if (!$content) {
...
it doesn't work
I've tried a few different options with " and ' changes, but I either get nothing or an error message
The plan is to use the SELECT statement as an Include, hence wanting to set up the variable.
Any thoughts?
Thanks


LinkBack URL
About LinkBacks
Reply With Quote
