Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post

    short function problem

    Hello
    I made a simple function for further use :
    PHP Code:
    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:
    PHP Code:
    $q _q("SELECT * FROM table");
    mysql_num_rows($q); 
    It gives an error or mysql_num_rows

    So... What to do?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by M.W.S. View Post
    Hello
    I made a simple function for further use :
    PHP Code:
    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:
    PHP Code:
    $q _q("SELECT * FROM table");
    mysql_num_rows($q); 
    It gives an error or mysql_num_rows

    So... What to do?
    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

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    It should be something like this, the underscore in the beginning of the function name says its supposed to be a private function.
    PHP Code:
    function q($q){
    $result mysql_query($q) or die (mysql_error());
    return 
    $result;

    You also need to pass it the mysql_connect variable.
    Last edited by _Aerospace_Eng_; 02-21-2008 at 05:38 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post
    Thanks, it's working now


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •