Can’t figure out how to capture PHP Generated Row Data to $.post()

Can’t figure out how to capture PHP Generated Row Data to $.post()

Greetings to all,

I’m a complete newbie to jquery.  I started out of GREAT necessity as I’m writing a meal plan function where I want to post a particular food to “my favorites” and found that while PHP is truly powerful, it has one limitation – I have to send things to the server to process them (yes, that was my attempt at humor).

I wrote my first jquery driven $.post that calls a PHP page, that actually does the store for me.  This works great.  However, the “ignorance” I’m hoping someone will cure from me comes from the fact that my button, only posts the “first” row of information.

The table I generate from a search for foods.  It lists all the foods that match the description.  Then I added, like I do in PHP a form button to Post the data from that row to my Favorite’s table.  However, this does not work with the way I wrote my function.

The function I wrote is this:

  1. <script type="text/javascript" src="js/jquery-1.5.2.min.js"></script>
  2. <script type="text/javascript">
  3.                 function fav_store() {
  4.                                 $('#stored').hide();
  5.                                 $.post('meal_fav_post.php', {

  6.                            NDB_No: $('form[name=favorites] input[name=NDB_No]').val(),
  7.                              user_id: $('form[name=favorites] input[name=user_id]').val(),
  8.                          MM_insert: $('form[name=favorites] input[name=MM_insert]').val() 
  9.                                                                                                                    },
  10.                                                                 function(result) {
  11.                                                                                 $('#stored').html(result).show();
  12.                                                                 });
  13.                 }
  14. </script>

 

The button is part of a DO WHILE loop in PHP and here’s the code:

  1. <?php do { ?>
  2.       <tr>
  3.         //lots of stuff here then       

  4.             <td>
  5.               <form name="favorites" id="fav_form">
  6.                 <input type="hidden" name="NDB_No" value="<?php echo $row_test_food_selection['NDB_No']; ?>" />
  7.                <input type="hidden" name="user_id" value="1" /> (Note user_id = 1 for testing only)

  8.                <input type="hidden" name="MM_insert" value="form1" />
  9.                 <input type="button" value="Add To Favorites" onclick="fav_store();" />
  10.               </form>  
  11.                 <div id="stored">This is where I want to display my results</div>
  12.                 </td>
  13.     </tr>
  14.       <?php } while ($row_test_food_selection = mysql_fetch_assoc($test_food_selection)); ?>
Please forgive my ignorance, but before I started looking for tutorials on this, I drank java, not programmed in it, so this is really new to me.

Thanks in advance to anyone with the patience to teach me how to fix this.

Paul