etsted Posted May 12, 2014 Share Posted May 12, 2014 I cant see anything wrong here, but when i try to echo the $id variable i get nothing, i have tried with some of the other variable but i get nothing. I also have a custom $error variable that is supposed to tell me if i dont have anything i the DB, and it keeps saying that i dont. // if the user is not logged in, header them away if($user_status != true) { //header("location: index.php"); } $error = $sentMsg = $status_replies =""; // select all of a users messages from the DB //$sql = "SELECT id, to, from, date_sent, message, subject FROM conversation WHERE `from`='$log_username' AND deleted='0' "; $sql = "SELECT * FROM conversation"; $query = mysqli_query($con, $sql) or die(mysqli_error($con)); // check to see if he has more than 1 message $numrows = mysqli_fetch_array($query); if($numrows > 0) { $error = "You have no messages in your inbox<br>"; } else { while ( $row=mysqli_fetch_array($query) ) { $id = $row['id']; $to = $row['to']; $from = $row['from']; $date_sent = $row['date_sent']; $message = $row['message']; $subject = $row['subject']; $sentMsg = " <form action='' method='post' name='msgForm_".$id."'> <input type='checkbox' name='box_".$id."'> </form> "; } echo $id; } Link to comment Share on other sites More sharing options...
justsomeguy Posted May 12, 2014 Share Posted May 12, 2014 mysqli_fetch_array does not return the number of rows, it returns the next record or false if there is not another record. Look at the manual for it for examples. Your if statement is also backwards. You are saying they have no messages if the number of rows is greater than 0. That's backwards. Link to comment Share on other sites More sharing options...
funbinod Posted May 13, 2014 Share Posted May 13, 2014 (edited) @justsomeguy refers to $numrows = mysqli_fetch_array($query); if($numrows > 0) change this to $numrows = mysqli_num_rows($query); if($numrows <= 0) //or use just '=' coz there couldn't be, perhaps, negative number of messege Edited May 13, 2014 by funbinod Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now