Jump to content

Proper concatenaton in href for querystring


cofey12681

Recommended Posts

Hello, what I'm trying to do is make a very basic shopping cart that interacts with mysql. Right now I have some code that will spit out a column, category in an echo statement with <li>. What I need though is to properly concatenate this for a query string...

 

What I mean is, the user clicks the link, they get brought to the respective page that selects all records for that particular passed in category.

 

This is what I have, and I have not been able to figure it out, sometimes I see nothing with no eror, but many times I'll get parse erros referring to ".

 

echo " "<li> . "<a href=" . $row["category"] . " . ">" something here..., maybe $row['category"] again...  . "</a>" . "</li>" . "; 

 

Can someone please educate me on the right way to do this.... thanks.And then once that's done, How would I read the category on page load? I am used to .net but not php.

Well it will boil down to personal preference with using single or double quotes. But I prefer the single quote method. This should  be properly formatted.

 

echo '<li><a href="' . $row["category"] . '">something here..., maybe '.$row['category"].' again...</a></li>";

The error you are receiving seems to occur because of the way you are performing the concatenation.

 

echo "<li> . "<a href=" . $row["category"] . "> something here..., maybe $row['category"] again...   </a></li>"; 

 

You only need to do the concatenation when you are trying to insert bits of php. So

</a>"."</li>

is complete unnecessary.

 

However, like IchBin said, it's easier to to separate which quotes you use. Keep single quotes to php and double quotes to html.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.