hi can someone help? I'm retrieving from database and i want to display it on screen. i use aler in my ajax to see if it's working but it's not alerting anything. anyone can tell me what's wrong?

client:
function client{
...
....
public function GetMarks(){
        $query=mysql_query("SELECT users.name, marks.MarksHighest FROM marks,users WHERE marks.name=users.name ORDER BY MarksHighest ASC");
        $q=mysql_fetch_assoc($query);
        $name=$q["users.name"];
        $high=$q["marks.MarksHighest"];
        $mk=array("Name"=>$name,"Marks"=>$high);
        $mk1=json_encode($mk);
        echo $mk1;
    }
    ..
}



ajax call:

server.prototype.GetMarks=function(){
        $.ajax(
        {url:"getmark.php",
        type:"POST",
        dataType:"json",
        success:function(data){
            alert(data.Name);

        }});
    }




getmark.php
<?php
   //import connection file and appropriate php file
    $con=new server();
    $client1=new client();
    $con->connect();

    $x=$client1->GetMarks();

?>
getting this error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\.....client.php on line 34
{"Name":null,"Marks":null}

i think you need to pass connection reference to mysql_query() function as follows

$query=mysql_query("SELECT users.name, marks.MarksHighest FROM marks,users WHERE marks.name=users.name ORDER BY MarksHighest ASC",**$your_conn_reference_here**);

check it once

let me know the status

my connection is like this in getMarks()

<?php
include('connect.php');
include('client.php');
$connection=new server();
$clientcom=new ClientCommunicator();
$connection->connect();
..
?>

which one i should include? i dont think so. coz i have serveral function in my client.php and it works well!

i think it may be $clientcom reference

try to use that reference in mysql_query($query,$clientcom) function

because in your first post you called GetMarks() method by using client connection

getmark.php
<?php
//import connection file and appropriate php file
$con=new server();
$client1=new client();
$con->connect();
$x=$client1->GetMarks();
?>

so thats the reason you have to pass $clientcom reference

check it once and let me know the status

happy coding

Instead of adding the connection, make sure your connection is actually successful. It's definitely NOT $clientcom because that's an object, not a resource.

@pritaeas my connection is working. because like i said i got several queries working at the same time and am having good response.only this one is giving me this error! why this?
@radhakrishna its client1 not clientcom. i make a mistake in my previous post

no one will help? :(

The error message means that the query has failed. So it's either (in order):

  1. mysql_connect failed
  2. mysql_select_db failed
  3. mysql_query failed

Since you think it's the last one, do this:

$query = mysql_query("SELECT users.name, marks.MarksHighest FROM marks,users WHERE marks.name=users.name ORDER BY MarksHighest ASC") or die(mysql_error());

See if you get an error message, and post it here.

actually am trying to retrieve a whole column. i think there should be a loop to echo the values. am i right? if so how is it done?

i check my query in easyphp, it's ok. my connection also is working fine!! where the problem?
the problem is here :
$q=mysql_fetch_assoc($query);

I dont think it's capturing the whole data in the column users.name and marks.marksHighest! any idea?

i solve it. should call the field name directly name and marksHighest instead users.name....
but am having another problem, its alerting me in ajax. alert(data.Name). any clue abt this?

its alerting me in ajax. alert(data.Name). any clue abt this?

Not sure what you mean by this.

i retrieve my data and add to associative array in php. now in ajax i want to alert it.but it's alerting me object or undefined! here the code:

server.prototype.GetMarks=function(){
        $.ajax(
        {url:"getmarks.php",
        type:"POST",
        dataType:"json",
        success:function(data){
            alert(data.Name);
        }});
    }

You can inspect the value of data if you debug in the browser. Code appears fine, without seeing it in action, I can't guess what the problem might be.

no error in browser :/

i know where the problem. should alert(data[0].name);

Thanks mate .appreciate your help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.