dongxi1943
dongxi1943
2012-09-21 19:18

如何将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 duangang1991 9年前

    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.

    点赞 评论 复制链接分享

相关推荐