通过url将id传递给第二页

时间:2013-11-24 04:31:03

标签: php mysql

我正在尝试将id传递给第二页,我从另一个表中选择但下面的代码无效。当我做var_dump时,我可以看到值是我想要的,但主查询的行没有显示(标题和图像没有显示)。

我有两个查询,其中一个在另一个内。有人可以帮我吗?如果我摆脱第二个查询的while loop,主查询就可以正常工作。

        $paginate = new pagination($page, "SELECT * FROM table1 where title != '' ORDER BY id desc"  , $options);
           }
           }
           catch(paginationException $e)
           {
            echo $e;
            exit();
            }
           if($paginate->success == true)
            {
            $result = $paginate->resultset->fetchAll();
            foreach($result as $row)

            {
            $dx = $row['image_one'];//image_one from main query
            //second query
            $item = $mydb->prepare("select * from table2 where imageone  = ?");
            $item->bind_param('s', $dx);
            $item->execute();
            $item_res = $item->get_result();
            while($row = $item_res->fetch_assoc()){
            $rx = $row['id'];
            var_dump($rx);
            }   //the rows below aren't being displayed   
            $path = 'images/';
            echo "<a href='second.php?title=".urlencode($row['title'])." &amp;item=".$row['id']."&amp;id=".$rx."'>"."<img src='".$path."".$row['image_one']."'/></div>"."</a>";
            }

2 个答案:

答案 0 :(得分:1)

试试这个:

echo "<a href='second.php?title="'.urlencode($row['title']).'" &amp;item="'.$row['id'].'"&amp;id="'.$rx.'"'>"."<img src='"'.$path.'"".$row['image_one']."'/></div>"."</a>";

在var name

周围使用' '

答案 1 :(得分:0)

一旦退出$ row,你在while循环中重新分配$ row为空。

请改为尝试:

while($item_row = $item_res->fetch_assoc()) {
   $rx = $item_row['id'];
}  

此外,您应该尝试使用连接,而不是嵌套查询。

相关问题