Forum Moderators: coopster

Message Too Old, No Replies

Dreamweaver MX, php filtering and URL Variable

dreamweaver issue php url variable set up

         

JayDev

12:23 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



Hello,

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

sonjay

1:02 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



I would guess it's the <?php> and <php> tags that are the problem. PHP opens like this:
<?php

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.

JayDev

5:23 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



Thank you for your reply. I think the syntax is right. I just wrote it the wrong way as I am new to php. Sorry about this, won't do it again.

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.

ergophobe

7:45 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As long as $categoryID is defined, that should work for you.

And Welcome to WebmasterWorld

JayDev

10:18 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



Pardon me if this is a basic question but: how do you define a variable?

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.

ergophobe

3:22 am on Dec 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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