I know there are a few bits of infomation about prepared statement, but none specific to my needs. I quite new to PHP and MySQLI so when I started to build my site I was not really aware of the prepared statement. So I'm updating these as I go into each page for updates.
I have the below statement snippet of code originally, and below this is the code I changed to but it's not returning any results.
$sqlCommand = "SELECT users.id, scout_profile.s_name_first,scout_profile.s_name_mid, scout_profile.s_name_last, scout_profile.nationality, scout_profile.s_country, scout_profile.s_club_main, scout_profile.s_type, scout_profile.status, scout_profile.gender, users.signup, users.avatar, users.username FROM scout_profile INNER JOIN users ON scout_profile.scout_id=users.id";
include_once("../php_includes/db_conx.php");
$query = mysqli_query($db_conx,$sqlCommand) or die(mysqli_error($sqlCommand));
$count = mysqli_num_rows($query);
if($count >= 1){
$i = 0; // for ads
$adCode=""; // for ads
while($row = mysqli_fetch_array($query,MYSQLI_NUM)){
// Insert Adds and selected interval - Begin (also look for (for ads))
$i++;
if($i==2 || $i==4 ||$i ==6){
$adCode = '<div class="card-body bg-warning m-2 p-1 add_text" style="height: 100px;">This is Ad Space from Ads server Im on ('.$i.')</div>';
}else{
$adCode="";
}
$sid = $row[0];
$s_name_first = $row[1];
$s_name_mid = $row[2];
$s_name_last = $row[3];
-- Updated (but not working)
//$fn_searchquery = $_POST['fn_searchquery'] ?? '';
$sqlCommand = "SELECT users.id, scout_profile.s_name_first,scout_profile.s_name_mid, scout_profile.s_name_last, scout_profile.nationality, scout_profile.s_country, scout_profile.s_club_main, scout_profile.s_type, scout_profile.status, scout_profile.gender, users.signup, users.avatar, users.username FROM scout_profile INNER JOIN users ON scout_profile.scout_id=users.id";
include_once("../php_includes/db_conx.php");
$statement = $db_conx->prepare($sqlCommand);
$statement->execute();
//$result = $statement->get_result()->fetch_all(MYSQLI_ASSOC);
$result = $statement->get_result();
$statement -> store_result();
$count = $statement->num_rows;
if($count >= 1){
$i = 0; // for ads
$adCode=""; // for ads
while($row = $result->fetch_row()){
// Insert Adds and selected interval - Begin (also look for (for ads))
$i++;
if($i==2 || $i==4 ||$i ==6){
$adCode = '<div class="card-body bg-warning m-2 p-1 add_text" style="height: 100px;">This is Ad Space from Ads server Im on ('.$i.')</div>';
}else{
$adCode="";
}
$sid = $row[0];
$s_name_first = $row[1];
$s_name_mid = $row[2];
$s_name_last = $row[3];
This code is return no data, if I have to I can change to an associated row but would link to keep the way it as it is less code to the change. I think it is something to do with the fetch function but I'm not sure the best way to debug it.