SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to return a individual rows using ajax

    Hi,

    I am using jquery ajax with PHP and I would like to return individual rows instead of html. here is my code:

    Code:
    $('#btnShowDetails').click(function(){
        $.ajax({
            url : "get_company_details.php",
            data : 'id=ed23e767-539f-11e3-aef0-74de2b9a31a4',
            type : "post",
            success : function(data)
            {
                $('#lblCompanyName').text(company name from data result);
                $('#lblCompanyWebsite').text(company website from data result);
            }
        });
    });
    and here is my get_company_details.php:

    Code:
    <?php
        include('../includes/php_header.php');
        include($_SESSION["absolute_path"] . '/includes/connect2db.php');
        
        if (!isset($_SESSION["member_loggedOn"])) { exit(header("Location: ../signin")); }
        
        $mysql_query = $mysql_connection->prepare("CALL sp_get_company_details(:param_company_guid)");
        $mysql_query->bindParam(':param_company_guid', $_GET["id"], PDO::PARAM_STR);
        $mysql_query->execute();
    
        $mysql_row_count = $mysql_query->rowCount();
    
        if ($mysql_row_count <= 0) { exit(header("Location: " . $_SESSION["domain_name"] . "home")); }
    
        while ($mysql_row = $mysql_query->fetch())
        {
            $company_id = $mysql_row["company_id"];
            $company_guid = $mysql_row["company_guid"];
            $company_name = $mysql_row["company_name"];
            $company_industry = $mysql_row["industry_name"];
            $company_country = $mysql_row["country_name"];
            $company_region = $mysql_row["region_name"];
            $company_telephone = $mysql_row["company_telephone"];
            $company_fax = $mysql_row["company_fax"];
            $company_website = $mysql_row["company_website"];
            $company_email = $mysql_row["company_email"];
            $about_company = $mysql_row["about_company"];
            $hide_email = $mysql_row["hide_email"];
        }
    ?>

    Thanks,
    <snip/>
    Last edited by Mittineague; Jan 11, 2014 at 16:45.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,799
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Whatever the PHP echos is what is going to get returned. If you want one row returned from each call to the server then you will need to restructure the PHP so that it echos one row each time it is called. So the while loop will go and the query will need to be changed to get the next row satisfying the condition rather than all of the rows.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How? do you a sample?


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
  •