I have these lines of code:
$user = $_SESSION['name'];
$con = mysqli_connect("localhost","root","","db_shop");
$sql = mysqli_query($con,"SELECT * FROM tbl_cart WHERE `user` = '$user' AND `done` = '0'");
while( $result = mysqli_fetch_assoc( $sql ) ){
$file = $result['items'];
$res = explode(",",$file);
$total = 0;
$tmp = count( $res );
for( $i = 0 ; $i <= $tmp; $i++ ){
$sql = "SELECT * FROM `tbl_details` WHERE `file_name` = '".$res[$i]."'";
echo $sql;
$sql = mysqli_query( $con, "SELECT * FROM `tbl_details` WHERE `file_name` = '".$res[$i]."'");
while( $res = mysqli_fetch_assoc( $sql ) ){
$total += $res['price'];
}
echo "<script>alert('$total');</script>";
}
}
where $res[1] must contain a value of 1000 from my database, but it just gives me a null value.
As you can see I tried to echo out $sql, $res[0] returned the right one but $res[1] returned:
SELECT * FROM `tbl_details` WHERE `file_name` = ''
Any help would be appreciated thanks.
echo $sql;outputs?tbl_detailsWHEREfile_name= '1.jpg'SELECT * FROMtbl_detailsWHEREfile_name= ''SELECT * FROMtbl_detailsWHEREfile_name= '' this is the outputprint_r($res);immediately after$res = explode(",",$file);what would you get in the array? Does this contain all the values you would expect?