Functions and different files

Discussion in 'PHP' started by crazyryan, Feb 28, 2008.

  1. #1
    Hey

    Having a little problem..

    I have say, page.php with this code:
    get_coupon_info($_GET['cid']);
    PHP:
    page.php also includes functions.php, one of the functions is get_coupon_info:
    function get_coupon_info($id) {
        $query = mysql_query("SELECT * FROM coupons, categories WHERE coupons.coupon_category=categories.category_id AND coupon_id = '" . mysql_real_escape_string($id) . "'") or die(mysql_error());
        $row = mysql_fetch_array($query);
    }
    PHP:
    Now, as you can see, I'm trying to pull all the stuff within functions.php to keep page.php tidy, however. When I use something like $row['field'] in page.php, it's empty.

    Is that because what I'm trying to do is not possible and if so what other solution is there? Or is it because I have a slight error somewhere, all help appreciated.
     
    crazyryan, Feb 28, 2008 IP
  2. quicksolutions

    quicksolutions Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    a simple solution is :
    function get_coupon_info($id) {
    $query = mysql_query("SELECT * FROM coupons, categories WHERE
    coupons.coupon_category=categories.category_id AND coupon_id = '" . mysql_real_escape_string($id) . "'") or die(mysql_error());
    $row = mysql_fetch_array($query);
    return $row; /// newly added code
    }

    Page.php


    $row = get_coupon_info($_GET['cid']); /// get the result in page.php code
     
    quicksolutions, Feb 28, 2008 IP
  3. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #3
    Thanks, worked perfectly.
     
    crazyryan, Feb 28, 2008 IP