www.webdeveloper.com
Results 1 to 3 of 3

Thread: what's wrong with this function (with mysql)?

  1. #1
    Join Date
    Aug 2006
    Posts
    152

    Question what's wrong with this function (with mysql)?

    Hi everyone, have a look at this custom function

    PHP Code:
    function countcat($ccount){
    $conn=mysql_connect($server,$dbuser,$dbpass);
    $q="select * from linkslinks where catno='$ccount'";
    $r=mysql_db_query($dbname,$q,$conn);
    while(
    $row=mysql_fetch_array($r)) {
    print 
    "List: " $row[title];
    }

    when I call for example (countcat(5)) it only prints "List: ", I tried (countcat('5')) also doesn't work.. the connection and query is correct cause when I write it like that

    PHP Code:
    $conn=mysql_connect($server,$dbuser,$dbpass);
    $q="select * from linkslinks where catno='$ccount'";
    $r=mysql_db_query($dbname,$q,$conn);

    while(
    $row=mysql_fetch_array($r)) {
    print 
    "List: " $row[title];

    it works fine.. wut am I missing? TY..

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    The variables $server, $dbuser, $dbpass do not exist in the function's scope. You either need to declare them as global, or else pass them in to the function as arguments (or explicitly declare them inside the function, but that's not helpful when you have lots of functions). A tip is to always develop with error_reporting set to the highest level (E_ALL | E_STRICT), it would have caught this error for you and saved you lots of time.

  3. #3
    Join Date
    Aug 2006
    Posts
    152
    thank you.. i declared them in the function n it worked

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles