WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Navigation by clicking buttons
Categories : PHP, HTML and PHP, Navigation Click here to Update Your Picture
Jon Slack
Date : Apr 15th 2004
Grade : 2 of 5 (graded 5 times)
Viewed : 9766
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Jon Slack
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

I created an Access database which the customer wanted to access from the web. What's more, they wanted the web version to look exactly like the Access version - so they wanted to click buttons rather than links to pages. I created an index page that presented buttons and used the Header function to decide where to go. It looks like this:

Buffer the page becuse if ANYTHING is output to the browser before the relocation - it wont work This is at the very top of the .php file.

<?php
ob_start
();


// Check whether we are returning from a button-press
// The HTML Form Buttons are simply called Opt1, Opt2 ...Optn


// Set $opt to zero
$opt = 0;

// Check which (of 6) buttons clicked (if any)
if(isset($opt1)) $opt=1;
if(isset(
$opt2)) $opt=2;
if(isset(
$opt3)) $opt=3;
if(isset(
$opt4)) $opt=4;
if(isset(
$opt5)) $opt=5;
if(isset(
$opt6)) $opt=6;

//If $opt is NOT still zero (a button was clicked), determine which one...and go there.

if($opt)
{
    switch (
$opt) {

        case
1 :
           
header("Location: http://www.yourpage.php?var1=$var1&var2=$var2);
            exit;
        case 2 :
            header("
Location: http://www.yourpage2.php?var1=$var1&var2=$var2);
           
exit;       
        case
3 :
           
header("Location: http://www.yourpage3.php?var1=$var1&var2=$var2);
            exit;
        case 4 :
            header("
Location: http://www.yourpage4.php?var1=$var1);
           
exit;
        case
5 :
                     
// Cases 5 & 6 included for future expansion
           
break;
        case
6 :
            break;
        }   
    exit;
}

// If $opt is still Zero - no button has been pressed
// so your visitor has just arrived or clicked refresh
// or back.

else
{
?>

// Finish off the php and start the HTML (where the buttons are presented in an ordinary HTML form [they are ALL Submit buttons].)

<html>
<head>


...
etc.

This has several advantages. No links, just buttons. One index page allows parameters to be set (using check boxes etc) before choosing a page to go to, which negates the need to quiz the visitor for variables when (s)he gets there.



PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
Database resultset navigation
Categories : PHP, HTML and PHP, Databases, MySQL, Navigation
Record Set Paging with PHP (RSP)
Categories : PHP, MySQL, Navigation, Databases, HTML and PHP
GonxTabs : Create elegant HTML tabs based interface
Categories : Navigation, HTML, HTML and PHP, PHP
TreeView - Finally a working tree view function to be used as you want. Simple create the Table using the code provided and you will be able to have a tree view in your project. Download the zip to get the images.
Categories : PHP, HTML and PHP, Navigation
Complete, simple working example of login screen and check on a unique page using php functions, cookies and mysql database.
Categories : PHP, Cookies, MySQL, HTML and PHP, Authentication
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
PHPixel - output of 1 pixel transparent/colored gif for counters etc.
Categories : PHP, Graphics, HTML and PHP
PHP MultiList Mailing List Manager
Categories : Email, HTML and PHP, PHP
How to use regular expressions to get the list of links from an HTML page
Categories : PHP, Regexps, HTML, HTML and PHP
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
Select with current month
Categories : PHP, HTML and PHP, Date Time, Arrays
class formHTML build your HTML Forms from PHP
Categories : PHP, PHP Classes, HTML and PHP, HTML
This script allows people to add their favorite quotes to your website. This could easily be modified to be a guestbook script or comment page script.
Categories : PHP, Complete Programs, HTML and PHP, Misc
 Jon Slack wrote : 1068
I should perhaps have mentioned that the action= part of the form declaration is PHP_SELF or the URL of this index page so that upon pressing any of the 6 submit buttons always beings the visitor back to the same page.

:o)
 
 matthew waygood wrote :1069
Your example is a bit half-hearted. It doesnt contain full code as an example should. It just looks like an example of a switch statement. There is no reference to $_GET to process the passed values or how you are showing the buttons.

Surely a simpler example would be to replace all links with forms.

function link_as_button($url, $link)
{
  return `&lt;form method="get" action="`.$url.`"&gt;&lt;input type="submit" value="`.$link.`"/&gt;&lt;/form&gt;`;
}

To use it just supply the URL and the Text for the button.

echo link_as_button("index.php", "home");