Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8431495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:52:14+00:00 2026-06-10T05:52:14+00:00

I don’t know what’s wrong, the question is i’m trying to return the values

  • 0

I don’t know what’s wrong, the question is i’m trying to return the values from a mysql query for print in a html div (#receptor) but is not printing any value, i’m trying to make a call after make the request to an external function define below for print the JSON source, this is what i’m trying to do for now:

result.php

    <?php
    $library = "DbConnection.inc.php";
    if (is_readable($library)){
            require $library;}else{
            throw new RuntimeException("No se Pudo Incluir la ${library}");
    }


    $db = new DbConnection('localhost','root','','macrotelecom');

    switch (@$_REQUEST['action'])
    {
       case "consultar" :
        $db->connect();
        $data =  $db->getAllRows("SELECT * FROM Caracter");
        $db->disconnect();    
        echo json_encode($data);      
        exit;


    }


    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src='jquery-1.7.1.min.js' ></script>
    <script type="text/javascript">
    $(function(){ 
      $("#consultar").click(function(){
        $("#receptor").text("Consultando....");        
          $.post("result.php",{action:"consultar"}, respuesta,'json')
       });
    });



    function respuesta(arg){

       $("#receptor").html(arg.toSource());
    }
    </script>
    </head>
    <body>
        </br>
        <input type="button" id="consultar" value="consultar">
        <div id="receptor" style="border: solid 1px black; height: 100%; width: 100%;">

        </div>
    </body>
    </html>

But, if i make a call within $.post function, it works, but i don’t want to do this:

    <?php
    $library = "DbConnection.inc.php";
    if (is_readable($library)){
            require $library;}else{
            throw new RuntimeException("No se Pudo Incluir la ${library}");
    }


    $db = new DbConnection('localhost','root','','macrotelecom');

    switch (@$_REQUEST['action'])
    {
       case "consultar" :
        $db->connect();
        $data =  $db->getAllRows("SELECT * FROM Caracter");
        $db->disconnect();    
        echo json_encode($data);      
        exit;


    }


    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src='jquery-1.7.1.min.js' ></script>
    <script type="text/javascript">
    $(function(){ 
      $("#consultar").click(function(){
        $("#receptor").text("Consultando....");        
          $.post("result.php",{action:"consultar"}, respuesta,'json')
       });
    });



    function respuesta(arg){

       $("#receptor").html(arg.toSource());
    }
    </script>
    </head>
    <body>
        </br>
        <input type="button" id="consultar" value="consultar">
        <div id="receptor" style="border: solid 1px black; height: 100%; width: 100%;">

        </div>
    </body>
    </html>

What’s wrong, this drive my nuts seriously, i can’t undestand why is not print values, i define de datatype as json and nothing happens, i passed the paramater in the call “respuesta” like respuesta(data) and neither, i hope someone can give me a hand, i’m not able to see the solution.

I put the library code for database connection that i’m using for if you want to make local tests.

DbConnection.inc.php

    <?php
    class DbConnection {

      private $db_connection  = null;
      private $db_host     = '';
      private $db_user     = '';
      private $db_password = '';
      private $db_name     = '';
      private $errors      = array();



      public function __construct($db_host, $db_user, $db_password, $db_name)
      {
        $this->db_host     = $db_host;
        $this->db_user     = $db_user;
        $this->db_password = $db_password;
        $this->db_name     = $db_name;
      }

      public function connect()
      {
        if ( !$this->db_connection = @mysql_connect($this->db_host, $this->db_user, $this->db_password) ) {
          throw new RunTimeException("Couldn't connect to the database server");
        }
        if ( !@mysql_select_db($this->db_name, $this->db_connection) ) {
          throw new RunTimeException("Couldn't connect to the given database");
        }
        $this->executeQuery("SET CHARACTER SET 'utf8'");
      }

      public function disconnect(){
        if(mysql_close($this->db_connection)){
            return true;
        }
        return false;
      }

      public function getAllRows($sql)
      {
        if ( !$results = @mysql_query($sql, $this->db_connection) ) {
          throw new RunTimeException("Couldn't execute query: ". mysql_error($this->db_connection) );
        }

        $count = 0;
        $rows  = array();
        while ( $row = mysql_fetch_assoc($results) ) {
          $rows[] = $row;
          $count++;
        }
        return ($count)?$rows:false;
      }

      public function getOneColumn($sql)
      {
        if ( !$results = @mysql_query($sql, $this->db_connection) ) {
          throw new RunTimeException("Couldn't execute query: ". mysql_error($this->db_connection) );
        }

        $count = 0;
        $rows  = array();
        while ( $row = mysql_fetch_array($results) ) {
          $rows[] = $row[0];
          $count++;
        }
        return ($count)?$rows:false;
      }

      public function getArrayPair($sql)
      {
        if ( !$results = @mysql_query($sql, $this->db_connection) ) {
          throw new RunTimeException("Couldn't execute query: ". mysql_error($this->db_connection) );
        }

        $count = 0;
        $rows  = array();
        while ( $row = mysql_fetch_array($results) ) {
          $rows[$row[0]] = $row[1];
          $count++;
        }
        return ($count)?$rows:false;
      }

      public function getOneRow($sql)
      {
        if ( !$results = @mysql_query($sql, $this->db_connection) ) {
          throw new RunTimeException("Couldn't execute query: ". mysql_error($this->db_connection) );
        }

        if ( $row = mysql_fetch_assoc($results) ) {
          return $row;
        }
        return false;
      }

      public function getOneValue($sql)
      {
        if ( !$results = @mysql_query($sql, $this->db_connection) ) {
          throw new RunTimeException("Couldn't execute query: ". mysql_error($this->db_connection) );
        }

        if ( $row = mysql_fetch_array($results) ) {
          return $row[0];
        }
        return false;
      }

      public function executeQuery($sql)
      {
        if ( !@mysql_query($sql, $this->db_connection) ) {
          $this->errors[] = mysql_error($this->db_connection);
          return false;
        }
        return true;
      }

      public function getErrors()
      {
        return $this->errors;
      }

      public function getLastId()
      {
        return mysql_insert_id($this->db_connection);
      }

      public function countRows($table)
      {
        if (!is_string($table)) {
          throw new InvalidArgumentException("table_name isn't an string");
        }

        if ( !$results = @mysql_query("SELECT COUNT(*) as total FROM $table", $this->db_connection) ) {
          throw new RunTimeException("Couldn't execute query: ". mysql_error($this->db_connection) );
        }

        $count = mysql_fetch_array($results);
        $count = $count['total'];
        return ($count)?$count:0;
      }
    }

    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:52:15+00:00Added an answer on June 10, 2026 at 5:52 am

    You can also use it with this

    var id=$("#id").attr("value");
    $.getJSON("pages.php",{id:id},dates);
    function dates(datos)
    {
    
    $("#list").html("Name:"+datos[1].name+"<br>"+"Last Name:"+datos[1].lastname+"           
     <br>"+"Address:"+datos[1].address);
    }
    

    more help you will find it on here

    http://docs.jquery.com/Getjson

    hope this will help

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

don't know if the title describes anything about what I'm trying to say but
Don't know how to google for such, but is there a way to query
Don't know if I worded the question right, but basically what I want to
Don't know if this has been asked before, so point me to another question
Don't know how to explain it better but i'm trying to get a response
I don't know if this question is trivial or not. But after a couple
Don't know what's wrong here, when I run the application it says Specified method
Don't know where else to ask, but from one day to the other my
Don't know if it's I'm doing it wrong or if there's a bug (I
Don't know if I'm over-thinking this or not.. but I'm trying to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.