Hello,

Please, if anyone knows how to pass a Javascript integer variable as a parameter into php mysql_query. Below gg1 is successfully converted to an integer (i checked it using some maths additions), and now i need to pass this value to BirdID. The last line with innerHTML works fine if this php is fixed, i.e. if i put BirdID='2', it displays well.

Any help will be very much appreciated

function loadBirdData(bb)
{
		
var gg1 = parseInt(bb); 

<?php
$var = mysql_query("SELECT Colour FROM birdstable WHERE BirdID = 'gg1'  ");
$row = mysql_fetch_assoc($var);
?>
document.getElementById('content').innerHTML = '<?php "".$row['BirdColour']."</br>" ?>';

...
}

simple... fetch the data through query and
use this javascript function
like...
echo "<script language='javascript'>location.href=('index.php?act=addres&dept=$id')</script>";

When is the variable populated? Before or after the page is loaded?

before

no, sorry, actually it's populated after the page is loaded - it comes from a mouse click

sorry i'm very new to java and php, so i didn't understand what you mean by fetch data i query, and where should i insert that javascript line?
thanks

no, sorry, actually it's populated after the page is loaded - it comes from a mouse click

Then you'll have to look into using AJAX. PHP, by itself, cannot modify the page after it has been loaded. It's a common misconception. You see, once the page is loaded, php, by itself, can no longer communicate with the client without a page refresh.
Think of AJAX with php as a phone call between javascript and php.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.