0

我正在尝试通过 javascript 将多个 MySQL 结果集数据从弹出页面传递到主页。

这是我到目前为止所做的:

在我的 popup.php 页面中:

$sql = mysql_query("SELECT * from item
                    where category like '$category%'
                    and type like '$type%'");
$num = mysql_num_rows($sql);


<table align="center" border="1" cellpadding="10" cellspacing="5">

    <tr bgcolor = 'yellow'>
    <th align="center"><font face="Arial, Helvetica, sans-serif">Select</font></th>
    <th align="center"><font face="Arial, Helvetica, sans-serif">Item Desc</font></th>
    <th align="center"><font face="Arial, Helvetica, sans-serif">Item Specification</font></th>
    <th align="center"><font face="Arial, Helvetica, sans-serif">Item Rate</font></th>
    </tr>
<?php
    $i = 0;
    while ($i < $num) {
    $f1=mysql_result($sql,$i,"item");
    $f2=mysql_result($sql,$i,"specification");
    $f3=mysql_result($sql,$i,"rate");

?>

<tr>
<td><input type="checkbox" name="item" id="item" /></td>
<td align="center"><font face="Arial, Helvetica, sans-serif" color = 'red'><b><?php echo $f1; ?></font></b></td>
<td align="center"><font face="Arial, Helvetica, sans-serif" color = 'red'><b><?php echo $f2; ?></font></b></td>
<td align="center"><font face="Arial, Helvetica, sans-serif" color = 'red'><b><?php echo $f3; ?></font></b></td></tr>
<?php
  $i++;}
?>
<?php

echo('<input type="button" value="Select" id="button" onClick="passVariable(\''.str_replace("'", "\\'", $f1).'\', \''.str_replace("'", "\\'", $f2).'\');">');

这是 passVariable 函数:

function passVariable(name1, name2){
  //This code should be able to pass the entire selection list after user clicks on the check-button to the main.php.
}

在我的 main.php 中,我应该只获取用户选择结果集。

我想我需要使用arrays,但需要一点帮助。

我应该如何进行?

4

1 回答 1

1
<?php if(isset($_POST[add])){ ?>
<?php foreach($_POST[item] as $t){ 
        $sql = mysql_query("SELECT * from item
                    where item=$t");
        //write code here to draw table based upon selected items
<} ?>
<?php }?>

<form name="form1" action="test.php" method="POST">
<table align="center" border="1" cellpadding="10" cellspacing="5">
<tr bgcolor = 'yellow'>
    <th align="center"><font face="Arial, Helvetica, sans-serif">Select</font></th>
    <th align="center"><font face="Arial, Helvetica, sans-serif">Item Desc</font></th>
    <th align="center"><font face="Arial, Helvetica, sans-serif">Item Specification</font></th>
    <th align="center"><font face="Arial, Helvetica, sans-serif">Item Rate</font></th>
    </tr>
<?php
$sql = mysql_query("SELECT * from item
                    where category like '$category%'
                    and type like '$type%'");
$num = mysql_num_rows($sql);
$i = 0;
    while ($i < $num) {
    $f1=mysql_result($sql,$i,"item");
    $f2=mysql_result($sql,$i,"specification");
    $f3=mysql_result($sql,$i,"rate");
?>
<tr>
<td><input type="checkbox" name="item[]" id="item" value="<?php echo $f1; ?>"/></td>
<td align="center"><font face="Arial, Helvetica, sans-serif" color = 'red'><b><?php echo $f1; ?></font></b></td>
<td align="center"><font face="Arial, Helvetica, sans-serif" color = 'red'><b><?php echo $f2; ?></font></b></td>
<td align="center"><font face="Arial, Helvetica, sans-serif" color = 'red'><b><?php echo $f3; ?></font></b></td></tr>
<?php  $i++; 
}
?>
</table>
<input type="submit" name="add" value="Submit">
</form>
于 2013-07-29T09:20:05.437 回答