Current location: Hot Scripts Forums » Programming Languages » Other Languages » [SOLVED] AJAX within a table


AJAX within a table

Closed Thread
  #1 (permalink)  
Old 05-22-10, 11:45 AM
Jambone Jambone is offline
Newbie Coder
 
Join Date: Oct 2008
Location: Solihull, UK
Posts: 45
Thanks: 1
Thanked 0 Times in 0 Posts
AJAX within a table

Hi all,

I am trying to get this so it echoes out rows, according to an option selected in a drop down box

The drop down box is coded like so:
PHP Code:

<select id="depicao" name="depicao"><option value="">Please select a departure airfield</option>'; $selectflights = mysql_query("SELECT * FROM `airports`"); while($fselect = mysql_fetch_array($selectflights)) { echo '<option value="'. $fselect['icao'] .'">'. $fselect['name'] .'</option>'; } echo '</select
The table like so:
HTML Code:
<table width="700px" style="margin: 0 auto;border: 2px solid #696969;text-align: center;" id="flightlist">
<tr style="border-bottom: 1px dashed #000;">
<td style="padding: 5px;font-weight:900;">Flight ID<br />(click for full flight information)</td>
<td style="padding: 5px;font-weight:900;">Departure Airport</td>
<td style="padding: 5px;font-weight:900;">Arrival Airport</td>
<td style="padding: 5px;font-weight:900;">Equipment</td>
<td style="padding: 5px;font-weight:900;">Book this flight?</td>
</tr>'
</table>
The javascript page like so:
Code:
function getFlights() {
    if($('#depicao').val() == ''){
     $('#flightlist').html('<tr bgcolor="white"><td style="padding: 5px;" class="grey">There are no flights departing from the selected airport</td></tr>');
     } else {
        $.ajax({
            type: 'GET',
            url: '../ajax_funct/ajax.flightlist.php',
            data: 'depAirfield='+$('#depicao').val(),
            success: function(data){
                if($.trim(data) != 'false'){
                    $('#flightlist').html(data);
                } else  {
                    $('#flightlist').html('<tr bgcolor="white"><td style="padding: 5px;" class="grey">There are no flights departing from the selected airport</td></tr>');
                    }
                }
        });
    }
}
and the AJAX php update page like so:
PHP Code:

 <?

 
require('../mysql_connect.php');
 
$depicao $_GET['depAirfield'];
 
$listflights mysql_query("SELECT * FROM `flights` WHERE dep_icao = '$depicao'");
 if(
mysql_num_rows($listflights) >= 1) {
 while(
$alflights mysql_fetch_array($listflights)) {
$color1 '#f9f7bb';
$color2 '#bfd0f8';
 
$row_color = ($row_count 2) ? $color1 $color2
echo 
'<tr bgcolor="'$row_color .'" >
<td style="padding: 5px;" class="grey"><span class="rost"><a href="index.php?page=flightinfo&id='
$alflights['id'] .'">'$alflights['id'] .'</a></span></td>
<td style="padding: 5px;" class="grey">'
$alflights['dep_icao'] .'</a></td>
<td style="padding: 5px;" class="grey">'
$alflights['arr_icao'] .'</a></td>
<td style="padding: 5px;" class="grey">'
$alflights['equipment'] .'</a></td>
<td style="padding: 5px;" class="grey"><form method="post" action="booked.php?id='
$alflights['id'] .'&pid='$id .'"><input type="submit" value="" name="submit" style="border:none;background: url(\'images/book.png\');width:51px;height:16px;">
</form></td>
</tr>'
;
$row_count++;
}
} else {
echo 
'false';
}
?>
Thanks all
  #2 (permalink)  
Old 05-22-10, 01:30 PM
Jambone Jambone is offline
Newbie Coder
 
Join Date: Oct 2008
Location: Solihull, UK
Posts: 45
Thanks: 1
Thanked 0 Times in 0 Posts
Ok, I have managed to get it to work, forgot to set the onChange="" attribute, however now it shows the data, but not in a new row, instead it removes the other row, I think I can fix that by just entering the whole code to be echoed. Will let you guys know
  #3 (permalink)  
Old 05-22-10, 01:52 PM
Jambone Jambone is offline
Newbie Coder
 
Join Date: Oct 2008
Location: Solihull, UK
Posts: 45
Thanks: 1
Thanked 0 Times in 0 Posts
Alright, I managed to get it working Thanks anyway guys.
Closed Thread

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ajax hide/unhide html table esandra JavaScript 2 09-09-09 02:08 PM
calling a table through ajax function raizel AJAX 2 08-27-09 10:55 PM
MYSQL database countll Database 2 06-19-07 04:20 PM
What do you think of my database structure? Oskare100 Database 5 12-27-06 07:43 AM
Pretty simple ( i think) question any help!?!? 0o0o0 PHP 2 04-07-06 10:47 AM


All times are GMT -5. The time now is 03:47 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.