JSEvents and PHP.

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
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

JSEvents and PHP.

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

No, PHP only runs server side. Your using short tags again... :roll:
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

if you like short tags, get used to people on these boards nagging at you about them... cuz it will never end.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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;
    }
}
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
Post Reply