View Full Version : Help! I cant remember how to code :(
gurhy 08-16-2006, 08:04 PM Can some 1 tell me what I am doing wrong? as this dont seem to be working way its ment to.
in one of my other projects simular version worked, although can not use the other as the compaibilty between the 2 scripts. any help be most greatful.
<?
require("inc/header.inc.php");
$Result = mysql_query("select id, sender, subject, date, status, NickName from Messages where NickName='$NickName'");
if($sender['sender'])
echo"
<table border=0 cellspacing=1 cellpadding=2 width=95% bgcolor=AAAAAA align=center>
<tr>
<td bgcolor=E0E0E0> </td>
<td bgcolor=E0E0E0>From:-</td>
<td bgcolor=E0E0E0>Subject:-</td>
<td bgcolor=E0E0E0>Date:-</td>
</tr>";
while($row = mysql_fetch_array($Result)){
$id=$row["id"];
$sender= $row["sender"];
$date=$row["date"];
$subject=$row["subject"];
echo"<tr bgcolor=#FFFFCC>
<td width=34> <div align=center>$status</div></td>
<td width=346><b><a href=read.php?id=$id>$sender</a></b></td>
<td width=314><b><a href=read.php?id=$id>$subject</a></b></div></td>
<td width=250><div align=left>".(date("d M Y / H:i"))."</div></td>"; }
echo"</table>";
} else { echo "<center><B>No messages found.</B></center><P></P>";}
include('inc/footer.inc.php');
?>
Lebanon 08-16-2006, 09:02 PM and do you have any errors posted back ?
Do you have $nickname defined ?
Whats 'not' happening ? or what is u want to happen ?
shortyzgotpop 08-16-2006, 09:55 PM Yeah we can't really help you if we don't know what error you're getting
is it a MySQL error?
gurhy 08-17-2006, 07:50 AM well the problem I am getting is that I want this to say that there is no messages when there are none as you can see from the code of what I am trying to do..
As soon as an entry is made into the database for username $NickName it shows the information ok, but when there is no info in the database it shows no information, when its ment to show the page as ,,, No Messages Found..
No errors posted back and what you meen $nickname defined? thats the hole page i have posted above.
lutan 08-17-2006, 08:12 AM Check your curly bracket pairs, seems not match.
BurakUeda 08-17-2006, 08:23 AM Check your curly bracket pairs, seems not match.
Yeah seems like it:
if($sender['sender'])
{ //// <-- this bracket is missing ?
gurhy 08-17-2006, 08:37 AM I do apoligise, I missed out that bracket wen I posted this forum, that bracket is there, was only thing I had missed out, but I still have the problem
lutan 08-17-2006, 08:45 AM You can view the source from your browser to see whether what part of code has been executed by the server, then you can locate where the problem is.
gurhy 08-17-2006, 09:18 AM I checked it and it dont seem to be printing the $sender which is a vital part to make it work, im still workin on fixing it but wiv no luck
maiahost 08-17-2006, 09:29 AM if (mysql_num_rows($Result)==0) {echo '<center><B>No messages found.</B></center><P></P>';}
That should do the trick.
also it is :
if($sender['sender'])
change to
if($row['sender'])
and the output will not work :
<a href=read.php?id=$id>$sender</a>
will give you a wrong link the right way to do it is :
<a href=read.php?id='.$id.'>'.$sender.'</a>
as well as the other rows
gurhy 08-17-2006, 09:36 AM Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/dating/public_html/other/Dating/view.php on line 25
No messages found.
maiahost 08-17-2006, 09:43 AM let me see if I can write this in a clearer way :
<?
require("inc/header.inc.php");
$Result = mysql_query("select * from Messages where NickName='$NickName'");
$num_rows = mysql_num_rows($Result);
if ($num_rows==0)
{echo '<center><B>No messages found.</B></center><P></P>';}
else {
echo '<table border=0 cellspacing=1 cellpadding=2 width=95% bgcolor=AAAAAA align=center>
<tr>
<td bgcolor=E0E0E0> </td>
<td bgcolor=E0E0E0>From:-</td>
<td bgcolor=E0E0E0>Subject:-</td>
<td bgcolor=E0E0E0>Date:-</td>
</tr>';
while($row = mysql_fetch_array($Result))
{
$date=$row["date"];
echo'<tr bgcolor=#FFFFCC>
<td width=34> <div align=center>$status</div></td>
<td width=346><b><a href=read.php?id='.$row["id"].'>'.$row["sender"].'</a></b></td>
<td width=314><b><a href=read.php?id='.$row["id"].'>'.$row["subject"].'</a></b></div></td>
<td width=250><div align=left>'.(date("d M Y / H:i")).'</div></td></table>';
}
}
include('inc/footer.inc.php');
?>
maiahost 08-17-2006, 09:47 AM Do you access this file with filename.php?NickName=nickname
gurhy 08-17-2006, 10:01 AM no, im useing _session thats passing the NickName..
Thank you for the script that made things lot clear to me and now it works :)
maiahost 08-17-2006, 10:05 AM Sure no problem, that's what wht is all about. I really hope this works cause I did it in a hurry.
gurhy 08-17-2006, 10:20 AM yea this works perfectly, differnt to how my other codes work but this actualy looks more professional to what I have done :)
I have another question,
How do I make it that one line shows as grey and the other pale blue? if you know what I meen
maiahost 08-17-2006, 10:29 AM :) well not exactly - do you want your results displayed in different colors (i.e. one blue row one gray row etc.)
gurhy 08-17-2006, 10:34 AM yup exactly what I meen
maiahost 08-17-2006, 10:41 AM well personally I do it like that add this :
$i=1;
at the beginning of the code (right after <?php)
and modify this line :
echo'<tr bgcolor=#FFFFCC>
to this :
if ($i%2===0) {echo '<tr bgcolor=#gray>';}
else {echo '<tr bgcolor=#blue>';}
$i++;
echo '
remember to change the color codes the way you want them
gurhy 08-17-2006, 10:52 AM that changes the colors ok :) but,
it broken the table up, the first row is ok but then the next 2 rows are showing up in place of the footer
maiahost 08-17-2006, 10:56 AM Sorry I am not looking at the html at all :) here you go paste after the while :
while($row = mysql_fetch_array($Result))
{
$date=$row["date"];
if ($i%2===0) {echo '<tr bgcolor=#gray>';}
else {echo '<tr bgcolor=#blue>';}
$i++;
echo '<td width=34> <div align=center>$status</div></td>
<td width=346><b><a href=read.php?id='.$row["id"].'>'.$row["sender"].'</a></b></td>
<td width=314><b><a href=read.php?id='.$row["id"].'>'.$row["subject"].'</a></b></div></td>
<td width=250><div align=left>'.(date("d M Y / H:i")).'</div></td></tr>';
}
echo '</table>';
}
include('inc/footer.inc.php');
?>
gurhy 08-17-2006, 11:05 AM Thank You :) I am becomeing so proud of this work that you sorted out for me :)
all perfect now :D
If I find anything else I need help with, is it ok to email you useing the private message or just add to this forum?
maiahost 08-17-2006, 11:12 AM Well let's not spam the board - just PM me and if I have the time I'll certainly be happy to help. Good luck.
gurhy 08-30-2006, 04:57 PM ermm dont meen to sound dumb but what do you meen?
maiahost 09-01-2006, 01:47 AM send me a private message :)
|