0

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!

4

1 回答 1

0

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.

于 2012-09-21T22:26:59.093 回答