Exactly what the title says with working demonstration please.

I know the code but I am unable to get it working.

function q($a) {
 return mysql_query($a);
}

function a($b) {
 return mysql_fetch_assoc($b);
}

$abc="select * from table";
$bcd = q($abc);
$cde = a($bcd);

echo $cde[$column];

Thanks, Regards X
PS: sorry about the messy code just doing it off the top of my head

Hey...
I tried this ,its working fine...

I think you have mistaken at last line ,means you have write the column name with out $.

function q($a) {
      return mysql_query($a);
      }
      function a($b) {
      return mysql_fetch_assoc($b);
      }
      $abc="select * from user";
      $bcd = q($abc);
      $cde = a($bcd);
      echo $cde['uname'];

Check out this...

Thanks
Shanti.

Ok there has to be a problem with my configuration or setup of php/mysql.

I get this error once again which I have recieved 100 times doing the same thing on different code (that is using function to access mysql_* commands).

"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\www\test.php on line 11"

11.  return mysql_fetch_assoc($b);

Can anyone tell me why this is? or more importantly tell me how to fix my configuration of mysql/php so it works?

Thanks, Regards X

Check for your database username,password,name are correct or not..
And also check your table once again...
And use mysql_fetch_array(); instead of mysql_fetch_assoc();..

If all the above are correct then,
simply re-install your mysql..

Check for your database username,password,name are correct or not.. - CORRECT
And also check your table once again... - CHECKED
And use mysql_fetch_array(); instead of mysql_fetch_assoc();.. - SAME ERROR
If all the above are correct then, simply re-install your mysql.. - DONE

Any other ideas? :(

Can anyone tell me why this is? or more importantly tell me how to fix my configuration of mysql/php so it works?

Dude, I have told you many times already to assign the mysql_query result to a variable and return it. :confused:

function q($a) {
      $x = mysql_query($a);
      return $x;
 }

could you tel me any other retrieves are done with your database....?

nav :P

I told you I tried it like that and I still got the same error (remember i was just copying the book I have for argument sake?).

Anyways I did your change and still the same error :|.

Even when I used your code from the older thread nav, still got the same error the one you tested, remember?

Shanti, my test.php does nothing but what the code you saw (if that answers your question - abit confused).

Anyways :(

I tried again this way and it works. Do you have mysql_connect and mysql_select_db queries ?

<?php
$con = mysql_connect("localhost","root");
mysql_select_db("test");
function query($a) {
      $x = mysql_query($a);
      return $x;
}
function res($b) {
      $y = mysql_fetch_assoc($b);
      return $y;
}
$query="select * from users";
$res = query($query);
$columns = res($res);
echo $columns['UD_FIRSTNAME'];
?>

Yes I do, same error came up when i used your code :(

maybe try to put the $con variable with the query so it will denote which connection the query corresponds to.

ex.

function q($sql) {
  $query = mysql_query($sql,$con);
  return $query;
}

Just a slight modification to Kkeith29's example. $con has to be either global, or, function q should have another parameter ie., $con (or $con will be empty). function q($sql,$con) or global $con; .

Just a slight modification to Kkeith29's example. $con has to be either global, or, function q should have another parameter ie., $con (or $con will be empty). function q($sql,$con) or global $con; .

really, i thought if it was outside of the function it was global.

http://in2.php.net/global The scope of a variable in a function is local for that function.

guess i am wrong. sadly i am starting to forget things after I started to use OOP class stuff.

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.