Jump to content

[SOLVED] variable in sql statement


noname_clark

Recommended Posts

hello, i am trying to have a sql statement grab a number from a table called 'photosunday' and then use that number in a sql for another table called 'link'.

 

i have a table called photosunday with:

counter    hidden  and a few other un-importand stuff for this....

    5          59

    4          58

    3          57

    2          56

    1          55

 

and a table called link with:

 

counter    hidden    and a few other un-importand stuff for this....

    1            1

  thru        thru

  700          59

 

 

 

 

heres the code:

 

  <?php

$conn=mysql_connect("db","usr","pass");

mysql_select_db("usr",$conn);

 

// heres the first sql statement:

 

$sql = 'SELECT * FROM `photosunday` ORDER BY `counter` DESC LIMIT 1';

$result=mysql_query($sql,$conn) or die(mysql_error());

 

 

while ($newArray=mysql_fetch_array($result))

{

 

// this gets the number i need, in this case, it is 59.

 

$hidden=$newArray['hidden'];

}

 

// so heres the second sql statement, and theres the variable $hidden

 

$sql = 'SELECT * FROM `link` WHERE `theme`= "$hidden" ORDER BY `counter`';

$result=mysql_query($sql,$conn) or die(mysql_error());

echo $hidden;

echo "<ol>";

 

while ($newArray=mysql_fetch_array($result))

{

$name=$newArray['name'];

$url=$newArray['url'];

echo "<li><a href=\"$url\" target=\"_blank\">$name</a></li>";

}

echo "</ol>";

?>

 

 

 

 

i can put a few echo $hidden; so i know that its the right number, and i know that there are atleast 12 records in 'link' where `hidden` = 59

 

so if someone could tell me the correct quotation for the hidden = $hidden in the      $sql = 'SELECT * FROM `link` WHERE `theme`= "$hidden" ORDER BY `counter`';  that would be greatly appriciated

 

thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/119049-solved-variable-in-sql-statement/
Share on other sites

Archived

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

×
×
  • Create New...

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.