简体   繁体   English

php include和mysqli准备

[英]php include and mysqli prepare

Im trying to figure this out but code isnt working inside of a function on my custom functions page. 我试图弄清楚这一点,但我的自定义函数页面上的代码无法在函数内部运行。 even if it does run the values arent returned to my reports to add to my $html for later echoing. 即使它确实运行返回到我的报表的值arent,也要添加到我的$ html中以供以后回显。 ideas???? 想法????

Thanks!! 谢谢!!

//**************** page reports.php***********//

include 'db_connect.php';
include 'functions.php';
include 'custom_functions.php';

sec_session_start();
if(login_check($mysqli) == true) {

if($sub_val ==='Jobs In This Week'){ // if week report jobs

            $table = 'jobs';
            $op = 'in';
            $start ='';
            $end = '';

            mkwk();
            sql_prepare($table,$op,$start,$end,$mysqli);


    } // end if jobs report week
        elseif($sub_val ==='Jobs In This Month'){ // if month report jobs
            // functoin to make current month

            mkmth();
            sql_prepare($table,$op,$start,$end);

    } // end if jobs report month

$html = 'add html here to build source';
echo html;

// ******** custom_functions.php ******//


function sql_prepare($table,$op,$start,$end,$mysqli,$stmt){

    global $job_id,$vin,$yr,$mk,$mdl,$color,$miles_in,$miles_out,$quoted,$price,$phone,$customer,$bal,$tax,$msg,$in,$out;
    if($table==='jobs'){
            $stmt = $mysqli->prepare("SELECT * FROM jobs WHERE ? between ? and ? ");
            $stmt->bind_param('sss', $oper,$startday,$endday);

            $oper = $op;
            $startday = $start;
            $endday = $end;

            $stmt->execute();
            $stmt->store_result();

            $stmt->bind_result($job_id,$vin,$yr,$mk,$mdl,$color,$miles_in,$miles_out,$quoted,$price,$phone,$customer,$bal,$tax,$msg,$in,$out);
            return $job_id;
            return $vin;
            return $yr;
            return $mk;
            return $mdl;
            return $color;
            echo 'sql prepare worked';
    }

    if($table==='expenses'){
            $stmt = $mysqli->prepare("SELECT * FROM expenses WHERE ? between ? and ? ");
            $stmt->bind_param('sss', $oper,$startday,$endday);

            $oper = $op;
            $startday = $start;
            $endday = $end;

    }

    return $stmt;
}


// function to make current week,  
function mkwk(){    

    // define global variable so that they be available outside the function
            global $month;
            global $year;
            global $day;
            global $dayl;
            global $sday;
            global $eday;
            global $start;
            global $end;

    // do the actual work
            $month = date("m");
            $year = date("Y");
            $day = date("d");
            $dayl = date("l");

            if($dayl==='Monday'){
             $sday = $day;
             $eday = $day+6;    
            }elseif($dayl==='Tuesday'){
                $sday = $day-1;
                $eday = $day+5;
            }elseif($dayl==='Wednesday'){
                $sday = $day-2;
                $eday = $day+4;
            }elseif($dayl==='Thursday'){
                $sday = $day-3;
                $eday = $day+3;
            }elseif($dayl==='Friday'){
                $sday = $day-4;
                $eday = $day+2;
            }elseif($dayl==='Saturday'){
                $sday = $day-5;
                $eday = $day+1;
            }elseif($dayl==='Sunday'){
                $sday = $day-6;
                $eday = $day;
            }

            $start = $year.'-'.$month.'-'.$sday;
            $end = $year.'-'.$month.'-'.$eday;

    // return the values to the global world
            return $month;
            return $year;
            return $day;
            return $dayl;
            return $sday;
            return $eday;
            return $start;
            return $end;


}

// end function to make current week

// functoin to make current month
function mkmth(){
    // define global variable so that they be available outside the function
            global $month;
            global $year;
            global $day;
            global $start;
            global $end;

    // do the work
            $month = date("m");
            $year = date("Y");
            $day = date("d");

            $start = $year.'-'.$month.'-01';
            $end = $year.'-'.$month.'-31';

    // return the values to the global world
            return $month;
            return $year;
            return $day;
            return $start;
            return $end;
}
// end function for current month

so I figured it out for anyone who doesnt know how to do this either. 所以我想出来的人谁也不知道如何做到这一点。

the function was working but simply i was not figuring the return values. 该功能正在工作,但我只是没有弄清楚返回值。 basicly i needed to set 基本上我需要设置

return $html;

this would send back the html i wanted to be returned and on the other page i would want to either set a value to equal the return or echo the return like so. 这将发送回我想返回的html,而在另一页上,我想将一个值设置为等于return或像这样回显return。

$html = sql_prepare(...insert values sent here,$html);

or 要么

 echo sql_prepare(...insert values sent here,$html);

this did the work. 这完成了工作。 thanks for replies 感谢您的答复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM