marcus Posted December 29, 2006 Share Posted December 29, 2006 I am making a forum and I was wondering, the user selects say board ID #5 and want the post to go onto board #5, but he meant six, without changing the URL he could use a drop down to find the one he wants, but sort by id 1-12 but 5 being first.So the drop would be like:5- ONTOP1 23466789101112 Link to comment https://forums.phpfreaks.com/topic/32129-solved-sort-by-given-id/ Share on other sites More sharing options...
trq Posted December 29, 2006 Share Posted December 29, 2006 An example.[code]<?php $boards = range(1,12); $current = 5; echo "<select name='boards'>"; echo " <option value='$current' selected='selected'>$current</option>"; foreach ($boards as $board) { if ($board != $current) { echo " <option value='$board'>$board</option>"; } }?>[/code] Link to comment https://forums.phpfreaks.com/topic/32129-solved-sort-by-given-id/#findComment-149077 Share on other sites More sharing options...
marcus Posted December 29, 2006 Author Share Posted December 29, 2006 How would I use it in relationship to a SQL database? Link to comment https://forums.phpfreaks.com/topic/32129-solved-sort-by-given-id/#findComment-149078 Share on other sites More sharing options...
marcus Posted December 29, 2006 Author Share Posted December 29, 2006 Or, how could I do this. Have a drop down using a while statement and have it so that the ID given is the selected one? Link to comment https://forums.phpfreaks.com/topic/32129-solved-sort-by-given-id/#findComment-149090 Share on other sites More sharing options...
corbin Posted December 29, 2006 Share Posted December 29, 2006 [code=php:0]<?$link = mysql_connect();$db = mysql_select_db('dbname', $link);if(!$db) {die("Database error. Please try again later.");}$bid = $_GET['boardid']; //pulls the board ID via getif(!is_numeric($bid) || !isset($bid) || $bid == ""){$bid = 1;}$q1 = mysql_query("SELECT id FROM forum_sections WHERE id = '{$bid}'");if(@mysql_num_rows($q1) < 1) {//sets the board id to 1 if the board doesnt exist in the db$bid = 1;}$q = mysql_query("SELECT id,name FROM forum_sections WHERE SORT BY id ASC"); //pulls the ids and names from the DB and sorts them with IDs like 1 2 3 4 5..echo "<form action=\"\" method=\"get\">\r\n";echo "<input type=\"\" name=\"boardid\">\r\n";while($r = mysql_fetch_assoc($q)) {if($r['id'] == $bid) {$sel = " SELECTED"; //makes the chosen one selected...}echo "<option value=\"{$r['id']}\"{$sel}>{$r['name']</option>\r\n";$sel = NULL;}echo "</form>\r\n";?>[/code]That would pull topics from a database with a table called forum_sections. It would make the one that was the current board selected in a drop down list... It should work, but I might have a slight syntax error or something... Lol wrote it in this box... It's lightly commented, but if you don't understand a part just tell me... Link to comment https://forums.phpfreaks.com/topic/32129-solved-sort-by-given-id/#findComment-149106 Share on other sites More sharing options...
corbin Posted December 29, 2006 Share Posted December 29, 2006 On a side note, now that I think about it, I hate to be critical, but coding forums would be extremely hard and would take forever if you plan for them to have as many features as some of the forums out there... If you plan on making like every feature that other forums have, you might as well just use tweaked boards... If you don't plan for it to get crazy complex though, you have more control over it if you code it your self :p. Link to comment https://forums.phpfreaks.com/topic/32129-solved-sort-by-given-id/#findComment-149108 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.