ryan king Posted January 26, 2009 Share Posted January 26, 2009 I need to include a php file inside another php that is querying results from my database and make it look something like this.. <?php include('/members/{$row['band_id']/online.php'); ?> havent had much luck yet. but is it possible? Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/ Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 include("/members/{$row['band_id']}/online.php"); Using double quotes it is. Just make sure, if the $row comes from get or an untrusted source that you filter/verify the data before using it. Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-746932 Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 missing a close brace premiso: include("/members/{$row['band_id']}/online.php"); edit: you fixed it.... Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-746936 Share on other sites More sharing options...
ryan king Posted January 26, 2009 Author Share Posted January 26, 2009 I tried this and it doesnt work. I get a syntax error for it. Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-746943 Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 what does this output: print "/members/{$row['band_id']}/online.php"; Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-746952 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 I tried this and it doesnt work. I get a syntax error for it. Well we are not mind readers. What is the syntax error and post any relevant code. Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-746965 Share on other sites More sharing options...
ryan king Posted January 26, 2009 Author Share Posted January 26, 2009 it returns the band_id in and prints it like this on the screen /members/15/online.php its supposed to show a "online" message if the member is online..thats why I need to include it. Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-746973 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 You probably want something like this: <?php $band_id = $row['band_id']; include("/members/online.php"); ?> I believe you are wanting to pass the variable to the script and not use it to dynamically define the path...in the include script you should be able to use "$band_id", or even $row['band_id'] if you want to take out that extra step. Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-746978 Share on other sites More sharing options...
ryan king Posted January 26, 2009 Author Share Posted January 26, 2009 first off. I apologize because in my first post I typed it out with double quotes ("") but when I went back to my code it was in single quotes.. so I changed that and no more errors. however, it doesnt output anything. I might have to go about this a diffrent way becuase this online.php file I have was a hack that I did that works in diffent areas of my site inside smarty templates. Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-746987 Share on other sites More sharing options...
ryan king Posted January 26, 2009 Author Share Posted January 26, 2009 accualy..premiso had it correct. Im tripping..my ADD is setting in.. I may need to step away form my computer for awhile.. Thanks guys! Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-746993 Share on other sites More sharing options...
ryan king Posted January 26, 2009 Author Share Posted January 26, 2009 ok.. its fixed now. I had to use double quotes as premiso stated and I had some permission problems so I just gave it the full path instead of just /members/ works as its supposed to. you can see when my members are online now! yaaay!! Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-747032 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 ok.. its fixed now. I had to use double quotes as premiso stated and I had some permission problems so I just gave it the full path instead of just /members/ works as its supposed to. you can see when my members are online now! yaaay!! Glad to hear you worked it out. Topic Solved is on the bottom left hand corner above the Quick Reply =) Link to comment https://forums.phpfreaks.com/topic/142536-solved-can-i-put-a-variable-in-an-include/#findComment-747038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.