Gettin javascript var passed to PHP?!

I have a javascript in which I need to create an php if/else statement based on one af the javascripts vars.

<script type="text/javascript">
<?
$sql = "SELECT * FROM users WHERE userid=row[1]"; // Here I need to get the javascript var row[1] into the query //
$result = mysql_query($sql) or die("Error: (" . mysql_errno() . ") " . mysql_error());
$row = mysql_fetch_array($result);

if($row['userimg'] == 1){ ?>
	return '<img src="profileimages/'+row[1]+'.jpg" width="25px" height="25px"> '+row[0];
<? } else { ?>
	return '<img src="profileimages/noimage.jpg" width="25px" height="25px"> '+row[0];
<? } ?>

/* JAVASCRIPT CONTINOUS */
</script>

I need to get the javascript bit “row[1]” into the sql query… Any ideas how to do so!!!

Thanks in advance :_)

The PHP will have finished running long before the JavaScript even starts so you can only combine PHP and JavaScript together where the PHP is generating the JavaScript and not the other way around.

To be able to get JavaScript to update PHP you need to either load a new web page passing the parameter from the JavaScript as either a GET or POST variable OR you need to do an Ajax call from the JavaScript in order to run a separate PHP script on the server.