PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
the9ulaire
Forum Commoner
Posts: 74 Joined: Mon Jun 11, 2007 11:31 am
Post
by the9ulaire » Sun Aug 05, 2007 8:44 pm
I'd like to make a navigation where it displays:
Code: Select all
while ($row = mysql_fetch_array($result)) {
echo "<a href=\"index.php?p=" . $row['page_id'] . "\" title=\"" . $row['page_desc'];
echo "\">";
echo $row['page_name'];
echo "</a>";
echo " | ";
}
Except on the last one it leaves out the final echo, thus all links have a line between them and there isn't one hanging off the end.
Thank you for your time! I greatly appreciate it!
Luke
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Aug 05, 2007 8:55 pm
I would put the pipe at the beginning, then simply detect the fist iteration.
the9ulaire
Forum Commoner
Posts: 74 Joined: Mon Jun 11, 2007 11:31 am
Post
by the9ulaire » Sun Aug 05, 2007 9:02 pm
What do you mean by 'pipe'? Sorry, I'm still quite new to all of this.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Aug 05, 2007 9:04 pm
"|" is called a pipe (character.)
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Aug 05, 2007 9:20 pm
If the result set is small, I would just stick the results into an array and make use of implode()
Code: Select all
$result = array();
while ($row = mysql_fetch_array($result)) {
$result[] = "<a href=\"index.php?p=" . $row['page_id'] . "\" title=\"" . $row['page_desc'] ."\">". $row['page_name'] ."</a>";
}
echo implode('|', $result);
the9ulaire
Forum Commoner
Posts: 74 Joined: Mon Jun 11, 2007 11:31 am
Post
by the9ulaire » Sun Aug 05, 2007 10:52 pm
feyd wrote: "|" is called a pipe (character.)
Oh, of course! I knew that. Goodness, I certainly make things more complicated than they really are.
Jcart wrote: If the result set is small, I would just stick the results into an array and make use of implode()
Code: Select all
$result = array();
while ($row = mysql_fetch_array($result)) {
$result[] = "<a href="index.php?p=" . $row['page_id'] . "" title="" . $row['page_desc'] ."">". $row['page_name'] ."</a>";
}
echo implode('|', $result);
Thank you! I tried that and it works perfectly; thanks!
aileenguan
Forum Newbie
Posts: 3 Joined: Sun Aug 05, 2007 10:52 pm
Location: P.R.C.
Post
by aileenguan » Mon Aug 06, 2007 12:20 am
Jcart wrote: If the result set is small, I would just stick the results into an array and make use of implode()
Code: Select all
$result = array();
while ($row = mysql_fetch_array($result)) {
$result[] = "<a href="index.php?p=" . $row['page_id'] . "" title="" . $row['page_desc'] ."">". $row['page_name'] ."</a>";
}
echo implode('|', $result);
Yes!