AdRock Posted December 4, 2006 Share Posted December 4, 2006 I have a problem with inserting a $_GET variable into a url.The variable is a category from a database and it could be one of three things.I want to put the variable into my url so it opens the right page.The problem I'm having is putting the variable into this url[code]<li class="current"><a href="/gallery/'.$cat'/'.$webpage.'/1">First</a></li>[/code]I get this error message when i use these lines[quote]Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/adrock/public_html/image.php on line 28[/quote]Everything else works fine except the hyperlinksHere is my entire page[code]h2 style="margin-bottom:0">Image Gallery</h2><hr><div style="text-align:center"><?php include "includes/connection.php";$cat = $_GET['cat'];$webpage = basename(image); function pagination_five($total_pages,$page){ global $webpage; $max_links = 7; $h=1; if($page>$max_links){ $h=(($h+$page)-$max_links); } if($page>=1){ $max_links = $max_links+($page-1); } if($max_links>$total_pages){ $max_links=$total_pages+1; } echo '<div class="page_numbers"> <ul>'; if($page>"1"){ echo '<li class="current"><a href="/gallery/'.$cat'/'.$webpage.'/1">First</a></li> <li class="current"><a href="/gallery/'.$cat.'/'.$webpage.'/'.($page-1).'">Prev</a></li> '; } if($total_pages!=1){ for ($i=$h;$i<$max_links;$i++){ if($i==$page){ echo '<li><a class="current">'.$i.'</a></li>'; } else{ echo '<li><a href="/gallery/'.$cat.'/'.$webpage.'/'.$i.'">'.$i.'</a> </li>'; } } } if(($page >="1")&&($page!=$total_pages)){ echo '<li class="current"><a href="/gallery/'.$cat.'/'.$webpage.'/'.($page+1).'">Next</a></li> <li class="current"><a href="/gallery/'.$cat.'/'.$webpage.'/'.$total_pages.'">Last</a></li> '; } echo '</ul> </div> '; }$result = mysql_query("Select count(*) from images WHERE cat='$cat'") or die (mysql_error()); $numrows = mysql_fetch_row($result); if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1); $entries_per_page = 1; $total_pages = ceil($numrows[0]/$entries_per_page); $offset = (($page * $entries_per_page) - $entries_per_page); //after we have $total_pages and $page, we can include the //pagination style wherever we want on the page. //so far there is no output from the script, so we could have //pagination before or after the pages results //before the results $result = mysql_query("SELECT id,image,thumb FROM images WHERE cat='$cat' ORDER BY id ASC LIMIT $offset,$entries_per_page"); if(!$result) die(mysql_error()); $err = mysql_num_rows($result); if($err == 0) die("No matches met your criteria."); while($row=mysql_fetch_array($result)){ echo "<img src='/images/gallery/large/".$row['image']."'>";} //or after the results pagination_five($total_pages,$page); ?></div>[/code] Link to comment https://forums.phpfreaks.com/topic/29452-how-to-put-_getcat-variable-into-a-url/ Share on other sites More sharing options...
fert Posted December 4, 2006 Share Posted December 4, 2006 you need to escape the quotes in:[code]echo '<li><a href="/gallery/'.$cat.'/'.$webpage.'/'.$i.'">'.$i.'</a> </li>'; [/code]like this[code]echo "<li><a href=\"gallery\"".$cat.$webpage.$i.">\".$i.\"</a> </li>"; [/code] Link to comment https://forums.phpfreaks.com/topic/29452-how-to-put-_getcat-variable-into-a-url/#findComment-135144 Share on other sites More sharing options...
papaface Posted December 4, 2006 Share Posted December 4, 2006 Not entirely sure if this will solve your error.But in places where you have:[code]echo '<li class="current"><a href="/gallery/'.$cat'/'.$webpage.'/1">First</a></li> <li class="current"><a href="/gallery/'.$cat.'/'.$webpage.'/'.($page-1).'">Prev</a></li> '; [/code]make it like:[code] echo "<li class=\"current\"><a href=\"gallery\"".$cat"/".$webpage."/1" .">First</a></li> <li class=\"current\"><a href=\"gallery\"" .$cat."/".$webpage."/".($page-1)."\">Prev</a></li> "; [/code]instead. Link to comment https://forums.phpfreaks.com/topic/29452-how-to-put-_getcat-variable-into-a-url/#findComment-135147 Share on other sites More sharing options...
sanfly Posted December 4, 2006 Share Posted December 4, 2006 I would suggest it may have something to do with the missing full stop after $cat[quote]echo '<li class="current"><a href="/gallery/'.$cat[color=red][b].[/b][/color]'/'.$webpage.'/1">First</a></li>[/quote] Link to comment https://forums.phpfreaks.com/topic/29452-how-to-put-_getcat-variable-into-a-url/#findComment-135155 Share on other sites More sharing options...
AdRock Posted December 4, 2006 Author Share Posted December 4, 2006 Will it make any difference that I've used mod rewrite for the urls? Link to comment https://forums.phpfreaks.com/topic/29452-how-to-put-_getcat-variable-into-a-url/#findComment-135160 Share on other sites More sharing options...
AdRock Posted December 4, 2006 Author Share Posted December 4, 2006 I tried all the suggestions but I'm getting the that the page cannot be displayedI have looked at the url when I hover over a link and I get this[quote]mydomain.com/gallery//image/1[/quote]It seems that the $cat is not being placed in the url and I don't know why as $webpage is in the urlI also tried a url like this because it works for another page I have [code]<a href='/gallery/$cat/image/$counter'>[/code]but it actually puts $cat in the url not the value of $cat[quote]mydomain.com/gallery/$cat/image/1[/quote]Has anyone got any more ideas....This is really strange ??? Link to comment https://forums.phpfreaks.com/topic/29452-how-to-put-_getcat-variable-into-a-url/#findComment-135190 Share on other sites More sharing options...
jcbarr Posted December 5, 2006 Share Posted December 5, 2006 $cat has to be enclosed in " " in an echo statment for it to actually echo the value of the variable.If you use something like;[code]echo "<a href='gallery/$cat/image/$counter'>";[/code]That should work. Link to comment https://forums.phpfreaks.com/topic/29452-how-to-put-_getcat-variable-into-a-url/#findComment-135249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.