dongxi1943 2012-09-21 19:18
浏览 146
已采纳

如何将mysql查询结果作为变量传递给另一个查询搜索?

Ok so basically I've got a product database. members search the database by clicking on categories of their choice.

These categories are spans which all trigger a javascript (ajax) function which calls a php query to find all of the subcategories of the span just clicked.

Those subcategories are outputted in a while loop which creates more spans which also trigger the same js function which will link back to the query.

The code below shows the output of the categories displayed based on the output of the database query.

  "<div id=\"div1\">";
while($row = mysql_fetch_array($result))
{
$spans++;

echo " <span id=\"$spans\"         
onclick='serverconnect(\"http://localhost/dreamweaver/Website/webdev/Code structure.php\", 
\"nya\")'> $row[1] </span>";    
 echo "<br />";
}


"</div>";

So let's say the output of this is:

HEALTH FITNESS EDUCATION LEISURE

How could i pass the span names as values for the next query so that whatever span is clicked on gets its appropriate value passed to the database search?

Would i have to somehow assign the contents of each span to a variable and then pass the variable to the javascript function which would then pass it to the query?

Im out of ideas as to how to do that, or if i should do it another way.

Thanks!

  • 写回答

1条回答 默认 最新

  • duangang1991 2012-09-21 22:26
    关注

    Try replacing:

    echo " <span id=\"$spans\"
       onclick='serverconnect(\"http://localhost/dreamweaver/Website/webdev/Code structure.php
       \", \"nya\")'> $row[1] </span>";    
    

    With:

    echo " <span id=\"$spans\"
       onclick='serverconnect(\"http://localhost/dreamweaver/Website/webdev/Code
       structure.php?value=" . urlencode($row[1]) . "\", \"nya\")'> $row[1] </span>";    
    

    You may then retrieve the value in $_GET['value'] after clicking the SPAN.

    Note: I added some line breaks in the text for ease of reading, don't forget to remove them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况