Reputation: 33
i want to get this number "1" in my javascript function, how can i do it?
HTML--» onclick="displayResult(1)
Javascript --»
function displayResult(obj)
{
var number = ??????;
}
And after i get the number i wanted to be available in PHP. like this:
function displayResult(obj)
{
var number = ??????;
<?
$sql = mysql_query("SELECT * FROM `artigos` WHERE id = ????var number????");
$resultado = mysql_fetch_array($sql);
?>
}
It is possible to do it like this ?
Effect needed --» http://youtu.be/Jz-7Vrx-Xaw
Upvotes: 0
Views: 137
Reputation: 572
onclick callthis function with your value, this javascript function will call the some.php file using jquery ajax call.you can find how to use jquery ajax from jquery site.
javascript side
function displayResult(obj)
{
var number = ??????;
$.ajax({
type: "POST",
url: "some.php",
data: { name: obj}
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
}
PHP side some.php
<?php
$number = $_REQUEST['name'];
echo $number;
$sql = mysql_query("SELECT * FROM `artigos` WHERE id = ????var number????");
$resultado = mysql_fetch_array($sql);
?>
now you can use your values sent from js file in some.php $number.
Upvotes: 1
Reputation: 960
onclick="displayResult('1')"
function displayResult(obj)
{
document.location.href='xyz.php?st='+obj;
}
//now in your php page
$sql = mysql_query("SELECT * FROM `artigos` WHERE id = '".$_REQUEST['st']."'");
Upvotes: 2