Jump to content


Photo

Variables


  • Please log in to reply
3 replies to this topic

#1 kevloink

kevloink
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 10 August 2006 - 05:38 PM

Can you use variables in sql statments, or links? Like 'a href=$varhere' Or SELECT #varhere FROM table.

#2 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 10 August 2006 - 05:41 PM

indeed you can, just make sure you put: a href="<? echo $variable; ?>" if the link is not in a php statement already



#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 10 August 2006 - 05:42 PM

Can you use variables in sql statments, or links? Like 'a href=$varhere' Or SELECT #varhere FROM table.


as long as you echo the variable in such a way that it will be translated, yes indeed.

for instance:
<?php
// these will work:
echo "<a href=\"$myLink\">Some Link Text</a>";
$sql = mysql_query("SELECT $myColumn FROM tableName");

// this will not:
echo '<a href="$myLink">Some Link Text</a>';
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 kevloink

kevloink
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 10 August 2006 - 05:45 PM

Cool, thanks very much!  ;D ;D ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users