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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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