Jump to content

How to put $_GET['cat']; variable into a url


AdRock

Recommended Posts

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 hyperlinks

Here 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

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.
I tried all the suggestions but I'm getting the that the page cannot be displayed

I 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 url

I 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  ???

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.