Jump to content

[SOLVED] Sort By Given ID


marcus

Recommended Posts

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- ONTOP
1
2
3
4
6
6
7
8
9
10
11
12
Link to comment
Share on other sites

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
Share on other sites

[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 get
if(!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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.