Forum Moderators: coopster
I am fairly new to php. After struggling for a while with Dreamweaver MX I managed to get my link to filter the MySQL column that I wanted. However, only when I type in the URL variable myself (example: products?category=Bathroom%20Decorating) am I able pass on the filter. When I click the category link on my preview page, which is supposed to carry the URL variable, Dreamweaver generates a long php string with all kinds of characters %203$_row.Products%20$_HTTP_GET..............etc... and therefore does not recognize the url variable I am assuming.
The links are the categories and the categories should link to each product contained within each category.
I have 2 tables.
Category Table
Products Table
each included the column " category" which is the url variable that I am attempting to filter.
I apologize for the lengthy post but in a nutshell:
When typing in the browser the url variable myself, the products list is properly filtered. When clicking the link from a category, which should carry the category url variable and filter the corresponding category, Dreamweaver a very long url with all sorts of characters.
My url variable from the categories is:
<a href="myproducts.php<?php> echo $HTTP_GET_VARS......<php>">.
Any help would be greatly appreciated. I used to work with ASP which was built in with Dreamweaver and was not expecting to struggle that much with php and MySQL.
Thank you.
JayDev
and closes like this:
?>
So your url should look something like this:
<a href="myproducts.php?<?php echo $HTTP_GET_VARS.....?>">
It's entirely possible that you also have additional problems with how your variables are defined -- i.e., exactly what are you echoing there, and are you sure it's correct? But the php syntax definitely needs to be fixed.
All I am trying to do is pass the variable in my URL so that it filters the variable (category type in my case).
Could this do the trick for it:
echo "<a href='mypage.php?myfiltervariable=$categoryID'>Category Link Here</a>";
Thank you.
In this case, I have a category column in my MySQL table, which is named "cat" which is the filter for the receiving page (myproducts.php)
echo "<a href='myproducts.php?myvariable=$cat'>Category Name</a>";
Is this the way to do it? If there is something wrong with what I am doing, please let me know. Thank you.
Pardon me if this is a basic question but: how do you define a variable?
Basic questions are fine!
As for defining variables, in PHP you do so simply by assigning a value to it. There is no need to declare a variable and set its type before assigning a value as in some languages. Simply
$x = 0;
is enough.
As for your example, typically the 'cat' column is going to be an array index in your result set. So in other words,
$sql = "SELECT cat from table1";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
echo "<a href='myproducts.php?myvariable=$row['cat']>Category Name</a>";
}
Tom