Announcement

Collapse
No announcement yet.

PDF Report - returning NULL in sub-selection (pls help me)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PDF Report - returning NULL in sub-selection (pls help me)

    Hello to all,

    I'm trying to make a subselect in a report pdf but the result is "Null"

    Can anyone tell me where did I go wrong?

    here is the code:

    Code:
    $curent_id = {id};
    //sub_db = ex
    function fetch_ex()  
    {
     
    $output = '';
    $con = mysqli_connect("*****************","*****************","*****************","*****************") or die("Some error occurred during connection " . mysqli_error($con)); 
    // Write query
     
    $strSQL = "SELECT 
       _mr.id,
       _ex.id_mr,
       _ex.pos,
       _ex.com,
       _ex.date_f,
       _ex.date_t,
       _ex.exp
    FROM
       _mr INNER  JOIN _ex ON _ex.id_mr = _mr.id
       WHERE _ex.id_mr = '".$curent_id."'";
     
    var_dump($strSQL);
    // Execute the query.
     
    $query = mysqli_query($con, $strSQL);
     
    if ($query->num_rows > 0) 
    {
    while($row = mysqli_fetch_array($query))
    {
       $output .= '<tr>
         <td style="width:20%; text-align: left;">'.date("M.Y -", strtotime($row["date_f"])).'<br>'.date("M.Y", strtotime($row["date_t"])).'</td>
    </tr>';
    }
    return $output;
     
    }
    }
     
    var_dump($query);
    $exp = fetch_exp();
     
    //Close the connection
    mysqli_close($con);
    This select returns at var_dump($query);

    NULL string(312) "SELECT _mr.id, _ex.id_mr, _ex.pos, _ex.com, _ex.date_f, _ex.date_t, _ex.exp FROM _mr INNER JOIN _ex ON _ex.id_mr = _mr.id WHERE _ex.id_mr = ''"

    Observations:
    1) If I use instead of this parameter $curent_id a number (from the id list) everything works great;
    2) if I make this parameter $curent_id = with a number I have the same error >> NULL string(312) "SELECT _mr.id, _ex.id_mr, _ex.pos, _ex.com, _ex.date_f, _ex.date_t, _ex.exp FROM _mr INNER JOIN _ex ON _ex.id_mr = _mr.id WHERE _ex.id_mr = ''" <<

    Does have anyone any ideas?

    Thank you for your help,
    Dan
    Thanks for your time & have a nice day,
    Dan

    //覧覧覧覧覧覧覧
    Scriptcase Version 8.00.0030
    Types pe_mysql_bronze

  • #2
    Hello all,

    so I figured my self.

    the problem was that I wanted to use an external variable inside of my function "fetch"

    The correct variant of the code is the following:

    $curent_id = {id};
    //sub_db = ex
    function fetch_ex($x_var)
    {

    $output = '';
    $con = mysqli_connect("*****************","************** ***","*****************","*****************") or die("Some error occurred during connection " . mysqli_error($con));
    // Write query

    $strSQL = "SELECT
    _mr.id,
    _ex.id_mr,
    _ex.pos,
    _ex.com,
    _ex.date_f,
    _ex.date_t,
    _ex.exp
    FROM
    _mr INNER JOIN _ex ON _ex.id_mr = _mr.id
    WHERE _ex.id_mr = ".$x_var;

    var_dump($strSQL);
    // Execute the query.

    $query = mysqli_query($con, $strSQL);

    if ($query->num_rows > 0)
    {
    while($row = mysqli_fetch_array($query))
    {
    $output .= '<tr>
    <td style="width:20%; text-align: left;">'.date("M.Y -", strtotime($row["date_f"])).'<br>'.date("M.Y", strtotime($row["date_t"])).'</td>
    </tr>';
    }
    return $output;

    }
    }

    var_dump($query);
    $exp = fetch_exp($current_id);

    //Close the connection
    mysqli_close($con);
    What's in red was changed in order to make the function to work.

    Hope this will help someone.

    Regards,
    Dan
    Thanks for your time & have a nice day,
    Dan

    //覧覧覧覧覧覧覧
    Scriptcase Version 8.00.0030
    Types pe_mysql_bronze

    Comment

    Working...
    X