my links are not redirecting properly
<p>after running a search in my database the results show up in form of a link so that they redirect me to a particular page...for example when i search for a category business it shows that category but when i click on it it redirects me to the contents of another category..when i checked my url and i noticed its like </p>

<pre><code>http://mysite/forum%20part%20two/view_category.php?cid=1
</code></pre>

<p>instead of </p>

<pre><code>http://mysite/forum%20part%20two/view_category.php?cid=2
</code></pre>

<p>this my search code</p>

<pre><code> if(isset($_POST['search'])){ //form submitted, clicked Submit Search 
    $query = strip_tags(mysql_real_escape_string($_POST['query'])); //try to prevent sql injections
    if(!$query){ //not enterered a query 
        echo 'You must enter a search query!'; 
    }else{ 
        //EDIT THIS ---------------------------------- 
        $table = 'categories'; //the table you want to search 
        $row = 'category_title'; //the row in which you want to search 
        //EDIT THIS ---------------------------------- 
        $sql = mysql_query("SELECT * FROM `".$table."` WHERE `".$row."` LIKE '%".$query."%'"); //search query 
        if($sql){ //no errors 
            if(mysql_num_rows($sql) == 0){ //No results found. 
                echo 'No results were found for &lt;strong&gt;'.$query.'&lt;/strong&gt;'; 
            }else{ //one or more results have been found 
                echo 'We have found &lt;strong&gt;'.mysql_num_rows($sql).'&lt;/strong&gt; for &lt;strong&gt;'.$query.'&lt;/strong&gt;.&lt;br&gt;&lt;br&gt; 
                &lt;table&gt; 
                    &lt;tbody&gt; 
                        &lt;tr&gt; 

                            &lt;td&gt;&lt;strong&gt;category_title&lt;/strong&gt;&lt;/td&gt; 
                        &lt;/tr&gt;'; 
                while($r = mysql_fetch_array($sql)){ //get data of every user where their category_title is like the $query string 

                    $category_title = $r["category_title"]; 
                    //lets put the part they searched in bold. 
                    $category_title = str_ireplace($query, '&lt;strong&gt;'.$query.'&lt;/strong&gt;', $category_title); 
                    //lets put the part they searched in bold. 
                    echo '&lt;td&gt;'.$category_title."&lt;a href='view_category.php?cid=".$id."' class='cat_links'&gt;".$category_title." - &lt;font size='-1'&gt;".$description."&lt;/font&gt;&lt;/a&gt;&lt;/td&gt; 
                &lt;/tr&gt;'"; 
                } 
                echo '&lt;/tbody&gt;&lt;/table&gt;'; 
            } 
        }else{ 
            echo 'Sorry, an MySQL error occurred:&lt;br&gt;&lt;br&gt;'.mysql_error(); //an error occurred, so echo it 
        } 
    } 
}
</code></pre>

<p>my view_category.php code is this</p>

<pre><code>&lt;?php
// Connect to the database
include_once("connect.php");

// Function that will count how many replies each topic has
function topic_replies($cid, $tid) {
    $sql = "SELECT count(*) AS topic_replies FROM posts WHERE category_id='".$cid."' AND topic_id='".$tid."'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    return $row['topic_replies'] - 1;
}
// Function that will convert a user id into their username
function getusername($uid) {
    $sql = "SELECT username FROM users WHERE id='".$uid."' LIMIT 1";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    return $row['username'];
}
// Function that will convert the datetime string from the database into a user-friendly format
function convertdate($date) {
    $date = strtotime($date);
    return date("M j, Y g:ia", $date);
}

// Assign local variables
$cid = $_GET['cid'];

// Check to see if the person accessing this page is logged in
if (isset($_SESSION['username'])) {
    $logged = " | &lt;a href='create_topic.php?cid=".$cid."'&gt;Click Here To Create A Topic&lt;/a&gt;";
} else {
    $logged = " | Please log in to create topics in this forum.";
}
// Query that checks to see if the category specified in the $cid variable actually exists in the database
$sql = "SELECT id FROM categories WHERE id='".$cid."' LIMIT 1";
// Execute the SELECT query
$res = mysql_query($sql) or die(mysql_error());
// Check if the category exists
if (mysql_num_rows($res) == 1) {
    // Select the topics that are associated with this category id and order by the topic_reply_date
    $sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
    // Execute the SELECT query
    $res2 = mysql_query($sql2) or die(mysql_error());
    // Check to see if there are topics in the category
    if (mysql_num_rows($res2) &gt; 0) {
        // Appending table data to the $topics variable for output on the page
        $topics = "&lt;table width='100%' style='border-collapse: collapse;'&gt;";
        $topics .= "&lt;tr&gt;&lt;td colspan='4'&gt;&lt;a href='index.php'&gt;Return To Forum Index&lt;/a&gt;".$logged."&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;";
        $topics .= "&lt;tr style='background-color: #dddddd;'&gt;&lt;td&gt;Topic Title&lt;/td&gt;&lt;td width='65' align='center'&gt;Last User&lt;/td&gt;&lt;td width='65' align='center'&gt;Replies&lt;/td&gt;&lt;td width='65' align='center'&gt;Views&lt;/td&gt;&lt;/tr&gt;";
        $topic = "&lt;tr&gt;&lt;td colspan='4'&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;";
        // Fetching topic data from the database
        while ($row = mysql_fetch_assoc($res2)) {
            // Assign local variables from the database data
            $tid = $row['id'];
            $title = $row['topic_title'];
            $views = $row['topic_views'];
            $date = $row['topic_date'];
            $creator = $row['topic_creator'];
            // Check to see if the topic has every been replied to
            if ($row['topic_last_user'] == "") { $last_user = "N/A"; } else { $last_user = getusername($row['topic_last_user']); }
            // Append the actual topic data to the $topics variable
            $topics .= "&lt;tr&gt;&lt;td&gt;&lt;a href='view_topic.php?cid=".$cid."&amp;tid=".$tid."'&gt;".$title."&lt;/a&gt;&lt;br /&gt;&lt;span class='post_info'&gt;Posted by: ".getusername($creator)." on ".convertdate($date)."&lt;/span&gt;&lt;/td&gt;&lt;td align='center'&gt;".$last_user."&lt;/td&gt;&lt;td align='center'&gt;".topic_replies($cid, $tid)."&lt;/td&gt;&lt;td align='center'&gt;".$views."&lt;/td&gt;&lt;/tr&gt;";
            $topics .= "&lt;tr&gt;&lt;td colspan='4'&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;";
        }
        $topics .= "&lt;/table&gt;";
        // Displaying the $topics variable on the page
        echo $topics;
    } else {
        // If there are no topics
        echo "&lt;a href='index.php'&gt;Return To Forum Index&lt;/a&gt;&lt;hr /&gt;";
        echo "&lt;p&gt;There are no topics in this category yet.".$logged."&lt;/p&gt;";
    }
} else {
    // If the category does not exist
    echo "&lt;a href='index.php'&gt;Return To Forum Index&lt;/a&gt;&lt;hr /&gt;";
    echo "&lt;p&gt;You are trying to view a category that does not exist yet.";
}
?&gt;
</code></pre>

<p>sorry for pasting alot of code</p>
