Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old November 20th, 2003, 05:14 PM
rayne rayne is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 101 rayne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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
  1.  
  2. 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
  1.  
  2. <?PHP
  3. /* set the allowed order by columns */
  4. $default_sort = 'username';
  5. $allowed_order = array ('id', 'lname','fname', 'username', 'status', 'email');
  6.  
  7. /* if order is not set, or it is not in the allowed
  8. * list, then set it to a default value. Otherwise,
  9. * set it to what was passed in. */
  10. if (!isset ($_GET['order']) ||
  11.     !in_array ($_GET['order'], $allowed_order)) {
  12.     $order = $default_sort;
  13. } else {
  14.     $order = $_GET['order'];
  15. }
  16.  
  17. /* connect to db */
  18. //mysql_connect ('localhost','user','pass');
  19. //mysql_select_db ('test');
  20.  
  21. /* construct and run our query */
  22. $query = "SELECT * FROM log_in ORDER BY $order";
  23. $result = mysql_query ($query);
  24.  
  25. /* make sure data was retrieved */
  26. $numrows = mysql_num_rows($result);
  27. if ($numrows == 0) {
  28.     echo "No data to display!";
  29.     exit;
  30. }
  31.  
  32. /* now grab the first row and start the table */
  33. $row = mysql_fetch_assoc ($result);
  34. echo "<TABLE border=1>n";
  35. echo "<TR>n";
  36. foreach ($row as $heading=>$column) {
  37.     /* check if the heading is in our allowed_order
  38.      * array. If it is, hyperlink it so that we can
  39.      * order by this column */
  40.     echo "<TD><b><font size=-1>";
  41.     if (in_array ($heading, $allowed_order)) {
  42.         echo "<a href="{$_SERVER['PHP_SELF']}?order=$heading">$heading</a>";
  43.     }
  44.     else {
  45.         echo $heading;
  46.     }               
  47.     echo "</b></TD>n";
  48.     }
  49.     echo   "<TD>edit</TD>";
  50.     echo "</TR>n";
  51.  
  52. /* reset the $result set back to the first row and
  53. * display the data */
  54. mysql_data_seek ($result, 0);
  55. while ($row = mysql_fetch_assoc ($result)) {
  56.     echo "<TR>n";
  57.     foreach ($row as $column) {
  58.         echo "<TD><font size=-1>$column</TD>n";
  59.     }
  60.     echo "<TD><a href="$MM_keepNone.(($MM_keepNone!="")?"&":"")."id=".$row_users['id']">edit</a></TD>";
  61.     echo "</TR>n";
  62. }
  63. echo "</TABLE>n";
  64. ?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > sorting by column heads


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway