需要一些AJAX / PHP / Array帮助 [英] Need some AJAX/PHP/Array help

查看:66
本文介绍了需要一些AJAX / PHP / Array帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当管理员选择其他用户时,我正在寻找重新填充的字段。我认为这可以通过数组完成,因为当它到达终端计算机时,PHP已经被解析,并且在其中运行带有PHP的javascript函数,最终将证明是徒劳的。但是我想弄清楚的是如何获取用PHP构建的数组并将其作为全局变量传递给javascript使用和阅读。


PHP数组的构建方式如下:


用户(User1(Number => number,FirstName => name),User2(Number => number,FirstName => ;姓名))


所以,因为我在用户中有信息数组。数组,它使它变得更加困难。


如果你去 http://beta.eastcoast911 .com / 你可以看到我正在尝试做什么。在右上角,当您选择其他用户时,它会使用值更新数字,但我正在尝试更新名称。在底部,它基于以下代码创建了表格:


[PHP] echo"< table width =''590px''border = 1 cellpadding = 0 cellspacing = 0>" ;;

echo"< tr>< th width =''5px''>#< / th>< th> Number< / th>< th> ;名字< / th>< th>姓氏< / th>< th>位置< / th>< th>关于< / th>< / tr>" ;;


$ dbh = mysql_connect(" localhost"," name"," password")或die(''数据库连接错误:''。mysql_error());

mysql_select_db(" db",$ dbh);


$ sqlArr =''SELECT Number,FirstName,LastName,Location2,About FROM Users ORDER BY" Number" ASC'';

$ dbsql = mysql_query($ sqlArr)或die(mysql_error());

$ row = mysql_num_rows($ dbsql);
< br $>
for($ i = 0; $ i< $ row; $ i ++){

$ myarray = mysql_fetch_row($ dbsql);

echo"< tr>< td valign =''top''align = right> $ i。< / td>" ;;

for($ j = 0; $ j< ; 10; $ j ++){

echo"< td valign =''top''> $ myarray [$ j]< / td>";

};

echo"< / tr> \ n";

};

echo"< / table> ;" ;; [/ PHP]


我已经用这个代码创建了数组,它也有效:


[PHP] for($ i = 0; $ i< $ row; $ i ++){

$ myArr = mysql_fetch_row($ dbsql);

for($ j = 0; $ j< 10; $ j ++){

$ myArr [$ i] [$ j] = $ myArr [$ j];

};

}; [/ PHP]

I''m looking to repopulate some fields when an administrator chooses a different user. I think this can be done through arrays, since by the time it gets to the end computer the PHP has already been parsed, and running a javascript funtion with PHP in it, would ultimately prove fruitless. But what I''m trying to figure out is how to take the array that was built in PHP and pass it (as a global variable?) to the javascript to use and read.

The PHP array is built somewhat like this:

Users(User1(Number=>number, FirstName=>name),User2(Number=>number, FirstName=>name))

So, since I have the information array within the "Users" array, it makes it that much harder.

If you go to http://beta.eastcoast911.com/ you can see what I''m trying to do. On the top right, when you select a different user, it updates the number with the value, but I''m trying to get it to update the name. On the bottom it has created the table based on the following code:

[PHP]echo "<table width=''590px'' border=1 cellpadding=0 cellspacing=0>";
echo "<tr><th width=''5px''>#</th><th>Number</th><th>First Name</th><th>Last Name</th><th>Location</th><th>About</th></tr>";

$dbh = mysql_connect ("localhost", "name", "password") or die (''Database Connection Error: '' . mysql_error());
mysql_select_db ("db", $dbh);

$sqlArr = ''SELECT Number,FirstName,LastName,Location2,About FROM Users ORDER BY "Number" ASC'';
$dbsql = mysql_query($sqlArr) or die(mysql_error());
$row = mysql_num_rows($dbsql);

for ($i=0; $i < $row; $i++) {
$myarray = mysql_fetch_row($dbsql);
echo "<tr><td valign=''top'' align=right>$i.</td>";
for ($j=0; $j < 10; $j++) {
echo "<td valign=''top''>$myarray[$j]</td>";
};
echo "</tr>\n";
};
echo "</table>";[/PHP]

I''ve used this code for creating the array, and it works as well:

[PHP]for ($i=0; $i < $row; $i++) {
$myArr = mysql_fetch_row($dbsql);
for ($j=0; $j < 10; $j++) {
$myArr[$i][$j] = $myArr[$j];
};
};[/PHP]

推荐答案

dbh = mysql_connect(" localhost"," nam) e,,密码)或死亡(''数据库连接错误:''。 mysql_error());

mysql_select_db(" db",
dbh = mysql_connect ("localhost", "name", "password") or die (''Database Connection Error: '' . mysql_error());
mysql_select_db ("db",


dbh);

dbh);


sqlArr =''SELECT Number,FirstName,LastName,Location2,About FROM Users ORDER BY" Number" ASC'';
sqlArr = ''SELECT Number,FirstName,LastName,Location2,About FROM Users ORDER BY "Number" ASC'';


这篇关于需要一些AJAX / PHP / Array帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆