Jump to content

Variable in MySQL command


NLCJ

Recommended Posts

Hello,

I'm creating a new site, and to do that I will have to do it like below. Basically I have to display something that I got from SQL, but the row I need is a variable. How do I do this? I've tried all possibilities I could think of...

$name = "NameOfSomething";
$sql = //MySQL query
echo $sql[$name];

I hope you guys understand my problem.

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/205956-variable-in-mysql-command/
Share on other sites

Okay. Here is a part of the code, which I think is necessary:

<?php
$id = $_GET['id'];
$table1 = mysql_fetch_array(mysql_query("SELECT * FROM table1 WHERE id='".mysql_real_escape_string($id)."'"));
$table2 = mysql_fetch_array(mysql_query("SELECT * FROM table2 WHERE date='".mysql_real_escape_string($table1['date'])."'"));

Lets say that there is a row with the same name as the result of table 1.

echo $table2[$table1['name']];
?>

However this doesn't work... :(

Thanks for your reply.

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.