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.

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

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题