Jump to content

if(isset($_GET['image_cat']) && $_GET['image_subcat'])


Recommended Posts

Is this the correct syntax for to check two things in a $_GET statement

 

if(isset($_GET['image_cat']) && $_GET['image_subcat'])

 

the address will be

?image_cat=landscape&image_subcat=test

 

and i need it to check both of these, this is the rest of my code

 

<?php
if(isset($_GET['image_cat']) && $_GET['image_subcat']) // If the URL ends in ?image_cat do everything in the brakets
{
$cat = $_GET['image_cat'];
$sub_cat = $_GET['image_subcat']; 
$query = "SELECT folder_name,image_link,image_id,image_name,sub_folder FROM `image_gallery` WHERE `folder_name` = '{$cat}' AND `sub_folder` = '{$sub_cat}' ORDER BY image_id ASC";
$result = mysql_query($query) or die("Error:" . mysql_error());
$i = 0;
?>
<table align="center"><tr>
<?php
while ($row = mysql_fetch_assoc($result))  {
     if ($i == 4) {
          $i = 0; // reset variable
          echo "</td></tr><tr></tr><tr><td>"; // break the line
     }

?><a href="<?php echo $row['image_link']; ?>" rel="lightbox [main]" title="<?php echo $row['image_name']; ?>" ><img width="150px" src="<?php echo $row['image_link']; ?>"></a></td><td>
	<?php

     $i++; // increase $i each time through the loop
}
?>
</td></tr></table>
<?php
require_once 'footer.php';
exit();
}
/////////////////////////////////////////////////////////////
if(isset($_GET['image_cat'])) // If the URL ends in ?image_cat do everything in the brakets
{
$i = $_GET['image_cat'];
$que = "SELECT sub_cat,imagelink FROM `sub_cat` ORDER BY sub_cat ASC";
$resu = mysql_query($que) ;
$query = "SELECT catergory FROM `image_catergory` ORDER BY catergory ASC";
$result = mysql_query($query) ;
$sql = "SELECT * FROM sub_cat WHERE `imagelink`='{$subcate}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql);
$rw = mysql_fetch_assoc($reslt); 
$wo = mysql_fetch_assoc($result);
$subcate = $rw['sub_cat']; 
$i = 0;
?>
<table align="center"><tr>
<?php
while ($row = mysql_fetch_assoc($resu))  {
     if ($i == 4) {
          $i = 0; // reset variable
           echo "<tr>"; // break the line
     }

	?><td><font style="font-size:large"><b><?php echo $row['sub_cat'] ?></b></font><br><a href="?image_cat=<?php echo $wo['catergory']; ?>&image_subcat=<?php echo $row['sub_cat']; ?>"><img width="150px" src="<?php echo $row['imagelink']; ?>"></a></td><td>    </td>
	<?php

     $i++; // increase $i each time through the loop
}
?>
</td></tr></table>
<?php
if (mysql_num_rows($resu) < 1) 
{
echo "No Images Yet. <br>Keep Checking Backs<br>";
}
exit();
}
?>

Link to comment
https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/
Share on other sites

Yes you can, if the parameters exist in the URI.

For example:

index.php?uid=45&username=Wolphie

 

<?php
$uid = htmlentities($_GET['uid']); // Remember to secure values!
$username = htmlentities($_GET['username']); // Remember to secure values!

print $uid; // Returns 45
print $username; // Returns "Wolphie"
?>

 

<?php
if(isset($_GET['param']) && isset($_GET['param'])) { // The code inside the parathenses doesn't look pretty but ah well!
  print 'The GET parameters are set.';
}
else {
  print 'The GET parameters need to be set!';
}
?>

ok, that now works.

But how can i get this to work.

$query = "SELECT folder_name,image_link,image_id,image_name,sub_folder FROM `image_gallery` WHERE `sub_folder` = '{$sub_cat}'ORDER BY image_id ASC";

 

when i add a AND to it , it doesn't work.

 

e.g.

$query = "SELECT folder_name,image_link,image_id,image_name,sub_folder FROM `image_gallery` WHERE `sub_folder` = '{$sub_cat}' AND `folder_name` =  '{$cat}' ORDER BY image_id ASC";

erm, ok

well this is some of the code

<?php
$cat = $_GET['image_cat'];
$sub_cat = $_GET['image_subcat']; 
$query = "SELECT folder_name,image_link,image_id,image_name,sub_folder FROM `image_gallery` WHERE `sub_folder` = '{$sub_cat}' ORDER BY image_id ASC";
$result = mysql_query($query) or die("Error:" . mysql_error());
//$qry = "SELECT folder_name,image_link,image_id,image_name,sub_folder FROM `image_gallery` WHERE `folder_name` = '{$cat}' ORDER BY image_id ASC";
//$reslt = mysql_query($qry) or die("Error:" . mysql_error());
//$rw = mysql_fetch_assoc($reslt)
$i = 0;
?>

 

ok, well it is for a subcatergory in a image gallery,  but it isn't selecting from the actual main catergory only the sub, and when i add the AND. The page doesn't show any image

Well that is quite clearly not the code which contains the query with two criteria in your WHERE clause -- we need to see that code.

 

I assume you're sure that there are actually matching rows? Have you tried echoing the query inself to check exactly what is being executed, to check that variables are set etc?

$query = "SELECT folder_name,image_link,image_id,image_name,sub_folder FROM `image_gallery` WHERE `folder_name` = '{$cat}' AND `sub_folder` = '{$sub_cat}' ORDER BY image_id ASC";

$result = mysql_query($query) or die("Error:" . mysql_error());

 

and yes , just echoed them out and they are correct.

 

ok, anyone got any ideas,  i need to have main catergory's and then sub catergorys in it.

this is my database structure

 

3 tables
image_gallery
(
image_id
folder_name
image_name
img_time
image_link
filename
sub_folder
)

image_catergory
(
catergory
image_link
)

sub_cat
(
sub_cat
parent_cat
imagelink
)

 

this is my code,

to display this , but i can't get it right

<?php 
require_once 'header.php';
$time_stamp = date("d.m.Y");
$date = $time_stamp;
/////////////////////////////////////////////////////////////
if(isset($_GET['image_cat']) && isset($_GET['image_subcat'])) // If the URL ends in ?image_cat do everything in the brakets
{
$cat = $_GET['image_cat'];
$sub_cat = $_GET['image_subcat'];
$check = "SELECT sub_cat FROM sub_cat WHERE `parent_cat` = '{$cat}'"; 
$check2 = mysql_query($check) or die ("Error:" . mysql_error());
$rom = mysql_fetch_assoc($check2);
$cat2 = $rom['sub_cat'];
$query = "SELECT folder_name,image_link,image_id,image_name,sub_folder FROM `image_gallery` WHERE `sub_folder` = '{$cat2}' ORDER BY image_id ASC";
$result = mysql_query($query) or die("Error:" . mysql_error());
$i = 0;
?>
<table align="center"><tr>
<?php
while ($row = mysql_fetch_assoc($result))  {
     if ($i == 4) {
          $i = 0; // reset variable
          echo "</td></tr><tr></tr><tr><td>"; // break the line
     }

?><a href="<?php echo $row['image_link']; ?>" rel="lightbox [main]" title="<?php echo $row['image_name']; ?>" ><img width="150px" src="<?php echo $row['image_link']; ?>"></a></td><td>
	<?php

     $i++; // increase $i each time through the loop
}
?>
</td></tr></table>
<?php
require_once 'footer.php';
exit();
}
/////////////////////////////////////////////////////////////
if(isset($_GET['image_cat'])) // If the URL ends in ?image_cat do everything in the brakets
{
$i = $_GET['image_cat'];
$que = "SELECT sub_cat FROM sub_cat WHERE `parent_cat` = '{$i}'"; 
$resu = mysql_query($que) ;
$query = "SELECT catergory FROM `image_catergory` ORDER BY catergory ASC";
$result = mysql_query($query) ;
$sql = "SELECT * FROM sub_cat WHERE `imagelink`='{$subcate}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql);
$rw = mysql_fetch_assoc($reslt); 
$wo = mysql_fetch_assoc($result);
$subcate = $rw['sub_cat']; 
$i = 0;
?>
<table align="center"><tr>
<?php
while ($row = mysql_fetch_assoc($resu))  {
     if ($i == 4) {
          $i = 0; // reset variable
           echo "<tr>"; // break the line
     }

	?><td><font style="font-size:large"><b><?php echo $row['sub_cat'] ?></b></font><br><a href="?image_cat=<?php echo $wo['catergory']; ?>&image_subcat=<?php echo $row['sub_cat']; ?>"><img width="150px" src="<?php echo $row['imagelink']; ?>"></a></td><td>    </td>
	<?php

     $i++; // increase $i each time through the loop
}
?>
</td></tr></table>
<?php
if (mysql_num_rows($resu) < 1) 
{
echo "No Images Yet. <br>Keep Checking Backs<br>";
}
exit();
}
/////////////////////////////////////////////////////////////
//No ID passed to page, display user list:
$query = "SELECT catergory,image_link FROM `image_catergory` ORDER BY catergory ASC";
$result = mysql_query($query) ;
$sql = "SELECT * FROM image_catergory WHERE `image_link`='{$cate}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql);
$rw = mysql_fetch_assoc($reslt); 
$cate = $row['catergory']; 
$i = 0;
?>
<table align="center"><tr>
<?php
while ($row = mysql_fetch_assoc($result))  {
     if ($i == 4) {
          $i = 0; // reset variable
           echo "<tr>"; // break the line
     }

	?><td><font style="font-size:large"><b><?php echo $row['catergory'] ?></b></font><br><a href="?image_cat=<?php echo $row['catergory']; ?>"><img width="150px" src="<?php echo $row['image_link']; ?>"></a></td><td>    </td>
	<?php

     $i++; // increase $i each time through the loop
}
?>
</td></tr></table>
<?php
if (mysql_num_rows($result) < 1) 
{
echo "No Images Yet. <br>Keep Checking Back<br>";
}
require_once 'footer.php';
?>

 

i would do the database, but i can't seem to get it working now. ANY HELP PLEASEEE

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.