0

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();

?>

Edited by techyworld

3
Contributors
17
Replies
42
Views
4 Years
Discussion Span
Last Post by techyworld
0
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}
0

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

Edited by pritaeas: Added markdown

0

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!

Edited by pritaeas: Added markdown

0

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

Edited by radhakrishna.p: giving clarity on the requirement

0

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.

0

@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

0

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.

0

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?

0

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?

0

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?

0

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);
        }});
    }
0

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.

1

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

Thanks mate .appreciate your help :)

Edited by techyworld

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.