LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 09-25-2001, 09:10 AM   #1
Citizen Bleys
Member
 
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 page.inc, 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, 03:02 PM   #2
daholygoat
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:
<?
switch($content)
{
    case 
"apples":
         
$query "SELECT article FROM tblContent WHERE articlename =               'apples'";
         break;
    case 
"pears":
         
$query "SELECT article FROM tblContent WHERE articlename =               'pears'";
         break; 
     default:
         
$query "SELECT article FROM tblContent WHERE articlename =               'main'";
         break;
}
$result mysql_query($query) or die;
list(
$article) = mysql_fetch_row($result);
echo(
$article);
?>
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 :-).
 
  


Reply


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 11:05 AM
PHP image handling/resizing benrose111488 Programming 1 07-07-2005 02:00 AM
Handling filenames with spaces in PHP gw1500se Programming 2 03-14-2004 01:03 PM
i cant link a php frame to another page meluser Linux - Software 0 03-14-2003 11:17 PM
handling downloads with php niehls Programming 0 02-09-2003 05:11 AM


All times are GMT -5. The time now is 12:24 PM.

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