Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 27th, 2006, 6:16 PM   #11
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Post your entire NEW code.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 28th, 2006, 3:37 AM   #12
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
<html>
<?php
if ($_POST ['view']) $view = $_POST ['view']; else $view = 'fullname';
require_once ("table.php");
mysql_connect('localhost','guest','password');
$view = $ifdate;
if ($view='date') {
$query = ("SELECT * FROM test.messages  ORDER BY $view DESC");
} else {
$query = ("SELECT * FROM test.messages  ORDER BY $view ASC");
}
$result = mysql_query ($query) or die (mysql_error () . "query op<br/>");
?>
<body>
<table border="1">
<tr>
<td>
<img src="tri">
</td>
<td>
<h1> message reader <h1>
</td>
</tr>
<tr>
<td>
</td>
<td>
<form action="table.php" name="form" method="post">
<select name="view">
<option value="fullname">fullname a-z
<option value="emailaddress"> email a-z
<option value="date">date newest-oldest
</select>
<input type="submit" name="submit">
</form>
</td>
</tr>
<tr>
<td valign="top">

</td>
<td>
<?php
echo '<TABLE border="1">'; 
echo '<TR><TD><B>Full Name</B></td><TD><B>Email Address</B></td><TD><B>Date and time</B></td><TD><B>Message</td></B></TR>';
while($myrow = mysql_fetch_array($result)) 
{ 
echo '<TR><TD>'; 
echo $myrow['fullname']; 
echo "<TD>"; 
echo $myrow['emailaddress'];  
echo "<TD>"; 
echo $myrow['date']; 
echo "<TD>"; 
echo $myrow['message']; 
} 
echo '</TABLE>';
?>
</td>
</tr>
</table>
</body>
</html>
__________________
this forum rules you guys are great!
thanks to all who help
piercy
piercy is offline   Reply With Quote
Old Apr 28th, 2006, 6:03 AM   #13
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Without going through your code in detail, lets just talk about the top part: This assigns to $view the name of the field to be sorted; either what's posted or a default, 'fullname':

if ($_POST ['view']) $view = $_POST ['view']; else $view = 'fullname';

Then you immediately destoy the result by assigning the contents of $ifdate, whatever that is, as it's not shown in this code:

$view = $ifdate;

Then you immediately destroy it again by assigning the string 'date' to it and testing the result of the assignment. Perhaps you meant to use "==" for comparison purposes:

if ($view='date') {

Iffen ya see whut I mean.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 28th, 2006, 6:17 AM   #14
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
sorry that $view = $ifdate was just a test i did i forgot to remove it. im not sure what you mean about "==". i wanted hte if statment to basically say.

$view is equal to $_post["view"]
order by ascending
but if $_post["view"] was equal to date
order by descending

if that make sense.
__________________
this forum rules you guys are great!
thanks to all who help
piercy
piercy is offline   Reply With Quote
Old Apr 28th, 2006, 6:23 AM   #15
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
ahhh i just put the "==" in and now i see what you mean. it works perfectly

thank you very much.
__________________
this forum rules you guys are great!
thanks to all who help
piercy
piercy is offline   Reply With Quote
Old Apr 28th, 2006, 6:29 AM   #16
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Your requirements make sense, your code won't fulfill them. You need to read about operators. "=" makes an assignment. "==" makes a comparison. The statement, "if ($view = 'date')" first assigns the value, 'date', to the variable, $view, then tests to see if the result of the assignment is true or false (it will obviously always be true, because 'date' is not a zero-valued thangy). The statement, "if ($view == 'date')" compares the value store in $view with the value 'date' and tests the result of the comparison. Neither of the two members is modified (in this case), but the conditional execution of the following code is one of the foundations of computer operation.

Secondly, the $ifdate assignment, even if its presence was a mistake, highlights the need for including snippets of code or similar informative material with your questions, right? My very first post indicated you were lacking in that respect. Two additional posts had to be added JUST to get something to look at.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC