Jump to content

Recommended Posts

I want to beable to run a mysql query if a if function in javascript is called!

 

POSSIBLE ? I DONT THINK SO.. help me? Please!

lol

 

It's possible with AJAX.

 

Ok so i have this:

 

<?php
function test(){
$sql = mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id={$ibforums->member["id"]} LIMIT 1");
return $sql;
}
?>

 

And I want it to run:

 

when this happens:

 

case 3: content='You won this round. <?php echo test(); ?>';

 

and Case 3 get's called here:

 

 

if(iswon){
if(isplayer){
playerwins[level]++;
playerstarts=true;
writetext(3);
}else{
pcwins[level]++;
playerstarts=false;
writetext(2);
}}

 

So i can't do this unless I use ajax? WOW

You DO understand that php is a server side scripting language that is executed on the server when pages are requested via HTTP/HTTPS requests and that javascript is executed client side in the browser and that browsers can only make HTTP/HTTPS requests for web pages?

You DO understand that php is a server side scripting language that is executed on the server when pages are requested via HTTP/HTTPS requests and that javascript is executed client side in the browser and that browsers can only make HTTP/HTTPS requests for web pages?

 

 

Yea but my QUERY IS IN PHP..... It's only getting called if a JAVASCRIPT Function is called.

 

javascript - > then php

 

it should work why not?

But as Nightslyr was saying, you could use AJAX to send the HTTP/HTTPS requests, right?

If AJAX requested script.php, then script.php would run server-side, even though the client-side javascript prompted it to run by sending the HTTP request.

But as Nightslyr was saying, you could use AJAX to send the HTTP/HTTPS requests, right?

If AJAX requested script.php, then script.php would run server-side, even though the client-side javascript prompted it to run by sending the HTTP request.

 

ok well can u help me on that? in my other thread? i want to use that away man, i think that would do it ?

Gayner, you need to brush up on the basics.  First, trying to echo out the result of an update query is nonsense.  Literally.  It won't work, and certainly won't magically do what you think it should do.  Second, you seem to be confused about what JavaScript is, what PHP is, and how they work together.  Third, I don't even see a JavaScript function here.

 

Instead of blindly writing code in an attempt to somehow stumble onto a solution, take the time to learn how things actually work.

Gayner, you need to brush up on the basics.  First, trying to echo out the result of an update query is nonsense.  Literally.  It won't work, and certainly won't magically do what you think it should do.  Second, you seem to be confused about what JavaScript is, what PHP is, and how they work together.  Third, I don't even see a JavaScript function here.

 

Instead of blindly writing code in an attempt to somehow stumble onto a solution, take the time to learn how things actually work.

 

function findwinner(isplayer){
me=(isplayer)? 1 : 2;
for(n=1;n<=8;n++){
if( (moves[ways[n][1]]==me) && (moves[ways[n][2]]==me) && (moves[ways[n][3]]==me) ){
iswon=true;
break;
}}
if(iswon){
if(isplayer){
playerwins[level]++;
playerstarts=true;
writetext(3);
}else{
pcwins[level]++;
playerstarts=false;
writetext(2);
}}else{
if(done>{
draws[level]++;
playerstarts=!playerstarts;
writetext(1);
}else if(isplayer) pcturn();
}}

 

theres the function for ya

Gayner, you need to brush up on the basics.  First, trying to echo out the result of an update query is nonsense.  Literally.  It won't work, and certainly won't magically do what you think it should do.  Second, you seem to be confused about what JavaScript is, what PHP is, and how they work together.  Third, I don't even see a JavaScript function here.

 

Instead of blindly writing code in an attempt to somehow stumble onto a solution, take the time to learn how things actually work.

 

PHP.net - http://us2.php.net/manual/en/function.mysql-query.php

 

Return Values

 

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

 

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

 

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

 

Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

 

mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.

 

To help explain the gap between JavaScript and PHP:

 

When you request a page via HTTP requesting in your browser (type in http://www.google.com/ and hit enter, for instance), PHP is run before the page loads. Then as the page loads/after the page loads, JavaScript can be run. PHP is a server-side language, it's translated by the server before sent to the client. JavaScript is a client-side language, it's not really translated by any server.. mainly by the client in a Javascript-compatible browser.

 

AJAX allows JavaScript to call a page (think of cron jobs) as the user visiting the page with the javascript code. Any information that is contained within that user can be accessed via the called page (sessions, cookies for example). AJAX allows the JavaScript code to send data and parameters via a POST or GET query and then it can wait around for the page's response in which case you handle through various JavaScript functions. <-- This type of method is Asychronous (sp?) in which calls are made and information received in no logical order. Sychronous (sp?) is different.. but I like the Asychronous myself.

Gayner, you need to brush up on the basics.  First, trying to echo out the result of an update query is nonsense.  Literally.  It won't work, and certainly won't magically do what you think it should do.  Second, you seem to be confused about what JavaScript is, what PHP is, and how they work together.  Third, I don't even see a JavaScript function here.

 

Instead of blindly writing code in an attempt to somehow stumble onto a solution, take the time to learn how things actually work.

 

function findwinner(isplayer){
me=(isplayer)? 1 : 2;
for(n=1;n<=8;n++){
if( (moves[ways[n][1]]==me) && (moves[ways[n][2]]==me) && (moves[ways[n][3]]==me) ){
iswon=true;
break;
}}
if(iswon){
if(isplayer){
playerwins[level]++;
playerstarts=true;
writetext(3);
}else{
pcwins[level]++;
playerstarts=false;
writetext(2);
}}else{
if(done>{
draws[level]++;
playerstarts=!playerstarts;
writetext(1);
}else if(isplayer) pcturn();
}}

 

theres the function for ya

 

And this tells me...?  Also, why is this kind of game logic being executed by JavaScript anyway?  This sort of thing should be on the server, with the rest of your game code.  JavaScript should merely be used to enhance the experience, not be a critical piece of the software.  The game should be able to work without any JavaScript.

 

@kratsg: synchronous page execution is the default behavior - full page refresh when submitting info to the server.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.