One way would be to get the number of records (i.e. number of menu items) before running the loop.
Then, run the loop.
On each iteration, if a counter has not reached a certain value (based on the number of records), add the pipe.
A possible implementation would be:
$query = mysql_query("SELECT * FROM menu_items");
$items = mysql_num_rows($query);
$i = 1;
echo "<p>";
while ($row = mysql_fetch_assoc($query) {
echo $row['item_name'];
if ($i < $num) {
echo " |\n";
$i++;
}
}
echo "</p>\n";