使用<a href=""> for a mysqli select statement

时间:2015-11-04 02:32:00

标签: php mysqli href

could someone please direct me to a simple (basic easy) tutorial or resource page of how to use hyperlinks in a website to display the results of a select statement

To be precise - I am working on the footer section of my website http://www.mandyevansartist.com 当有人点击“彩色铅笔”字样时我希望将它们带到catagory.php页面并显示数据库中的数组

我知道这是可能的,因为我已经通过点击图片让它发挥作用了 - (http://www.mandyevansartist.com/gallery.php页面中有一个区域显示&#39;点击图片查看该类别中的其他人&#39; 39)

我已经通过

实现了这个目标
    <?php
session_start();
include 'header.php';
echo '<h1>CLICK ON AN IMAGE TO SEE OTHERS IN THAT CATAGORY</h1>';
$con = mysqli_connect("*","*","*","*");
$db = mysqli_select_db("images", $con);

$answer = mysqli_query($con,"SELECT image FROM images where HEAD = 'true'");
echo '<div id = "list">';
echo '<ul>'; 
    while   ($row   =   mysqli_fetch_array($answer))    {
    $pic = $row[image];
    $link ="<a href = 'catagory.php?id=".$row[image]."'>" . ' <img src="'.$pic.'" style ="height:222px;"/> '. "</a>";
echo '<li>' .$link.'</li>';  
    }
echo '</ul>';
echo '</div>';
?>

此时我的footer.php主要是html(用回声&#39;&#39;封闭),链接无处不在

    <div id="footer-one">
<h1>GALLERY</h1>
<p><a href = "#" >people pictures</a></p>
<p><a href = "#" >romance</a></p>
<p><a href = "#" >seascapes</a></p>
<p><a href = "#" >under the ocean</a></p>
<p><a href = "#" >paintings</a></p>
<p><a href = "#" >love heart series</a></p>
<p><a href = "#" >new works</a></p>
</div><!--/footer-one-->

我尝试将mysqli查询插入其中的方法之一

        <h1>GALLERY</h1>';
 $answer=mysqli_query($con,"SELECT image FROM images WHERE catagory =    pencils");
 while ($answer2 = mysqli_fetch_array($answer));    
 $link = <p><a href = "catagory.php?id=$answer2">family portraits</a></p>
 echo '<p>' .$link.'</p>';
 echo' <p><a href = "#" >coloured pencils</a></p>

只是出现了一个解析错误 - 意外&#34;&lt;&#34;

我正在寻找一个指导我完成这个过程的教程,因为我看了看,但找不到一个

1 个答案:

答案 0 :(得分:1)

错误parse error - unexpected "<"是由于'"{}之类的错误所致。请尝试以下修复程序。

<?php 
$answer = mysqli_query($con,"SELECT image FROM images WHERE catagory = pencils");
while ($answer2 = mysqli_fetch_array($answer));
{
    $img = $answer2['image'];
    $link = "<a href = 'catagory.php?id=$img'>family portraits</a></p>";
}
echo '<p>'.$link.'</p>';
echo '<p><a href = "#" >coloured pencils</a></p>';
?>

从给定的代码中,我提出了这些修复。但是根据您的要求可能会有一些变化。