Skip to main content
Jan 29, 2010 12:52 AM UTC
Question

dynamically inserting DB data into ajax pagination script

Hey everyone,

   I stumbled across this great pagination script that uses ajax earlier today.  Its a REAL good one but im having problems getting it to work with my database.   The link to it is here if anyone wants to check it out. http://www.dynamicdrive.com/dynamicindex17/ajaxpaginate/index.htm

If you go to the second page it explains how to get data from the DB.  It seems like he is using the ids as page numbers.

I want to display 5 records at a time, each of which gets it info from different tables.

this is the code I have for such, and it works...

$query1 = "SELECT * FROM video WHERE video_username = '$username' ORDER BY video_upload_date DESC;

        mysql_select_db($database_db294582132, $db294582132);

          $result1 = mysql_query($query1, $db294582132) or die(mysql_error());

// extract the first record as an array

    while($row1 = mysql_fetch_assoc($result1)){


          $video_id      = $row1['video_id'];
        $thumb         = $row1['video_t_filename'];
        $video_title   = $row1['video_title'];
          $song_name     = $row1['video_song_name'];
          $song_artist   = $row1['video_song_artist'];
          $song_unknown  = $row1['video_song_unknown'];
        $caption       = $row1['video_caption'];
        $vehicle_id    = $row1['vehicle_id'];
        $video_setup   = $row1['setup_id'];
        $upload_date   = date("m.d.'y, g:i a", strtotime($row1['video_upload_date']));
//get vehicle info
        $query2 = "SELECT * FROM user_vehicles WHERE vehicle_id = '$vehicle_id'";
        mysql_select_db($database_db294582132, $db294582132);
          $result2 = mysql_query($query2, $db294582132) or die(mysql_error());
        $row2    = mysql_fetch_assoc($result2);
        $year        = $row2['vehicle_year'];
        $make        = $row2['vehicle_make'];
        $model       = $row2['vehicle_model'];
//Get setup info   
        $query4 = "SELECT * FROM vehicle_setups WHERE setup_id = '$video_setup'";
     mysql_select_db($database_db294582132, $db294582132);
       $result4 = mysql_query($query4, $db294582132) or die(mysql_error());
     $row4 = mysql_fetch_assoc($result4);
         $setup = $row4['setup'];
//provide format for uploaded videos section
         echo
         '<div id="shopVidsDiv"><div id="editButtonDiv"><a href="editVideos.php">edit</a></div>
<div id="vehicleDescriptionDiv"><div id="title"><span class="videoStatHeading">TITLE: </span>',$video_title,'</div><div id="Caption"><span class="videoStatHeading">CAPTION: </span>
',$caption,'</div>
    <div id="song"><span class="videoStatHeading">SONG NAME: </span>',$song_name,'<span class="videoStatHeading"> ARTIST: </span>',$song_artist,'</div><div id="vehicle"><span class="videoStatHeading">VEHICLE: </span>',$year,' ',$make,' ',$model,'</div><div id="setup"><span class="videoStatHeading">SETUP: </span>',$setup,'</div><div id="uploadDate"><span class="videoStatHeading">UPLOADED ON: </span>',$upload_date,'</div></div>
<img src="images/videoThumbs/',$thumb,'.jpg" width="100" height="75" alt="',$caption,'" />
</div>';

I cant seem to get that part inserted correctly into

var bookonflowers={
PUT DYNAMIC CODE HERE,
selectedpage: 0 //set page shown by default (0=1st page)
}

That is where he puts his dynamic code in his example

Any help is appreciated on how to do this, I just need a better explanation and a lil guidance.  thanks

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Participating Frequently
Jan 29, 2010 1:08 AM UTC

>I want to display 5 records at a time, each of which gets it info from different tables.

I can't really help with the php, but just wondering why you are creating 4 queries/result sets since all of the records appear to be related. Why not just pull it all into a record set?

Translate
Jan 29, 2010 11:14 PM UTC

What do you mean exactly by a record set?  This is the first site i've ever made and ive made it from the ground up so sorry if im not to keen on the terminology... I've heard of them but never knew exactly what they were. is it like a database query?

Last night I was trying to condense the three queries into one using a join but I decided not to b/c the last 2 dont always need to get processed(optional inputs).  But if there is any way to make that code cleaner then by all means... please share.

As for everyone else reading this... any ideas on putting this into my ajax pagination?

Translate
Participating Frequently
Jan 30, 2010 12:20 AM UTC

>What do you mean exactly by a record set?

A recordset is just the results of a sql query.

>Last night I was trying to condense the three queries

>into one using a join but I decided not to b/c the last 2

>dont always need to get processed(optional inputs).

Yes, you should combine all of the queries as it will make your code much simpler and easier to maintain.Only resort to using procedural languages when you can't accomplish what you need using SQL, or if it greatly improves performance.

Not sure what you mean by optional inputs. Do you mean that there is not always data in some of the related tables?

Translate