4 Replies - 2230 Views - Last Post: 28 November 2012 - 07:25 AM Rate Topic: -----

#1 jakemmarsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 13-February 12

Dynamically display data from MYSQL rows

Posted 27 November 2012 - 08:19 AM

I have a table called "events" with the columns 'id', 'school_id', 'what', 'where', 'when', 'details'.

I'm currently using the following code to display data on my page "events.php":
    <?php
    $event_query = mysql_query("SELECT * FROM events WHERE school_id = '$school_id'") or die(mysql_error());;

    while($events = mysql_fetch_array($event_query)){
        print "<strong>Event:</strong> ".$events['what'] . " ";
        print "<br />";
        print "<strong>Location:</strong> ".$events['where'] . " ";
        print "<br />";
        print "<strong>Time:</strong> ".$events['when'] . " ";
        print "<br />";
        if ($events['details'] != ""){
            print "<strong>Additional Details:</strong> ".$events['details'] . " ";
            print "<br />";
        }
        print "<br />";
    }    

    ?>



However, what I want to be able to do is dynamically (I assume using jquery/ajax) display rows added to the table. For example, if someone submits an event and it is added to the table, I want to dynamically update the page with the new event without refreshing.

I also only want to show the newest 20 at a time, until the user scrolls to the bottom (and then show 20 more).

What would be the best way to approach these two things? Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Dynamically display data from MYSQL rows

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5178
  • View blog
  • Posts: 26,870
  • Joined: 10-May 07

Re: Dynamically display data from MYSQL rows

Posted 27 November 2012 - 08:22 AM

View Postjakemmarsh, on 27 November 2012 - 10:19 AM, said:

I also only want to show the newest 20 at a time, until the user scrolls to the bottom (and then show 20 more).

I would load all of the database entries into an array, & then handle the display with jquery.
Was This Post Helpful? 1
  • +
  • -

#3 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: Dynamically display data from MYSQL rows

Posted 27 November 2012 - 09:05 AM

Well, unless the database is "lotsabig"!
You want to choose some reasonable amount of data that won't kill your server on every request. If the client won't usually want to see all 1500 "pages" (here defines as a set of 20 results) of results, then obviously don't load it all from db. The user will probably scroll trough few pages, so preload those and then do it as you need.
Was This Post Helpful? 0
  • +
  • -

#4 jakemmarsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 13-February 12

Re: Dynamically display data from MYSQL rows

Posted 27 November 2012 - 04:05 PM

View PostXupicor, on 27 November 2012 - 09:05 AM, said:

Well, unless the database is "lotsabig"!
You want to choose some reasonable amount of data that won't kill your server on every request. If the client won't usually want to see all 1500 "pages" (here defines as a set of 20 results) of results, then obviously don't load it all from db. The user will probably scroll trough few pages, so preload those and then do it as you need.


I realize I only need to load a few at my first. My question is HOW to load more upon scrolling (ajax/jquery??) and HOW to dynamically update the page upon new row creation.
Was This Post Helpful? 0
  • +
  • -

#5 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: Dynamically display data from MYSQL rows

Posted 28 November 2012 - 07:25 AM

Yes, with AJAX - jQuery can do that. As to how to do that upon scrolling down, Google it and check how others did it. Or just peep the code at facebook/google.
http://www.fieg.nl/i...a-jquery-plugin
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1