...

View Full Version : short function problem



M.W.S.
02-21-2008, 04:20 PM
Hello
I made a simple function for further use :

function _q($q){
mysql_query($q) or die (mysql_error());
return $q;
}

BUT, it's not working with mysql_num_rows() and such functions. also I can't assign a variable to it. If I do such code:


$q = _q("SELECT * FROM table");
mysql_num_rows($q);


It gives an error or mysql_num_rows

So... What to do? :confused:

oesxyl
02-21-2008, 04:30 PM
Hello
I made a simple function for further use :

function _q($q){
mysql_query($q) or die (mysql_error());
return $q;
}

BUT, it's not working with mysql_num_rows() and such functions. also I can't assign a variable to it. If I do such code:


$q = _q("SELECT * FROM table");
mysql_num_rows($q);


It gives an error or mysql_num_rows

So... What to do? :confused:

sorry, but what's the utility of such function?
if the query die, what happend with return?
also why to pack all this when is more simple and flexible to call each of this where you need.
Maybe if I understand what do you want to achive I could help.

PS: I don't remember details, but names with underscore have a special meaning in php. I must check this

best regards

_Aerospace_Eng_
02-21-2008, 04:33 PM
It should be something like this, the underscore in the beginning of the function name says its supposed to be a private function.

function q($q){
$result = mysql_query($q) or die (mysql_error());
return $result;
}
You also need to pass it the mysql_connect variable.

M.W.S.
02-21-2008, 05:09 PM
Thanks, it's working now ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum