DeanWhitehouse Posted May 23, 2008 Share Posted May 23, 2008 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/ Share on other sites More sharing options...
p2grace Posted May 23, 2008 Share Posted May 23, 2008 Use this to check them: if(isset($_GET['image_cat']) && isset($_GET['image_subcat'])){ You want to make sure both are set before using them. I didn't look at the rest of your code for any errors. Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548316 Share on other sites More sharing options...
DeanWhitehouse Posted May 23, 2008 Author Share Posted May 23, 2008 ok, but can i get both of these from it, using $_GET['']; Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548319 Share on other sites More sharing options...
Wolphie Posted May 23, 2008 Share Posted May 23, 2008 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!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548320 Share on other sites More sharing options...
DeanWhitehouse Posted May 23, 2008 Author Share Posted May 23, 2008 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"; Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548335 Share on other sites More sharing options...
GingerRobot Posted May 23, 2008 Share Posted May 23, 2008 Any chance you could define 'doesn't work' ? What happens? Do you get an error? What code are you using? Do you have an or die statement on your query? What's the output? What's the expected output. Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548338 Share on other sites More sharing options...
DeanWhitehouse Posted May 23, 2008 Author Share Posted May 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548341 Share on other sites More sharing options...
GingerRobot Posted May 23, 2008 Share Posted May 23, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548349 Share on other sites More sharing options...
DeanWhitehouse Posted May 23, 2008 Author Share Posted May 23, 2008 $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. Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548353 Share on other sites More sharing options...
DeanWhitehouse Posted May 23, 2008 Author Share Posted May 23, 2008 anyone , have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548368 Share on other sites More sharing options...
DeanWhitehouse Posted May 23, 2008 Author Share Posted May 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548389 Share on other sites More sharing options...
sasa Posted May 23, 2008 Share Posted May 23, 2008 $sub_cat = $_GET['image_subcat']; but in query `sub_folder` = '{$cat2}' ! and SELECT * FROM sub_cat WHERE `imagelink`='{$subcate}' ORDER BY RAND() LIMIT 1 betore $subcate is setup Quote Link to comment https://forums.phpfreaks.com/topic/106973-ifisset_getimage_cat-_getimage_subcat/#findComment-548393 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.