Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-25-2001, 10:10 AM   #1
Citizen Bleys
Registered: Mar 2001
Location: Moncton, NB
Distribution: Gentoo 2006.0
Posts: 181

Rep: Reputation: 30
PHP Link Handling

Can anybody tell me a way to make clicking on a link in a PHP-generated page execute a function in the PHP script instead of loading a new page?

I'm redesigning my website from the ground up as an object-oriented PHP project. I want index.php to require, with the source code to class page, set a few variables, and then call the display() method of class page. When the user clicks a link, I want the script to load the new content from a MySQL database and then call display() again--Hence the header, footer, and other static content is unchanged, but the new content is displayed in a table frame at the center of the page.

Since I'll be keeping downloads and images for each section in a separate directory, just making a whole bunch of nearly identical "index.php" files is a pain in the hole--especially since loading a new index.php requires a new connection to the database! Why terminate a script and start an identical one when I can just keep running the same script?
Old 10-10-2001, 04:02 PM   #2
LQ Newbie
Registered: Oct 2001
Distribution: Debian
Posts: 8

Rep: Reputation: 0
Well you can actually run the same script you know. A simple example on how to go around these things:
You create that index.php, and make it look like this, for example (assuming you've already done your PHP connection and there's a field 'article' and 'articlename' in a table 'tblContent':
PHP Code:
$query "SELECT article FROM tblContent WHERE articlename =               'apples'";
$query "SELECT article FROM tblContent WHERE articlename =               'pears'";
$query "SELECT article FROM tblContent WHERE articlename =               'main'";
$result mysql_query($query) or die;
$article) = mysql_fetch_row($result);
Now if you call your script like this: index.php?content=apples , the "apples" case will get executed, and the correct content will be loaded whereever you want it to be loaded (well, whereever you echo() it, in this case). Same thing for the other menu items of course. If none of the cases are true, the 'main' content will be loaded. And that's that. Have a lot of fun :-).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP - MySQL link StarLion Fedora 4 09-10-2005 12:05 PM
PHP image handling/resizing benrose111488 Programming 1 07-07-2005 03:00 AM
Handling filenames with spaces in PHP gw1500se Programming 2 03-14-2004 02:03 PM
i cant link a php frame to another page meluser Linux - Software 0 03-15-2003 12:17 AM
handling downloads with php niehls Programming 0 02-09-2003 06:11 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:30 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration