Click to See Complete Forum and Search --> : Fairly difficult question


R.Noon
09-26-2005, 10:36 AM
Alright, I'm having some more problems with this announcements page;

I have a database set up, basically the only table in it I'm dealing with here is my `post` table.

The problem I'm reaching is that despite all of this code that LOOKS like it should work, it isn't.

It's viewing announcements when I ask it to; as it should well do, but it's not viewing announcements from the correct subject.

For instance -- My table has three posts in it, one for each subject.
When I choose a subject; and hit "view" it goes to the page; like it's working, but it views the wrong announcement, and it views the same announcement twice.

Upon closer inspection of my database, I find that the announcement it is viewing is the first on the list.

TIA of course :)

~Ryan




<?php
include('header.php');
$sql= "SELECT * FROM `post`";
$results=mysql_query($sql);
$row=@mysql_fetch_array($results)
?>
<?php
if (!isset($_POST['subj']))
{?>
<form method="post">
<dl align="center">~!~ Subject Of Announcement ~!~
<dd>Web Design<input type="radio" name="subj" value="Web Design"></dd>
<dd>Tech Support<input type="radio" name="subj" value="Tech Support"></dd>
<dd>Site Updates<input type="radio" name="subj" value="Site Updates"></dd>
<dd>All<input type="radio" name="subj" value="All"></dd>
</dl>
<input type="submit" value="View">
</form>
<?php }
if (isset($_POST['subj']))
{ $viewSub = $_POST['subj'];
if ($viewSub != "All")
{
$query = "SELECT * FROM `post` WHERE `$viewSub` = '{$row['subject']}'";
$result2 = mysql_query($query);
while($row2 = mysql_fetch_array($result2)){$posted = $row2[0]; }
}
else $posted = $row['post'];
}
//---------------------//
if (isset($viewSub))
{
if($username!=NULL){ ?><br><div align="left"><b><a href="addannouncement.php">Add An Announcement</a></b></div><br><? }?>
<table border="3">
<tr>
<?php if($username!=NULL){ ?><td align="center"><b>Options</b></td> <?php }?>
<td align="center"><b>Date</b></td>
<td align="center"><b>Anoucement</b></td>
<td align="center"><b>Posted By</b></td>
</tr>
<?php while($row=mysql_fetch_array($results))
{?>
<tr>
<?php if($username!=NULL){ ?><td><?php include('adminedit.php'); ?></td> <?php }?>
<td><?php echo date("d/m/y", $row{'date'}); ?></td>
<td valign="top"><?php echo $posted ?></td>
<td align="center" valign="middle"><?php echo $row{'username'}; ?></td>
</tr>
<?php
}
?>
</table>
<?php } ?>
<?php include('footer.php'); ?>

R.Noon
09-26-2005, 10:40 AM
An Edit --
When viewing any subject, besides all, it gives me the following error on both posts --

Notice: Undefined variable: posted in C:\inetpub\spragueweb\students05\noon_ryan\PHP\veiw_anouce.php on line 46

It gives me this error at the top of those pages --
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\inetpub\spragueweb\students05\noon_ryan\PHP\veiw_anouce.php on line 26

NogDog
09-26-2005, 11:02 AM
The "supplied argument is not a valid MySQL result resource" error message almost always means your query failed -- either a database connection error or a SQL syntax error. Check return values from all mysql_connect and mysql_query calls to verify whether or not they succeeded. If they returned FALSE, then output mysql_error() so you can maybe get a hint as to what went wrong, such as:

$results=mysql_query($sql) or die("SQL error: " . mysql_error());

theuedimaster
09-26-2005, 01:19 PM
Maybe the "where" definitions of the row and column intersection you want isn't clear enough. Or maybe make this slight change:


$query = "SELECT * FROM post WHERE sub = '".$row['subject']."';";

You can't have $viewsub there. YOu need to put the name of the column, not a variable thingy. Replace "sub" with the name of your column.

**EDIT**

nvm, i see what you're doing. Do this instead.

$query = "SELECT * FROM post WHERE ".$viewsub." = '".$row['subject']."';";