New Messages Problem [Resolved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

New Messages Problem [Resolved]

Post by Epiales »

Okay guys... I'm almost done with the conversion from mysql to mysqli. Just a few more pages to do and then I can move on to actually working on the game again.

I ran into a problem with the new messages not working properly after I rewrote the code to myslqi. Everything worked before the change, but since, it won't show the image that I have when there is a new message. Not sure why, but here's the code:

Code: Select all

<?php
$i = 0;    

$messageinfo = "SELECT pid FROM messages where pid='$_SESSION[userid]' AND readm = '1'";
$user_query = mysqli_query($db_conx, $messageinfo);

    while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {    
    $i = $i + 1;

}

    if($i > 0) {echo "<a href='messages.php?messages=1'><img src = 'images/newmail2.png' width='43' title = " . $i . "New></a>";    
}
    else{echo "<a href='messages.php?messages=1'><img src = 'images/nomail.png' width='43'></a>";
}

?>
Thanks for any help.
Last edited by Epiales on Tue Oct 15, 2013 5:50 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
alexander19
Posts: 180
Joined: Fri Apr 02, 2010 1:05 pm

Re: New Messages Problem

Post by alexander19 »

I think there was a problem with the quotes for the image's title, change :

Code: Select all

  if($i > 0) {echo "<a href='messages.php?messages=1'><img src = 'images/newmail2.png' width='43' title = " . $i . "New></a>";    
}
to

Code: Select all

 if($i > 0) {echo "<a href='messages.php?messages=1'><img src = 'images/newmail2.png' width='43' title = '".$i."New' /></a>";  
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: New Messages Problem

Post by Epiales »

alexander19 wrote:I think there was a problem with the quotes for the image's title, change :

Code: Select all

  if($i > 0) {echo "<a href='messages.php?messages=1'><img src = 'images/newmail2.png' width='43' title = " . $i . "New></a>";    
}
to

Code: Select all

 if($i > 0) {echo "<a href='messages.php?messages=1'><img src = 'images/newmail2.png' width='43' title = '".$i."New' /></a>";  
No, that didn't work :( I've tried a billion things too lol! It shows the new message in red, in the actual mail area, but won't change images to show that there is a new message :( Thanks for helping!!
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: New Messages Problem

Post by Winawer »

The code looks about right, so the query probably isn't returning any rows. Is $_SESSION['userid'] set and is readm supposed to be 1?
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: New Messages Problem

Post by MikuzA »

your code definetly looks fine.
Try debuging the query, see it if echos the way you except it to be queried.






(Side note, a suggestion, you could do a mysqli_num_rows() there instead of the while.)

Code: Select all

    while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {    
    $i = $i + 1;
}
 
to

Code: Select all

$i = mysqli_num_rows($user_query);
 
Since you are not using the content of the query :-)
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: New Messages Problem

Post by Epiales »

MikuzA wrote:your code definetly looks fine.
Try debuging the query, see it if echos the way you except it to be queried.






(Side note, a suggestion, you could do a mysqli_num_rows() there instead of the while.)

Code: Select all

    while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {    
    $i = $i + 1;
}
to

Code: Select all

$i = mysqli_num_rows($user_query);
Since you are not using the content of the query :-)
I did as u suggested, but now it just shows that there's a new message always; even if there is no new message lol. YAY grrrr
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: New Messages Problem

Post by Epiales »

Winawer wrote:The code looks about right, so the query probably isn't returning any rows. Is $_SESSION['userid'] set and is readm supposed to be 1?
Yes, it's meant to be 1 if it is a new message, and it's 0 when it's read.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: New Messages Problem

Post by Epiales »

Winawer wrote:The code looks about right, so the query probably isn't returning any rows. Is $_SESSION['userid'] set and is readm supposed to be 1?
If I echo the messageinfo I get:

SELECT pid FROM messages where pid='1' AND readm = '1'

And the pid=1 is correct, as I'm the first user!!
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: New Messages Problem

Post by Epiales »

So here is my current code with that numrows change:

Code: Select all

<?php
$i = 0;    

$messageinfo = "SELECT pid FROM messages where pid='$_SESSION[userid]' AND readm = '1'";
$user_query = mysqli_query($db_conx, $messageinfo);

    $i = mysqli_num_rows($user_query);    
    $i = $i + 1;

 if($i > 0) {echo "<a href='messages.php?messages=1'><img src = 'images/newmail2.png' width='43' title = '".$i. " New' /></a>"; 
}
    else{echo "<a href='messages.php?messages=1'><img src = 'images/nomail.png' width='43'></a>";
}
?>
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: New Messages Problem

Post by Epiales »

Okay, I am going to go ahead and post the php that I have before the messages, as that might be in conflict of allowing the messages to work properly, although I have checked it a billion times and I don't see any errors. Here's the full code that goes at top of the page. Again, it only shows the "new message png" at all times. When it should show a different png when there is no message.

Code: Select all

<?php 
include_once("header.php");
include_once("includes/db_conx.php");
include("includes/functions.php");
include("includes/config.php");
include("includes/safe.php");
include("runcron.php");

?>
<div id="wrapper">    
<link href="css/style.css" rel="stylesheet" type="text/css" />

<!------------BEGINNING OF THE TOP LEFT ICONS------------>

<div id="userinfo" style="width:20%;height:797px;-webkit-border-radius: 0px 0px 0px 0px;-moz-border-radius: 0px 0px 0px 0px;border-radius: 65px 0px 0px 65px;border:2px solid #393F42;background:rgba(0,8,3,0.2);">

<?php
$profile_pic = '<center><img src="user/'.$users_username.'/'.$users_avatar.'" alt="'.$users_username.'" width="100" height="120">';
if($users_avatar == NULL){
    $profile_pic = '<img src="images/avatardefault.jpg" width="100" height="120">';
}
?>
<table width="200">
<td width="250">       <?php echo $profile_pic; ?></td><tr>
<td width="100"><center><big><?php echo $_SESSION['username']; ?></center></big>
<br>
<?php echo $stats_location; ?>
<br>
Level <?php echo $stats_level ?>
<br /><br />
<a href="dicegame.php?rolldice=100"><img src="images/one.png" width="40"/>

</table>

</div>

<div id="lefticons" style="width:12.6%;height:55px;-webkit-border-radius: 0px 0px 0px 0px;-moz-border-radius: 0px 0px 0px 0px;border-radius: 0px 0px 0px 0px;border:2px solid #393F42;background:rgba(0,8,3,0.2);">
<a href="user.php?u='.$log_username.'"><img src ="images/profile.png" width ="40" title="Profile"></a>
<a href='bank.php'><img src ="images/bank2.png" width ="50" title="Bank"></a>

<?php
$i = 0;    

$messageinfo = "SELECT pid FROM messages where pid='$_SESSION[userid]' AND readm = '1'";
$user_query = mysqli_query($db_conx, $messageinfo);

    $i = mysqli_num_rows($user_query);    
    $i = $i + 1;

 if($i > 0) {echo "<a href='messages.php?messages=1'><img src = 'images/newmail2.png' width='43' title = '".$i. " New' /></a>"; 
}
    else{echo "<a href='messages.php?messages=1'><img src = 'images/nomail.png' width='43'></a>";
}
?>
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”