pocobueno1388 Posted June 16, 2007 Share Posted June 16, 2007 Hello =] I am creating a script for my horse simulation site that displays the persons horses depending on what gender of horse they select. There are three links above the horses that say "mare", "stallion", and "foals", I want it so when they click on one of those links it will automatically update the MySQL query to match what they want displayed, then it will automatically switch the horses out to the ones they want displayed without the page even moving. I wrote some code, but I have NO idea if I'm even on the right track....so I need some advice on how to set this up. This is what I have so far: <?php include 'header.php'; ?> <script language="javascript"> function changeGender(gender){ new_gender = gender; } </script> <?php $getHorses = mysql_query("SELECT * FROM horses WHERE ownerID='$sid' AND gender='????'"); ?> <center><h1>STABLE NAME</h1></center> <p> <center> <a href="#" onclick="changeGender('mare')">Mares</a> || <a href="#" onclick="changeGender('stallion')">Stallions</a> || <a href="#" onclick="changeGender('foal')">Foals</a> </center> <table class="dark" width="50%" align="center" cellpadding=5> <tr align="center" class="medium"> <td><b>Name</b></td> <td><b>Breed</b></td> <td><b>Gender</b></td> <td><b>Age</b></td> <tr align="center"> <?php while ($row = mysql_fetch_assoc($getHorses)){ echo '<td class="light">' .out($row['name']) .'</td>'; echo '<td class="lightest">' .out($row['breed']) .'</td>'; echo '<td class="light">' .out($row['gender']) .'</td>'; echo '<td class="lightest">' .out($row['age']) .'</td>'; echo '<tr align="center">'; } ?> </table> First of all, I don't even know if I am calling the changeGender() function correctly in my links. <a href="#" onclick="changeGender('mare')">Mares</a> Second, I'm not sure how to replace the "????" with the javaScript variable that the function comes up with. <?php $getHorses = mysql_query("SELECT * FROM horses WHERE ownerID='$sid' AND gender='????'"); ?> It would be greatly appreciated if someone could help me out with this =] Thank you all very much. Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 16, 2007 Share Posted June 16, 2007 Looks like you'll need to use AJAX for this one. Unless you want to reload the whole page again with the new gender and in that case you really won't need javascript. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 16, 2007 Author Share Posted June 16, 2007 Ohhhh, I had no idea this was something javascript couldn't do. I guess this "luxury" for my players will have to come later on when I am ready to start leaning AJAX. Thanks for the help =] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.