String concatenation and query string from link

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

Post Reply
cofey12681
Forum Newbie
Posts: 1
Joined: Fri Nov 21, 2008 7:58 am

String concatenation and query string from link

Post by cofey12681 »

Hello,

I am building a online store with PHP and MYSQL. I have a navigation bar that in PHP, spits out categories in a link and my goal is, when a user clicks the link, that the correct items will be displayed on the target page.

I'm having trouble with proper concatenation though.

I don't have my code with me, but what I'm basically entering is... echo " "<li>" . "<a href=" . $row["category"] . " ">" . "</a>" . "</li>" " ;

I'm not sure what I'm doing wrong, I've been playing with this forever, I've had funny things happen where I don't even close off the href tag and it still appears as a link. Can someone tell me the proper way to code this?

Also, I want this category to get passed into a query string, so when the user clicks the link for cat X, all items in X will appear. I'm used to using.net where on page load I can call the Sqldatasource and write teh select statement. How is this achieved in php...

Thank you.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: String concatenation and query string from link

Post by papa »

Code: Select all

 
echo "<li><a href=\"mypage.php?cat_id=".$row["cat_id"]."\">".$row["category"]."</a></li>\n";
 
Not much point unless you provide us with your code though. :)
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: String concatenation and query string from link

Post by Mark Baker »

Don't forget, with echo you don't need to concatenat, but can pass a series of arguments

Code: Select all

echo "<li>" , "<a href=" , $row["category"] ,  ">" , "</a>" , "</li>" ;
Post Reply