I tried to get some data from my function but I couldn't, Can any one help me

I have some data in functions file, from this page into my index page

public function selectData($table, $where = null, $wheree = null, $where1 = null, $wheree1 = null) {

    $QUERY = mysql_query("SELECT * FROM " . $table . " WHERE '" . $where . "' = '" . $wheree . "' && '" . $where1 . "' = '" . $wheree1 . "'");
    $Fetch_Assoc = mysql_fetch_assoc($QUERY);
    $Num_Rows = mysql_num_rows($QUERY);
    $Fetch_Array = mysql_fetch_array($QUERY);
    $Fetch_Object = mysql_fetch_object($QUERY);

but when I want extract data from my database using mysql_fetch_assoc in index file, it doesn't work, you'll find what I want to do in the data below

<?php include 'files/header.php';

$getData = $user->selectData('newpost');


echo $Fetch_Assoc['P_id'];

can any one help me plzz

I presume $user is the object instatntiated from the class that contains the selectData method. I am guessing that this class stores the results (array, object...) into some properties. Now, you should use correct operators to address those properties, such as:

echo $user->aarrayResultProperty['P_id'];

And also:


I do not think you can access the $QUERY variable from outside the method.

I tried it but nothing happens :(

I hope you din not just copy the code above since it is just a guess (and also contains a typo) - it won't work. Please post the code for the class and how you instantiate it.

no, there is no why, I found the solution, thank you so much :)

Member Avatar

no, there is no why, I found the solution, thank you so much :)

I hope it wasn't using deprecated mysql_* functions as in your original example.

Please mark the thread as solved if no more questions. And yes, do not use deprecated mysql_* functions in production. Happy coding.