If you're sure there will only be one record, you can make the code much simpler:
$stmt = $DB_con->prepare("SELECT DISTINCT department_name FROM filter WHERE university_name=:id");
$stmt->execute(array(':id' => $id));
if ($row=$stmt->fetch(PDO::FETCH_ASSOC)) // change to if to just get one row
<p><?php echo $row['department_name']; ?></p>
What you need to do after that, is change the code in the calling page so that it replaces the correct div. I don't know what names you are using in that - in my sample code in the post I linked to, I called it "subcats". So on this line in the calling code:
$("#subcat-list").html(result); // insert in div above
it would need to be
to replace the entire
select range, otherwise you'll be putting a
<p> inside a
<select> and I'm not sure how well that will work. It also only outputs it as a text display, it does not put it into a form field. If you need it to come into the next page with your other form fields, then you could probably output it as a hidden form field as well as the straight text - that's just html and duplicating the code above.
Obviously what you need to do after that is change the calling code so that it can work with both scenarios - one department, or more than one. So the pseudo-code for that would be something like
// run the query
// get the number of rows returned
// if it's only one :
// retrieve the one row and output it as a paragraph, or para and hidden input
// otherwise it must be more than one: **
// output the opening select tag
// loop through the results and output them as option tags
// output the closing select tag
** assuming that you couldn't have a university in the first drop-down that has no departments.
I'll leave you to code that, feel free to come back and post your code if you have trouble with it.