Page 1 of 1

basic question but hard to find on google.

Posted: Mon Mar 08, 2010 2:20 pm
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

Re: basic question but hard to find on google.

Posted: Mon Mar 08, 2010 2:32 pm
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.

Re: basic question but hard to find on google.

Posted: Mon Mar 08, 2010 3:04 pm
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. =)

Re: basic question but hard to find on google.

Posted: Mon Mar 08, 2010 4:48 pm
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
    }
}

Re: basic question but hard to find on google.

Posted: Tue Mar 09, 2010 9:36 am
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

Re: basic question but hard to find on google.

Posted: Tue Mar 09, 2010 10:03 am
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 />
 
 
 

Re: basic question but hard to find on google.

Posted: Tue Mar 09, 2010 3:35 pm
by Goofan
thanks a bunch! :D

Re: basic question but hard to find on google.

Posted: Tue Mar 09, 2010 3:44 pm
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?

Re: basic question but hard to find on google.

Posted: Tue Mar 09, 2010 4:00 pm
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.