NLCJ Posted June 26, 2010 Share Posted June 26, 2010 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, Quote Link to comment https://forums.phpfreaks.com/topic/205956-variable-in-mysql-command/ Share on other sites More sharing options...
Alex Posted June 27, 2010 Share Posted June 27, 2010 You need to post relevant code. Normally you'd do something like this: $sql = "..."; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo $row[$name]; Quote Link to comment https://forums.phpfreaks.com/topic/205956-variable-in-mysql-command/#findComment-1077800 Share on other sites More sharing options...
NLCJ Posted June 27, 2010 Author Share Posted June 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205956-variable-in-mysql-command/#findComment-1077802 Share on other sites More sharing options...
NLCJ Posted June 27, 2010 Author Share Posted June 27, 2010 Somehow it's working now... I guess I was just to tired. Thanks for all the help though! Quote Link to comment https://forums.phpfreaks.com/topic/205956-variable-in-mysql-command/#findComment-1077816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.