Recursive function including mysql does not work in php [duplicate]
This question already has an answer here:
Why doesn't this PHP recursive function return the value?
4 answers
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) ;
}
}
}
php mysql
marked as duplicate by deceze♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 5:34
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Why doesn't this PHP recursive function return the value?
4 answers
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) ;
}
}
}
php mysql
marked as duplicate by deceze♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 5:34
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
if (...) { return ... } else { NO RETURN HERE }…
– deceze♦
Nov 13 '18 at 5:34
add a comment |
This question already has an answer here:
Why doesn't this PHP recursive function return the value?
4 answers
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) ;
}
}
}
php mysql
This question already has an answer here:
Why doesn't this PHP recursive function return the value?
4 answers
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) ;
}
}
}
This question already has an answer here:
Why doesn't this PHP recursive function return the value?
4 answers
php mysql
php mysql
edited Nov 13 '18 at 5:31
suresh bambhaniya
863113
863113
asked Nov 13 '18 at 4:48
sky
116
116
marked as duplicate by deceze♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 5:34
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by deceze♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 5:34
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
if (...) { return ... } else { NO RETURN HERE }…
– deceze♦
Nov 13 '18 at 5:34
add a comment |
if (...) { return ... } else { NO RETURN HERE }…
– deceze♦
Nov 13 '18 at 5:34
if (...) { return ... } else { NO RETURN HERE }…– deceze♦
Nov 13 '18 at 5:34
if (...) { return ... } else { NO RETURN HERE }…– deceze♦
Nov 13 '18 at 5:34
add a comment |
1 Answer
1
active
oldest
votes
Each time your function calls itself, it needs to be able to pass the return value up the call stack. you miss return
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 {
return stockToDate($base_date, $i) ;
}
}
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Each time your function calls itself, it needs to be able to pass the return value up the call stack. you miss return
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 {
return stockToDate($base_date, $i) ;
}
}
}
add a comment |
Each time your function calls itself, it needs to be able to pass the return value up the call stack. you miss return
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 {
return stockToDate($base_date, $i) ;
}
}
}
add a comment |
Each time your function calls itself, it needs to be able to pass the return value up the call stack. you miss return
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 {
return stockToDate($base_date, $i) ;
}
}
}
Each time your function calls itself, it needs to be able to pass the return value up the call stack. you miss return
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 {
return stockToDate($base_date, $i) ;
}
}
}
answered Nov 13 '18 at 4:53
suresh bambhaniya
863113
863113
add a comment |
add a comment |
if (...) { return ... } else { NO RETURN HERE }…– deceze♦
Nov 13 '18 at 5:34