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
https://forums.phpfreaks.com/topic/73076-solved-a-little-php-help-probally-simple/
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

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]");
?>

im so confused right now lol

 

im probally wrong but i dont think i have a define

 

what in the message.php its just a simple link the sends them to pmessage.php?$view[id] on the pmessage page it just tells it to grab data from the database with the id of $view[id] which is in the address

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>";

}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.