Zwake
11-21-2011, 08:41 PM
Ok so i have been trying to get this to work for awhile but i cant manage to do it. I am new to PHP and was wondering how i can alert an index of a PHP array. If im not able to alert it i at least want to print it onto the page. What is happening here is i am grabbing a random line from a file and exploding that line into parts. I put the 2nd index in the table cell. When the user clicks on a cell i want an alert to pop up giving me the 3rd index of the array $pieces. This is what i have so far, thanks.
<html>
<script>
function speech(){
alert(<? $pieces[3] ?>);
}
</script>
<body>
<table border=1>
<?
$f = file("/myPathGoesHere");
for ($i=0;$i<3;$i++){
print "<tr></tr>";
for ($j=0;$j<6;$j++){
$r = rand(1, 35915);
$pieces = explode(" ", $f[$r]);
print "<td onclick='speech()'>$pieces[2]</td>";
}
}
?>
</table>
</body></html>
<html>
<script>
function speech(){
alert(<? $pieces[3] ?>);
}
</script>
<body>
<table border=1>
<?
$f = file("/myPathGoesHere");
for ($i=0;$i<3;$i++){
print "<tr></tr>";
for ($j=0;$j<6;$j++){
$r = rand(1, 35915);
$pieces = explode(" ", $f[$r]);
print "<td onclick='speech()'>$pieces[2]</td>";
}
}
?>
</table>
</body></html>