dpm91915 2014-02-17 06:19
浏览 51
已采纳

在while循环中添加指向数据库调用元素的链接

I want to add link to the searched element which is done through ajax. In search.php I've following code but apparently it's not working.

while($row = mysql_fetch_array($res_old))
{
  echo "<li style='border-bottom: 1px solid #A5ACB2; padding:5px; margin-left:-40px;margin-right:5px;>";
  $productid=$row['productid'];
  echo "<a href='search.php?productid='$productid'>";
  echo $row['brand'];
  echo "&nbsp";
  echo $row['product_name'];
  echo "&nbsp";
  echo $row['short_desc'];
  echo "&nbsp";
  echo "&#8377;";
  echo $row['price'];
  echo "</a>";
  echo "<br>";
  echo "</li>";
}

Anybody can shade some light on why it's not working? Just link is not being added, results are coming fine.

  • 写回答

2条回答 默认 最新

  • dongziya9863 2014-02-17 06:34
    关注

    The actual problem here is not a missing tag, but unmatched quotes.. or rather, misplaced quotes.

    Here is your current opening tag:

    <a href='search.php?productid='$productid'>
    

    If you will notice the syntax highlighting, it becomes clear what is wrong here; since attribute values can be denoted by quotes, you actually end your attribute value at the first quote it sees, thus giving a malformed a tag.

    If you want your code to work, you have to either escape those quotes, or do something else:

    <a href='search.php?productid=$productid'>
    

    For instance, the above has removed the quotes, so the tag parses correctly now.

    Of course, this isn't the only error:

    echo "<li style='border-bottom: 1px solid #A5ACB2; padding:5px; margin-left:-40px;margin-right:5px;>";
    //                                                                            Right here           ^, this should be an ending single quote.
    

    On this line, you never close your style attribute with a quote, thus messing up any following html.

    The corrected line is as follows:

    echo "<li style='border-bottom: 1px solid #A5ACB2; padding:5px; margin-left:-40px;margin-right:5px;'>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题