neverbegosu Posted June 16, 2012 Share Posted June 16, 2012 have an issue I am trying to work out. php document example (I pull information from my db to build forms and what not. But I am wanting to add php code into but it always just post the code, and not executing it.): echo 'test'; echo 'test'; echo $getresultsquery; DATABASE EXAMPLE db test1 table test1 field1 label field2 header field3 post $_SESSION['user']; ---------------------------------- I have succesuffully been able to run the the queries and pull content, and execute html code. Even within an echo statement on the php with the html in the query. But I cant figure out how to do php code in the query. Almost like using the database as a function, in some sense. If anyone knows why this is can you please get back to me. Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/ Share on other sites More sharing options...
xyph Posted June 16, 2012 Share Posted June 16, 2012 You don't do PHP code in the query. You can't. Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354504 Share on other sites More sharing options...
neverbegosu Posted June 16, 2012 Author Share Posted June 16, 2012 what about variables in a query, then I can make a function to call to create the varibles, is there a way to do what I am trying to other the php code in the database and pulling it as a query? I was assuming. when you pull information out of a database echo $queryrow['user']; would echo whatever is in the that datacell so TESTUSER1 would show on the screen. So is it not right to access the datacell can be used as a variable? Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354506 Share on other sites More sharing options...
Mahngiel Posted June 16, 2012 Share Posted June 16, 2012 what about variables in a query, then I can make a function to call to create the varibles, is there a way to do what I am trying to other the php Your sentence is difficult to understand, but I believe you aren't understanding the concepts. Databases store information. When you retrieve said information, you can assign variables to the values and subsequently pass it through functions. I was assuming. when you pull information out of a database echo $queryrow['user']; would echo whatever is in the that datacell Yes, because you've assigned the values in the table row as an array to the variable $queryrow, you are able to manipulate it with PHP. Your PHP scripts recall stored information from the database and then does things with that information. You do not save scripts in the database and execute it with some wizardry. Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354511 Share on other sites More sharing options...
neverbegosu Posted June 16, 2012 Author Share Posted June 16, 2012 kk first off, I don't know why you posted that quote from someone in this thread, I am not wanting anyone to write the code for me. I don't want the code at all. I want the understanding, so if your going to post shit like that, then do so in your own thread. As for your answer for me, it does make sense. That leaves me with the problem of achieving what I want to achieve so not I have to look at other venues of doing so. Is it possible to call a function that has a varible in the name, so you can pull diffrent functions based of the variable. I have webpages main.php profile.php that have a variable of $title=main/profile exc... In my sitebuild.php I built a function that builds the website without the center content. I declared the variables global in this function in order to call them from the page php scripts. centercontent(); is used to call the function building the center. Can I do somehting like this in order to make it page selectable. centercontent.$title(); ??? that way the name of called function changes with each page I run? Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354518 Share on other sites More sharing options...
litebearer Posted June 16, 2012 Share Posted June 16, 2012 Neverbegosu, that quote is simply part of his signature. It appears on EVERY post he makes. It is NOT intended for you personally. Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354519 Share on other sites More sharing options...
Mahngiel Posted June 16, 2012 Share Posted June 16, 2012 kk first off, I don't know why you posted that quote from someone in this thread, I am not wanting anyone to write the code for me. I don't want the code at all. I want the understanding, so if your going to post shit like that, then do so in your own thread. As for your answer for me, it does make sense. That's my signature. I stopped reading there. Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354520 Share on other sites More sharing options...
neverbegosu Posted June 16, 2012 Author Share Posted June 16, 2012 LMAO IC sorry for the misunderstanding. But horrible signiture man, nubs like me dont realize that stuff. Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354521 Share on other sites More sharing options...
Mahngiel Posted June 17, 2012 Share Posted June 17, 2012 Is it possible to call a function that has a varible in the name, so you can pull diffrent functions based of the variable. No. You're failing to grasp what a function is and does. A function does one task, commonly dependent on what you pass to it. Think about math and the many functions there are to solve certain situational exercises. Your job is to figure which function you need to achieve the goal. In my sitebuild.php I built a function that builds the website without the center content. I'd consider that more of a template than a function, since a function shouldn't control entire page elements like this. I declared the variables global in this function in order to call them from the page php scripts. Yea, don't do that. centercontent(); is used to call the function building the center. Can I do somehting like this in order to make it page selectable. centercontent.$title(); No. What you can do instead is pass parameters to the function, but again, you're not using functions properly. Example: <?php function get_news( $limit = 5 ) { $news_articles = //query database for articles with limit 5 // do something with the articles } // you can then get the standard of 5 get_news(); // or determine a different amount of articles get_news( 10 ); ??? that way the name of called function changes with each page I run? There's no reason you would want to do that. You want your functions to be statically named so you always know what you're expecting to receive. It'd be like renaming the mathematical term "sum". Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354537 Share on other sites More sharing options...
neverbegosu Posted June 17, 2012 Author Share Posted June 17, 2012 do you know any good tutorials on how to better learn functions, and peramiteres, expecially when It comes to building a website. I am very new to this php, and am self learning through tutorials and what not online. I designed what I did, in order to create webpages without having to rebuild the entire page everytime, just change the content in the center div. I used to re write the entire script. So I created a function/templet that I call from each webpage.php so it puts all the content up without having to retype it. From there I was doing html content and storing it on a database, and linked that database to the sitebuild.php. I guess I will install php on my computer and use xxamp to see how there doing it, and try to figure some stuff out that way. Thanks for the help mate, and again sorry for the signature thing. Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354661 Share on other sites More sharing options...
neverbegosu Posted June 17, 2012 Author Share Posted June 17, 2012 Ok so Mahngiel, hope I spelt that right. I did some rethinking after reading what you have said, and did some research on functions and peramiters. I am currently reviewing a small tutorial, and although some if it is making sense, I was hoping you can disect it fore me. Or anyone for that matter, once I understand it, I will be able to use it. I have linked the tutorial incase you need to see the structure of things. http://www.zeronese.net/knowledge-base/articles/article-1029.html <?php if(isset($_REQUEST['page'])) { if($_REQUEST['page'] !="") if(file_exists("pages/".$_REQUEST['page'].".html")) $page_content = file_get_contents("pages/".$_REQUEST['page'].".html"); else if (file_exists($_REQUEST['page'].".html")) $page_content=file_get_contents($_REQUEST['page'].".html"); else echo "<center>Page: ".$_REQUEST['page']." does not exist! Please check the url and try again!</center>"; } else $page_content=file_get_contents("design/pages/main.html"); $page_content=str_replace("!!HEADER!!",file_get_contents("design/header.html"), $page_content); $page_content=str_replace("!!LEFT_COLUMN!!", file_get_contents("design/left_column.html"),$page_content); $page_content=str_replace("!!RIGHT_COLUMN!!",file_get_contents("design/right_column.html"),$page_content); $page_content=str_replace("!!FOOTER!!",file_get_contents("design/footer.html"),$page_content); echo $page_content; ?> on the first line of code if(isset($_REQUEST['page'])) if(file_exists("pages/.$_REQUEST['page'].".html")) I think it checks weather the "page" is not null. But where is it checking this at? I mean where would 'page' come from its the same for the second line as well. I know its going to check for the existence of a file in the pages subfolder, so right now the only one it can be is "main" but again, the 'page' where is that declared, or defined? Once I figure out where the 'page' is comeing from I think I will be able to understand how I can use this. Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1354736 Share on other sites More sharing options...
neverbegosu Posted June 19, 2012 Author Share Posted June 19, 2012 does anyone know what "page" is referencing. After doing some more research I think it is referincing something in the url index.php?page=xxxx does that seem right? Quote Link to comment https://forums.phpfreaks.com/topic/264311-can-i-do-this/#findComment-1355266 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.