SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Ajax

  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax

    Hi,

    I am using ajax to load content within <div> tags, the problem is that I am trying to make a default record when the page is loaded. As a link is clicked the div tags are populated.. But by default upon arriving at the page the <div> is empty.

    Here is the link for the ajax

    PHP Code:
    <class=\"second\" href=\"javascript: AjaxRequest('main','./includes/portfoliodisplay.php?id=".$portfolioid."')\">Portfolio</a> 
    How can I take the latest record added and have it displayed as the default when the page is loaded ..

    Thanks

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by _matrix_ View Post
    Hi,

    I am using ajax to load content within <div> tags, the problem is that I am trying to make a default record when the page is loaded. As a link is clicked the div tags are populated.. But by default upon arriving at the page the <div> is empty.

    Here is the link for the ajax

    PHP Code:
    <class=\"second\" href=\"javascript: AjaxRequest('main','./includes/portfoliodisplay.php?id=".$portfolioid."')\">Portfolio</a> 
    How can I take the latest record added and have it displayed as the default when the page is loaded ..

    Thanks
    It sounds like you need to use the onLoad event.
    Code:
    <html>
    <body onLoad="//populate divs, and stuff.">
    </body>
    </html>

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Not really sure what I should be placing within onLoad?

    Thanks

  4. #4
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by _matrix_ View Post
    Hey,

    Not really sure what I should be placing within onLoad?

    Thanks
    Basically the same code that loads all the other content. Put it in a function, then call it.

    Code:
    function loadDefault() {
     // your AJAX call here
    }
    
    window.onload = loadDefault;

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Get the latest record with the MAX function of mysql itself if you are using mysql:
    PHP Code:
    $sql "SELECT * FROM tablename WHERE id=MAX(id)"
    For default:
    Just include the same file which is being called upon click via AJAX. You can check if whether the $_GET['id'] is set or not in including file portfoliodisplay.php:
    PHP Code:
    if(isset($_GET['id']){
        
    $sql "SELECT * FROM tablename WHERE id=" addslashes($_GET['id']);
    }
    else{
        
    $sql "SELECT * FROM tablename WHERE id=MAX(id)";
    }
    $result mysql_query($sql); 
    Does this make sense?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I allready tried:

    PHP Code:
        if(!$_REQUEST['id']) {
        
    $sql2 mysql_query("SELECT portfolioid FROM portfolio ORDER BY portfolioid DESC LIMIT 1");
        while(
    $row2 mysql_fetch_array($sql2)) {
        
    $id $row2['portfolioid'];
        }
        }else{
        
    $id $_GET['id'];
        
    $sql1 mysql_query("SELECT * FROM portfolio WHERE portfolioid = $id");
        } 
    But nothing populates the <div> tags as no link such as my first post has been clicked on. Just a simple link of ./portfolio.php has been selected to first navigate to the page.

    Thanks

  7. #7
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try like this then:
    PHP Code:
    if(!isset($_GET['id'])) {
        
    $sql2 mysql_query("SELECT portfolioid FROM portfolio ORDER BY portfolioid DESC LIMIT 1");
        
    $row2 mysql_fetch_array($sql2);
        
    $id $row2['portfolioid'];
    }
    else{
        
    $id $_GET['id'];
    }
    $sql1 mysql_query("SELECT * FROM portfolio WHERE portfolioid = $id");
    $row2 mysql_fetch_array($sql1);
    # now display the records
    echo $row2['portfolio_details']; 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  8. #8
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Tried that .. The problem is with populating the div field with a default record given that the link selected to load the portfolio page is

    <a href="./includes/portfoliodisplay.php?id=".$portfolioid">Portfolio</a>

    not

    <a class="second\" href=\"javascript: AjaxRequest('main','./includes/portfoliodisplay.php?id=".$portfolioid."')\">Portfolio</a>

    Thanks
    Last edited by _matrix_; Jul 22, 2008 at 18:28.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •