
November 20th, 2003, 05:14 PM
|
|
|
|
Join Date: Apr 2007
Posts: 101
Time spent in forums: < 1 sec
Reputation Power: 2
|
|
|
sorting by column heads
I have been studying Matt Wade's tutorial about how to sort on column heads (thanks!) and am working on how to add a column with an edit link in it to edit a particular row in the results. I have come up with the line:
php Code:
Original
- php Code |
|
|
|
echo "<TD><a href="$MM_keepNone. (($MM_keepNone!= "")? "&": ""). "id=". $row_users['id']">edit</a></TD>";
which adds the column and the edit link, but I can't get the syntax worked out to send the row id so I edit the correct record. Can anybody tell me where I am going wrong? The entire code is below.
Thanks.
--Rayne
php Code:
Original
- php Code |
|
|
|
<?PHP /* set the allowed order by columns */ $default_sort = 'username'; $allowed_order = array ('id', 'lname', 'fname', 'username', 'status', 'email'); /* if order is not set, or it is not in the allowed * list, then set it to a default value. Otherwise, * set it to what was passed in. */ if (! isset ($_GET['order']) || ! in_array ($_GET['order'], $allowed_order)) { $order = $default_sort; } else { $order = $_GET['order']; } /* connect to db */ //mysql_connect ('localhost','user','pass'); //mysql_select_db ('test'); /* construct and run our query */ $query = "SELECT * FROM log_in ORDER BY $order"; /* make sure data was retrieved */ if ($numrows == 0) { echo "No data to display!"; } /* now grab the first row and start the table */ echo "<TABLE border=1>n"; foreach ($row as $heading=>$column) { /* check if the heading is in our allowed_order * array. If it is, hyperlink it so that we can * order by this column */ echo "<TD><b><font size=-1>"; if (in_array ($heading, $allowed_order)) { echo "<a href="{$_SERVER['PHP_SELF']}?order= $heading">$heading</a>"; } else { } } /* reset the $result set back to the first row and * display the data */ foreach ($row as $column) { echo "<TD><font size=-1>$column</TD>n"; } echo "<TD><a href="$MM_keepNone. (($MM_keepNone!= "")? "&": ""). "id=". $row_users['id']">edit</a></TD>"; } ?>
|