Jump to content

functions and MySql


shadowmonk

Recommended Posts

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.


Link to comment
Share on other sites

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]

Link to comment
Share on other sites

[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?
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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