Page 1 of 1

String concatenation and query string from link

Posted: Fri Nov 21, 2008 8:06 am
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.

Re: String concatenation and query string from link

Posted: Fri Nov 21, 2008 8:14 am
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. :)

Re: String concatenation and query string from link

Posted: Fri Nov 21, 2008 8:43 am
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>" ;