![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#12 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
<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 |
|
|
|
|
|
#13 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#14 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#15 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#16 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|