我是 Javascript/PHP 新手,所以有几个基本问题。我正在尝试从 php 创建一个 javascript 数组。一切正常,直到我从我的 sql 表中引用列“0”或“pid”,但是一旦我尝试访问下一个列“函数”,javascript 就会停止工作。我创建了一个带有警报的测试用例(同样被数组替换)非常感谢您的帮助。
<?php
$baseName . "jobs";
$tableName = $baseName . "dbTable";
# datbase info .done.
$con = mysql_connect("localhost",$userName,$password);
if (!$con){
echo('Could not connect: ' . mysql_error());
}
mysql_select_db($dbName, $con);
$result = mysql_query("SELECT * FROM " . $tableName);
$count = 0;
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Function</th>
<th>Position</th>
<th>Location</th>
<th>Experience</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['pid'] . "</td>";
echo "<td>" . $row['Function'] . "</td>";
echo "<td>" . $row['Position'] . "</td>";
echo "<td>" . $row['City'] . ', ' . $row['State'] . "</td>";
echo "<td>" . $row['Experience'] . "</td>";
echo "</tr>";
?>
<script type="text/javascript">
alert(<?php echo $row['pid']?>); <!-- this works -->
**alert(<?php echo $row['Function']?>); <!-- this does not works -->**
</script>
<?php
$count++;
}
echo "</table>";
mysql_close($con);
?>