I have searched for this problem on google and all solutions I have tried dont work

I am new at PHP and used this method before but for some reason this one is giving me the run around.

it echo's the text "Special Occasions" but the link it refers to tries to load the view_gallery.php page as
www.myweb.com/view_gallery.php?cat=Special
when it should be:
www.myweb.com/view_gallery.php?cat=Special Occasions

What am I doing wrong here, i know its something stupid im doing.

<?php

$sqlr="SELECT * FROM categories ORDER BY id ASC"; 
$resultr=mysql_query($sqlr); 

while ($rowd=mysql_fetch_array($resultr)) { 
    $idr = $rowd['id']; 
    $category = $rowd['category'];

echo "

<td width=120 height=19 valign=top><center class=style3>
<p><a href=view_gallery.php?cat=" . $rowd['category'] . " style=color: #FFFFFF>$category</a></p>
</center></td>";
}

?>

Any suggestions ?

Try:

$category = urlencode($rowd['category']);

Since you are using the space in an URL, you should encode it. But, it works in your case too, if you hadn't forgotten to put quotes around the href (as is required by the HTML standard for attributes).

echo "<a href=view_gallery.php?cat=\"" . $rowd['category'] . "\">$category</a>";

I understand Sir, I treid it too still have no luck, I ended up using the ID in the HREF, and the view page first look up the name of the category by the id of previous page, once found, search for images of that categoryname that was found, I did not want to do it this way. It is double the effert for the page t find the result dont you agree.

To pull the Category name display it to the user and when the user selects one go to view page and AGAIN and search through same categories table so I can use the Category name (not id) to look up the images under that category. dumb if you ask me but I get why it is like that ... the spaces in the URL like you said :)

Thank you You taught me something I never knew.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.