Jump to content

[SOLVED] A Little Php Help (Probally Simple )


smithygotlost

Recommended Posts

Ok i been working on a big online rpg project for the past year now :S i made everything so it worked but didnt look professional ! so now its clean up time i have a private msg feature where people can msg each other the problem is if i for example try and pull msg 12 like so

$reply = mysql_query("SELECT * FROM mail WHERE id=$id");

if (!$read) {
print "<center><table cellpadding=0 cellspacing=0 width=600>";
print "<tr><td width=20% class=mail-title>From</td><td width=20% class=mail-title>Subject</td></tr>";
$msel = mysql_query("select * from mail where owner=$stat[id] order by id desc limit 15");
while ($mail = mysql_fetch_array($msel)) {
	print "<tr><td class=mail valign=bottom>";
if ($mail[unread] == T) {

print "<b>";
}

print "$mail[sender]</b></td><td class=mail valign=bottom>";
if ($mail[unread] == T) {
print "<b>";
}
mysql_query("update mail set unread='F' where owner=$stat[id]");
print "[<a href=\"pmessage.php?view=$mail[id]\">$mail[subject]</a>]</b></td>";
}

 

that takes it to pmessage.php like so

 

 

if($view) {

$msel = mysql_query("select * from mail where id=$view[id]");
while ($msg = mysql_fetch_array($msel)) {

print"

		<table border=1 cellpadding=0 cellspacing=8 style=border-collapse: collapse width=100% bgcolor=#333333>
		  <tr>
			<td width=100% style=padding:3px;>          

<table border=0>
    <tr>
    <td valign=top> 		</td>
    <td width=613 valign=top>
	<table border=1 cellspacing=0 cellpadding=5 width=610>
  			<tr>

    			<td bgcolor=#353535><font size=+1 color=5098D7>$msg[subject]
    				</font></td>
  			</tr>
		 <tr>
   			   <td width=100% height=34 style=background-color:#666666 cellpadding=5>
        <table cellpadding=0 cellspacing=0 border=0>

    					<tr>
   					    <td>From : </td>
   					    <td>$msg[sender]</td>
    					</tr>
   				  </table>    				</td>
  			</tr>
		<tr>

			<td height=128 bgcolor=545454>$msg[body]</td>
		</tr>
	</table>
</td>
  </tr>
</table>



[<a href=\"message.php?view=write&id=$mail[id]\">Reply</a>] [<a 
href=message.php?message=$mail[id]&step=delete>Delete</a>]</td></table>";

}
}

 

but rather than pulling msg 12 it pulls message 1 ??? it wont pull the full id for some reason is it something stupid i missed ?

 

- the db connection is in the header of each page

 

any hints of things i have missed would be helpful

 

thanks

mike

 

Link to comment
Share on other sites

when u go through the message page it takes all the msg's from the database ! the next page then uses the view id from the previous page so

 

message.php << does the query

message.php << [<a href=\"pmessage.php?view=$mail[id]\">$mail[subject]</a>]

pmessage.php <<

 

if($view) {
$msel = mysql_query("select * from mail where id=$view[id]");
while ($msg = mysql_fetch_array($msel)) {

 

grabs the data from the database where the id of the mail is the $view[id] as the top says ?view=$mail[id]

 

so if mail id = 23 the the query should grab the message with id 23 but grabs the message with id 2 lol

Link to comment
Share on other sites

Sorry, my question should be where you are getting the value for the $view

variable.

 

You should on you pmessage.php page have something like the following to grab the view value from the querystring pmessage.php?view=23.

<?php
$view = $_GET['view']; //23
?>

 

I think why you are just getting only the first value is this:-

 

<?php
$view = "23"; //Your view string value

echo $view['id']; //2
//You are trying to get the value as an associative array but $view is a string.
//$view['id'] is interpreted as $view[0] so just returns the first character.  
?>

So to fix your problem either have:-

 

<?php
$view = $_GET['view'];
$msel = mysql_query("select * from mail where id=$view");
?>

or

<?php
$view['id'] = $_GET['view'];
$msel = mysql_query("select * from mail where id=$view[id]");
?>

Link to comment
Share on other sites

Have you actual tried the piece of code i wrote before? Anyway, here's the full code you can try.

 

<?php

$view = $_GET['view'];


if($view) {

$msel = mysql_query("select * from mail where id=$view");  //$view NOT $view['id']
while ($msg = mysql_fetch_array($msel)) {

print"

		<table border=1 cellpadding=0 cellspacing=8 style=border-collapse: collapse width=100% bgcolor=#333333>
		  <tr>
			<td width=100% style=padding:3px;>          

<table border=0>
    <tr>
    <td valign=top> 		</td>
    <td width=613 valign=top>
	<table border=1 cellspacing=0 cellpadding=5 width=610>
  			<tr>

    			<td bgcolor=#353535><font size=+1 color=5098D7>{$msg['subject']}
    				</font></td>
  			</tr>
		 <tr>
   			   <td width=100% height=34 style=background-color:#666666 cellpadding=5>
        <table cellpadding=0 cellspacing=0 border=0>

    					<tr>
   					    <td>From : </td>
   					    <td>{$msg['sender']}</td>
    					</tr>
   				  </table>    				</td>
  			</tr>
		<tr>

			<td height=128 bgcolor=545454>{$msg['body']}</td>
		</tr>
	</table>
</td>
  </tr>
</table>



[<a href=\"message.php?view=write&id={$mail['id']}\">Reply</a>] [<a 
href=message.php?message={$mail['id']}&step=delete>Delete</a>]</td></table>";

}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.