Page 1 of 1

JSEvents and PHP.

Posted: Tue Jul 18, 2006 3:12 pm
by JellyFish
I was wondering if this is possible?

Code: Select all

<a href="" onclick="<? mySqlConnectionFunc() ?>">Click to connect to the database</a>
Basicaly the function does everything it needs to too connect to my database. So can php be in events like these? If not then how could one make php more "real-time" with JavaScript maybe.


Thanks

Posted: Tue Jul 18, 2006 3:14 pm
by Benjamin
No, PHP only runs server side. Your using short tags again... :roll:

Posted: Tue Jul 18, 2006 3:21 pm
by JellyFish
Okay. I understand. Sorry about the short tags(but I like them lol).

Can I use a JavaScript function that connects to the mySQL database using php? How would that look if so.

Posted: Tue Jul 18, 2006 3:28 pm
by Luke
if you like short tags, get used to people on these boards nagging at you about them... cuz it will never end.

Posted: Tue Jul 18, 2006 3:31 pm
by Benjamin
EasyGoing wrote:Okay. I understand. Sorry about the short tags(but I like them lol).

Can I use a JavaScript function that connects to the mySQL database using php? How would that look if so.
You may want to google for "AJAX Example | Sample".

The easiest way to do what you want though..

Code: Select all

<a href="?Action=Connect">Connect To Database</a>

Code: Select all

if (isset($_GET['Action'])) {
    switch ($_GET) {
        case 'Connect':
                // connect to the database code
            break;
    }
}

Posted: Tue Jul 18, 2006 3:40 pm
by JellyFish
if you like short tags, get used to people on these boards nagging at you about them... cuz it will never end.
Okay well staying on subject: my last question. :D

Posted: Tue Jul 18, 2006 3:53 pm
by Burrito
EasyGoing wrote:Okay well staying on subject: my last question. :D
...was answered. look at ajax if you dont' want to refresh the page.