php - IF statement within WHILE not working
Get the solution ↓↓↓Solution:
if(strlen($results[message]) < 30){
the message probably should be quoted:
if(strlen($results['message']) < 30){
There are quite a few other similar issues
Answer
Solution:
i tested your code an the only mistake i found was the lack of quoatation marks in the indices array $results. You are using this$result[message_id]
when the most appropriate would be$result['message_id']
. The rest works as expected, the records with msgread equal to 0 stayed with the green line.
Answer
Solution:
Your code looks a little nasty and is not easy to read.
- You should use
mysqli_fetch_assoc()
. - Always end style with a ;
- use quotation on associative array
- more logic choice of var names
- where does
$userid
come from? is the content safe?
Here is quickly cleaned version of your code :
$query = "SELECT * FROM messages WHERE toperson = '" . $userid . "'";
if($results = mysqli_query($query)) {
if(mysqli_num_rows($results) != 0) {
$table = "<table><tr><th>From</th><th>Subject</th><th>Message</th></tr>";
while($data = mysqli_fetch_assoc($results)) {
if(strlen($data['message']) > 30){
$data['message'] = substr($data['message'], 0 ,30) . "...";
}
$table .= "<tr";
if($data['msgread'] == 0){
$table .= " style='background:#9CFFB6;'";
}
$table .= ">";
$table .= "<td>" . $data['from'] . "</td><td>" . $data['subject'] . "</td><td><a href='viewmessage.php?id=" . $data['message_id'] ."'>" . $data['message'] . "</a></td></tr>";
}
echo $table ."</table>";
} else {
echo "No Messages Found";
}
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: use the option --with-all-dependencies (-w) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.