Jump to content

[SOLVED] Changing a mysql query with a javascript function....?


pocobueno1388

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.