PHP Classes

I'm basically using this to display results from my MySQL dat...

Recommend this page to a friend!

      AJAX Paginator  >  All threads  >  I'm basically using this to display...  >  (Un) Subscribe thread alerts  
Subject:I'm basically using this to display...
Summary:Package rating comment
Messages:6
Author:Josh LaMar
Date:2009-11-06 00:41:34
Update:2009-11-08 00:21:45
 

Josh LaMar rated this package as follows:

Utility: Good
Consistency: Good
Documentation: Good
Examples: Good

  1. I'm basically using this to display...   Reply   Report abuse  
Picture of Josh LaMar Josh LaMar - 2009-11-06 00:41:35
I'm basically using this to display results from my MySQL database in an interactive real-time AJAX-like fashion. How can I add more columns? Also if I add something to the database will it update on the AJAX page?

  2. Re: I'm basically using this to display...   Reply   Report abuse  
Picture of Omar Abdallah Omar Abdallah - 2009-11-06 11:27:54 - In reply to message 1 from Josh LaMar
Adding new columns is simple,
1. You will have to do this in your query ( make sure you use the same query for the page itself and the subpage that loads by ajax)
2. You will edit the display table to add the additional column
3. If you want to make it searchable you will have to add to 'fields' array

Example case:
Let's say you have another column called age

I'm gonna change the follwing
query: $query = "SELECT id, name, age FROM customers"; or just use astrisk

the display table changes will look like that:
<div id="listing_container">
<table border="0" cellpadding="2" cellspacing="0" class="listing">
<tr>
<th nowrap="nowrap" width="40" align='left'> ID</th>
<th nowrap="nowrap" width="450" align='left'>Name</th>
<th nowrap="nowrap" width="50" align='left'>Age</th>
</tr>
<?php

foreach($rows as $row){
echo "<tr>";
echo "<td nowrap='nowrap' align='center'>{$row['id']}</td>";
echo "<td nowrap='nowrap' align='left'>{$row['name']}</td>";
echo "<td nowrap='nowrap' align='left'>{$row['age']}</td>";
echo "</tr>";
}

echo "</table><br />";


and you also have to do the same changes on the subpage.php

About a realtime database update. I did not implement it but sure you can... actually its much easier using Jquery's ajax. but I didn't use it in the examples just to make it easy to understand for developers who are not familiar with jquery.

If you have any other questions you are most welcome.

  3. Sorting by Column   Reply   Report abuse  
Picture of Josh LaMar Josh LaMar - 2009-11-06 17:40:53 - In reply to message 2 from Omar Abdallah
Let's say I want to add a sorting feature where I can just click on table heading (let's say Name) and it sorts it in alphabetical order. How about numerical (such as ID) and chronological order (such as date)?

  4. jQuery   Reply   Report abuse  
Picture of Josh LaMar Josh LaMar - 2009-11-07 18:20:55 - In reply to message 2 from Omar Abdallah
I was looking at the jQuery Ajax functions (http://docs.jquery.com/Ajax) and wasn't sure how to go about displaying an interactive live-updating MySQL database using jQuery's Ajax. Did you have something specific in mind?

To be more specific I have a design for a leader board for a bicycle race. I'm using RFID to track the lap times and those times are recorded to a MySQL database. I want to change rider position automatically each time the database gets a new read. The more animated and user interactive I can get the leader board to be the better, which is why I think jQuery was a good suggestion. Any thoughts?

  5. Re: I'm basically using this to display...   Reply   Report abuse  
Picture of Omar Abdallah Omar Abdallah - 2009-11-07 23:27:47 - In reply to message 4 from Josh LaMar
The documentation of jquery.com is a bit poor. see this tutorial:
ibm.com/developerworks/library/x-aj ...
or google : jquery ajax tutorial
you'll get what you need.

for the position thing I thing you'll have to call the server on time intervals.. let me think and get back to you. I've searched alot for implementing a sleep function in js but nothing's working till now..



  6. Re: I'm basically using this to display...   Reply   Report abuse  
Picture of Omar Abdallah Omar Abdallah - 2009-11-08 00:21:45 - In reply to message 4 from Josh LaMar
I've found the solution

The concept is about recursion

You'll have the php script on the server to send a flag to continue requesting the position or the race is finished.

function getPosition(){
// send the ajax request
if (raceEnded == false){
// do the html work to move the players
getPosition();
}else{
// halt the execution of the function
return false;
}
}

hope that helped.