PDA

View Full Version : Problems with javascript, pfft!



Jackboy
11-09-2007, 03:52 PM
right i searched google and i can't find ANYTHING that is easy enough for me to understand. I can do php but NOT javascript.

How would i go about setting a php variable as a js object or setting a php session as a js object or w/e

Eg.


<?
$playername = JAVAVARHERE ?>
My current code is:



<script type=text/javascript>
function addplayer(id){
");
$xyz = mysql_query("SELECT * FROM `players` WHERE `id`='id'");
$xyzz = mysql_fetch_array($xyz);
echo ("
alert('You have selected'+id);
alert('$xyzz[lastname]');
}
</script>


And obv my query is duffage. +rep to all help

Tomm
11-09-2007, 04:33 PM
You can't. Just echo the data directly into the javascript code.

Dentafrice,
14-09-2007, 07:29 PM
<?php
include "config.php"; // includes config file

$query = mysql_query("SELECT * FROM table");
$row = mysql_fetch_array($query);
?>
<script type="text/javascript">
alert('<?=$row[thingy];?>');
</script>

One way to do it.

Want to hide these adverts? Register an account for free!