0

我的 php 中有两个要打印的数组。我希望将它们连接起来,但我不知道如何连接。$names 的数组打印,但描述数组“$desc”不打印。有什么办法可以同时打印吗?

    $query = "SELECT eName FROM Events";
            $query2 = "SELECT eDescription FROM Events";
            $result = mysql_query($query);
            $result2 = mysql_query($query2);
            $names = array();
            $desc = array();
            echo "hello there people!" . $query . " ".$result;
            for($i=0; $i<sizeof($result); $i++){
                echo $result[$i] ."\n" . $result2[$i];
            }
            while($entry = mysql_fetch_row($result)){
                $names[] = $entry[0];
            }
            while($entry2 = mysql_fetch_row($result2)){
                $desc[] = $entry2[0];
            }
            echo "Which Event would you like to see?<br>";
            $stop = count($names);
            //echo $stop . "\n";
            $i = 0;
            print_r($names);                
            print_r($desc);
            foreach($names as $value){
                    echo $value . " " . $desc[i] ."<br>";   
                                     $i++;              
            }
4

2 回答 2

2

为什么要执行两个查询以从同一源获取数据?

$sql = mysql_query("select `eName`, `eDescription` from `Events`");
while($row = mysql_fetch_assoc($sql)) {
    echo $row['eName']." ".$row['eDescription']."<br />";
}

简单得多。

于 2012-08-08T22:44:37.963 回答
0

试试这个:

        foreach($names as $key => $value){
                echo $value . " " . $desc[$key] ."<br />";                 
        }

只要数组$key匹配,信息就会一起打印。

于 2012-08-08T22:44:48.823 回答