how could i do this??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

how could i do this??

Post by ericburnard »

Hi again.

i have a email system which uses a db. when a new email is sent (enterd into the database) the feild "new" defults as 1. Now in my inbox i have it so that it displays the number 1 from the db next to the email. I would like to know to things.
How can i make it so that if when the email is read it changes the 1 to a 0.
Can instead of the number 1 or 0 now beig displayed in the inbox a checkbox be ticked or an image displayed for each number so the user can tell if they have read the email or not.

Hope this makes sence :s

Thanks
Eric
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

changing a field involves: UPDATE

as for showing a checkbox or image, use an if to tell you which to actually display...
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post by ericburnard »

i no the if function is really really simple but i cnt get it to work. i have a loop with echos in to display the latest mail but i cant seem to get it to work with the if function in:S what am i doing wrong?

Code: Select all

<? 
include('http://eric.madashatters.com/header.inc'); 
?> 

<?php 
// Connecting, selecting database 
mysql_connect('localhost', '*******', '*****') 
or die('Could not connect: ' . mysql_error()); 
mysql_select_db('madashat_mail') or die('Could not select database'); 


echo "<BR>"; 
$offset = $_GET['offset'];
if($offset == "") $offset = 0;
$max = $offset + 10;
$username = mysql_real_escape_string($_GET['user']); 
$query = "SELECT * FROM pm WHERE user='$username' order by id desc"; 
$result = mysql_query($query) or die(mysql_error()); 
$rows = mysql_numrows($result);
if($max > $rows) $max = $rows;



echo "<center><u><b>Inbox</u></b><br><BR><a href='http://eric.madashatters.com/sendmail.php?user=".$username."'>New Email Message</a> | <a href='http://eric.madashatters.com/sentmail.php?userm=".$username."'>Sent</a><br><table align='middle' cellpadding='5' style='border: dotted 1px'>
<tr> 
<td><div class='white'>New</td> 
<td><div class='white'>Date</td> 
<td><div class='white'>Subject</td> 
<td><div class='white'>Sender</td> 
<td><div class='white'>Delete</td>"; 

for($i=$offset;$i<$max;$i++){

$subject = mysql_result($result,$i,"subject"); 
$new = mysql_result($result,$i,"new"); 
$message = mysql_result($result,$i,"message"); 
$date = mysql_result($result,$i,"date"); 
$sender = mysql_result($result,$i,"sender"); 
$id = mysql_result($result,$i,"id"); 

echo "<tr style='border: dotted 1px'>"; 
echo "<td><div class='white'>";

if ($new = 1)
   echo 'New';

echo "</td>"; 
echo "<td><div class='white'>$date</td>"; 
echo "<td><div class='white'><a href='http://eric.madashatters.com/readmail.php?user=".$user."&mail=".$id."'>$subject</a></td>"; 
echo "<td><div class='white'>$sender</td>"; 
echo "<td></td>"; 
echo "</tr>"; 

}
?> 
</table> <BR><BR>
<? 
include('http://eric.madashatters.com/footer.inc'); 
?>
i guessed i would have to put it in an echo function but that dosnt seen to want to work either.

Any ideas??

Thanks again
Eric
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post by theda »

You don't echo mysql functions...
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post by ericburnard »

theda wrote:You don't echo mysql functions...
so what would i do with the if function then to get it to work?? because at the moment its saying that all messages are new

Eric
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post by theda »

I was just saying you dont echo mysql functions.

Oh, I'm curious what does "<you><b>Inbox</you>" <- what do the you tags do? Edit: Oh yeah, dumb filter changes the underline tag <_<
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post by ericburnard »

theda wrote:I was just saying you dont echo mysql functions.

Oh, I'm curious what does "<you><b>Inbox</you>" <- what do the you tags do? Edit: Oh yeah, dumb filter changes the underline tag <_<
thats good then lol cos i cudnt remember putting them in :D
i still cant seem to get it to work. any pointers at all ??

eric
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

$rows = mysql_numrows($result);
should be mysql_num_rows

PHP should throw a syntax error about that, unless you turned down error reporting which is NOT recommended during development
Post Reply