basic question but hard to find on google.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

basic question but hard to find on google.

Post by Goofan »

Hi!
How can i use normal links as "buttons"?
So that something happens when u click the link "not a button".


//Thanks in advance
//Thomas
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: basic question but hard to find on google.

Post by AbraCadaver »

Depends on what you want to happen? You can set the onclick event for the link to call some javascript function, or you can call a php page and pass it some values.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: basic question but hard to find on google.

Post by Goofan »

well i thought of basicly do a calculation or so.


Exampel code

Code: Select all

 
If ("link where pressed"){
 
$sql="SELECT * FROM konto WHERE saved_id=$id";
$result = mysql_query($sql) or die(mysql_error());//Välj all info i tall. //hämtar all info från tabell
 
while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
 
{
    $user = $row['user'];
    $pengar = $row['pengar'];
 
}
 
}
 
Those kind of actions where what i thought of. =)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: basic question but hard to find on google.

Post by AbraCadaver »

A simple example based on what "I think" you're asking:

Code: Select all

<a href="page.php?action=something">Click link</a>
page.php

Code: Select all

if(isset($_GET['action'])) {
    switch($_GET['action']) {
        case 'something':
            //do something
        default:
            //do a default action
    }
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: basic question but hard to find on google.

Post by Goofan »

yea thats basicly but i where more think in the line of all done on 1 page. so that if the link is pressed do a action. =)




//Thanks in advance
//Thomas
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: basic question but hard to find on google.

Post by AbraCadaver »

Goofan wrote:yea thats basicly but i where more think in the line of all done on 1 page. so that if the link is pressed do a action. =)
Just put it in one page then:

page.php

Code: Select all

<?php
if(isset($_GET['action'])) {
    switch($_GET['action']) {
        case 'something':
            //do something
            break;
 
        case 'this':
            //do this
            break;
 
        case 'that':
            //do that
            break;
 
        default:
            //do a default action
    }
}
?>
<a href="page.php?action=something">Click link</a><br />
<a href="page.php?action=this">Click link</a><br />
<a href="page.php?action=that">Click link</a><br />
 
 
 
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: basic question but hard to find on google.

Post by Goofan »

thanks a bunch! :D
JackD
Forum Commoner
Posts: 62
Joined: Sat Dec 12, 2009 6:25 pm

Re: basic question but hard to find on google.

Post by JackD »

Is there a way, using your example and only php, to do that without reloading the page, or do I have to use JavaScript for that?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: basic question but hard to find on google.

Post by AbraCadaver »

JackD wrote:Is there a way, using your example and only php, to do that without reloading the page, or do I have to use JavaScript for that?
JavaScript.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply