Could you anybody help me why the recursive function does not work? If the first parameter is match the function returns proper value. If not, the return value is null.
function stockToDate($base_date, $i) {
include "../lib/dbconn.php" ;
$today = date("Y-m-d") ;
$base_date = date("Y-m-d", strtotime($base_date . "-1day")) ;
$q = " SELECT txn_date "
. " FROM tworking_ymd "
. " WHERE txn_date = '$base_date' " ;
$r = mysqli_query($dbc, $q) ;
if(mysqli_num_rows($r) == 1){
$row = mysqli_fetch_row($r);
return $row[0] ;
} else {
$i = $i + 1 ;
if($i > 10) {
return $today ;
} else {
stockToDate($base_date, $i) ;
}
}
}