shadowmonk Posted January 9, 2007 Share Posted January 9, 2007 This is going to be hard to explain, but I'm going to give it a try. I'm trying to create a news database for a site my company is re-designing. Sometimes they have pictures that go along with their articles, so we need to post them with the article. I've got it built so it can upload the pictures to the server and will store the location in the database. I'm wanting to create a function that can automatically insert the necessary code, with the proper source name from the database, into the article where ever I need it and be able to define the alignment. This is where I think I'm stuck.The function is going to be stored in the sites config file, however, I'm trying to call the function on-the-fly when I load the article from the database. This means I'm trying to call the function when I load it from the database, with values that are stored in the database. This I should be able to do after I define variables, but first I need to get just a basic function working this way. The basic function I'm experimenting with just displays "Hello World" when called, but when I load the article it just shows the function "image()".Is it at all possible to do what I'm trying? If not, is there anyway to have it insert the text I need when it updates the database? If neither of these is possible, is there anything else I could do that wouldn't require me having to past the image code directly into the upload form?Thanks for any help I can get. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/ Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Can you show your code that isn't working? Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156246 Share on other sites More sharing options...
shadowmonk Posted January 9, 2007 Author Share Posted January 9, 2007 This is the direct link to the test article http://presbyterianmanors.org/2007/news/recent_news.php?article=2The function I'm trying to call is simple:[code]function image(){ echo "Hello world";}[/code]Instead i'm just getting "image()" in the text. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156253 Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 No, the code where you get image() as the text. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156255 Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 I was going to ask the same. The function is simple and fine..it's defiantely the way yer calling it in recent_news.php Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156257 Share on other sites More sharing options...
shadowmonk Posted January 9, 2007 Author Share Posted January 9, 2007 sorry.All I did was place image() in the database before the "Testing" so it looks like this "image()<p>Testing, 1. 2.. 3...</p>" in the database. I did forget the semicolon, but it didn't change anything, just added a semicolon after image().magic2goodil (and jesirose if I'm still wrong above) - all recent_news.php does is get the information from the database:[code]<? mysql_select_db($database, $connection) or die('Database Not Found'); $query = "SELECT pmma_active.title, pmma_active.article FROM pmma_active WHERE pmma_active.id = $article"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); while(list($title, $article, $id) = mysql_fetch_row($result)) { echo "<h3>$title</h3>"; echo "$article"; echo "<hr />"; }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156259 Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 You need to have it in PHP tags.<?=image()?> (works with short tags on, otherwise use <?php echo image(); ?>)You can't just write it and expect the computer to guess what is php. :-P Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156261 Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 [quote author=jesirose link=topic=121585.msg500225#msg500225 date=1168304968]You need to have it in PHP tags.<?=image()?>You can't just write it and expect the computer to guess what is php. :-P[/quote]damn computers not guessing that it's php Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156264 Share on other sites More sharing options...
shadowmonk Posted January 9, 2007 Author Share Posted January 9, 2007 [quote author=jesirose link=topic=121585.msg500225#msg500225 date=1168304968]You need to have it in PHP tags.<?=image()?> (works with short tags on, otherwise use <?php echo image(); ?>)You can't just write it and expect the computer to guess what is php. :-P[/quote]Ok, I tried it both ways. Now it just doesn't show anything there... any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156269 Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Is the image() function included on the page? You have to have it on the page you're running in order to call it. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156270 Share on other sites More sharing options...
shadowmonk Posted January 9, 2007 Author Share Posted January 9, 2007 [quote author=jesirose link=topic=121585.msg500234#msg500234 date=1168305381]Is the image() function included on the page? You have to have it on the page you're running in order to call it.[/quote]Thats what I was afraid of. No, the function is actually in the database itself. I was trying to have it call the function when it loaded the database article, because thats how I would have preferred it to be done, but I was pretty sure it wasn't going to work that way. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156281 Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 What? The function is...in the database?What?PHP code on PHP pages. Data in Database.Goooood.CALLING the function is not the same as defining it.Where is the part where you do function image(){//code}??You're not putting that in your database please say you're not. That is PHP code. Put it on the php page. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156282 Share on other sites More sharing options...
shadowmonk Posted January 9, 2007 Author Share Posted January 9, 2007 I might be a beginner at php, but thankfully I put the actual function in the config.php file for the page.Like I said, I figured that trying to call the function when loading the database information wouldn't work, but I wanted to try it anyway.Is there a way that when I submit the form that uploads the information to the database I can replace a place holder with what I want it to actually put into the database.I'm only looking for an easy way around the image code because each image also has footer text. It's actually a two row table that has the image up top and a footer underneath it that is unique for each picture. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156288 Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Okay, so IS your config.php included on your recent_news.php page? You'll also need to end the string which you're printing before calling the PHP otherwise it won't run.What you're trying to do likely won't work. If you need a placeholder, just do something like [image] and then str_replace. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156292 Share on other sites More sharing options...
shadowmonk Posted January 9, 2007 Author Share Posted January 9, 2007 the config.php file is included in the header of the recent_news.php page. I included the entire function code in my second post, and haven't changed it since. I guess my next avenue is the placeholder route, this should be fun...Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156299 Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Sorry that took so long. Best of luck. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156305 Share on other sites More sharing options...
shadowmonk Posted January 9, 2007 Author Share Posted January 9, 2007 no problem, it actually gave me faith in these forums. Tried some others and... well I don't go back to those anymore. Quote Link to comment https://forums.phpfreaks.com/topic/33408-functions-and-mysql/#findComment-156309 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.