Jump to content

[SOLVED] ?image_cat=folder. echo's as 0


DeanWhitehouse

Recommended Posts

with part of my code

if(isset($_GET['image_cat'])) // If the URL ends in ?image_cat do everything in the brakets

{

$i = $_GET['image_cat'];

echo "get=".$i;

 

this shows 0 not what it should why is this , the url ending is

?image_cat=test

 

anyone.

here is my complete code

<?php
if(isset($_GET['image_cat'])) // If the URL ends in ?image_cat do everything in the brakets
{
$i = $_GET['image_cat'];
$query = "SELECT sub_cat FROM `sub_cat` WHERE `parent_cat` = '{$i}'";
$result = mysql_query($query) or die("Error:" . mysql_error());
$sql = "SELECT * FROM image_gallery WHERE `sub_folder`='{$cat}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql) or die ("Error:" . mysql_error());
$rw = mysql_fetch_assoc($reslt);
$cat = $row['catergory'];
$i = 0;
echo "catergory=".$cat;
echo "image link=".$rw['image_link'];
echo "sub cat=".$row['sub_cat'];
echo "get=".$i;
?>
<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['sub_cat'] ?></b></font><br><a href="?image_subcat=<?php echo $row['sub_cat']; ?>"><img width="150px" src="<?php echo $rw['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 Backs<br>";
}
require_once 'footer.php';
exit();
}
?>

Link to comment
Share on other sites

ok, thanks , i changed that now,

now this is what is now being echoed

catergory=
image link=
sub cat=
get=test

 

can anyone see why it is not finding the data i need

 

this is the code that should find it

<?php
if(isset($_GET['image_cat']))
{
$cater = $_GET['image_cat'];
$query = "SELECT sub_cat FROM `sub_cat` WHERE `parent_cat` = '{$cater}'";
$result = mysql_query($query) or die("Error:" . mysql_error());
$sql = "SELECT * FROM image_gallery WHERE `sub_folder`='{$cat}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql) or die ("Error:" . mysql_error());
$rw = mysql_fetch_assoc($reslt);
$cat = $row['catergory'];
$i = 0;
echo "catergory=".$cat;
echo "<br>";
echo "image link=".$rw['image_link'];
echo "<br>";
echo "sub cat=".$row['sub_cat'];
echo "<br>";
echo "get=".$cater;
?>

Link to comment
Share on other sites

i would echo $query and $sql to see if they are what i expect and if there are any records matching the statements.

 

another thing: you mysql_query, but you never do anything with this result:

 

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

 

nor do you ever define $row...

Link to comment
Share on other sites

this is a bit more of the code

<?php
if(isset($_GET['image_cat']))
{
$cater = $_GET['image_cat'];
$query = "SELECT sub_cat FROM `sub_cat` WHERE `parent_cat` = '{$cater}'";
$result = mysql_query($query) or die("Error:" . mysql_error());
$sql = "SELECT * FROM image_gallery WHERE `sub_folder`='{$cat}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql) or die ("Error:" . mysql_error());
$rw = mysql_fetch_assoc($reslt);
$cat = $row['catergory'];
$i = 0;
echo "catergory=".$cat;
echo "<br>";
echo "image link=".$rw['image_link'];
echo "<br>";
echo "sub cat=".$row['sub_cat'];
echo "<br>";
echo "get=".$cater;
?>
<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['sub_cat'] ?></b></font><br><a href="?image_subcat=<?php echo $row['sub_cat']; ?>"><img width="150px" src="<?php echo $rw['image_link']; ?>"></a></td><td>    </td>
	<?php

     $i++; // increase $i each time through the loop
}
?>
</td></tr></table>

Link to comment
Share on other sites

i expect you want something more like:

 

if(isset($_GET['image_cat']))
{
$cater = $_GET['image_cat'];
$query = "SELECT sub_cat FROM `sub_cat` WHERE `parent_cat` = '{$cater}'";
$result = mysql_query($query) or die("Error:" . mysql_error());
$row = mysql_fetch_assoc($result);
$cat = $row['catergory'];
$sql = "SELECT * FROM image_gallery WHERE `sub_folder`='{$cat}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql) or die ("Error:" . mysql_error());
$rw = mysql_fetch_assoc($reslt);

echo "catergory=".$cat;
echo "<br>";
echo "image link=".$rw['image_link'];
echo "<br>";
echo "sub cat=".$row['sub_cat'];
echo "<br>";
echo "get=".$cater;

Link to comment
Share on other sites

alrite, with lots of debugging. I have found that my while loop is not working.

this is the code for it

<?php
if(isset($_GET['image_cat']))
{
$cater = $_GET['image_cat'];
$query = "SELECT sub_cat FROM `sub_cat` WHERE `parent_cat` = '{$cater}'";
$result = mysql_query($query) or die("Error:" . mysql_error());
$r = mysql_fetch_assoc($result);
$car = $r['sub_cat'];
$sql = "SELECT * FROM image_gallery WHERE `sub_folder`='{$car}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql) or die ("Error:" . mysql_error());
$rw = mysql_fetch_assoc($reslt);
$i = 0;
echo "<br>";
echo "image link=".$rw['image_link'];
echo "<br>";
echo "sub cat=".$r['sub_cat']." and ".$car;
echo "<br>";
echo "get=".$cater;
?>
<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['sub_cat']; ?></b></font><br><a href="?image_subcat=<?php echo $row['sub_cat']; ?>"><img width="150px" src="<?php echo $rw['image_link']; ?>"></a></td><td>    </td>
	<?php

     $i++; // increase $i each time through the loop
echo "<br>";
echo "image link=".$rw['image_link'];
echo "<br>";
echo "sub cat=".$r['sub_cat']." and ".$car;
echo "<br>";
echo "get=".$cater;	 
}
?>
</td></tr></table>

 

any ideas why, and any ideas on how to fix it?

Link to comment
Share on other sites

solved.

Heres the code

<?php 
require_once 'header.php';
$time_stamp = date("d.m.Y");
$date = $time_stamp;
/////////////////////////////////////////////////////////////
if(isset($_GET['image_subcat'])) // If the URL ends in ?image_cat do everything in the brakets
{
$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());
$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']))
{
$cater = $_GET['image_cat'];
$query = "SELECT sub_cat FROM `sub_cat` WHERE `parent_cat` = '{$cater}'";
$result = mysql_query($query) or die("Error:" . mysql_error());
$result1 = mysql_query($query)  or die("Error:" . mysql_error());
$r = mysql_fetch_assoc($result1);
$car = $r['sub_cat'];
$sql = "SELECT * FROM image_gallery WHERE `sub_folder`='{$car}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql) or die ("Error:" . mysql_error());
$rw = mysql_fetch_assoc($reslt);
$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 $car; ?></b></font><br><a href="?image_subcat=<?php echo $row['sub_cat']; ?>"><img width="150px" src="<?php echo $rw['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 Backs<br>";
}
require_once 'footer.php';
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) or die("Error:" . mysql_error());
$sql = "SELECT * FROM image_gallery WHERE `folder_name`='{$cate}' ORDER BY RAND() LIMIT 1";
$reslt = mysql_query($sql) or die ("Error:" . mysql_error());
$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><a href="?image_cat=<?php echo $row['catergory']; ?>"><font style="font-size:large" color="#000000"><b><?php echo $row['catergory']; ?></b></font><br><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>";
}
if($_SESSION['log_in'] == true)
{
?>
<a href="http://chrisdavies.awardspace.com/add_catagories.php">Add Images</a><br>
<a href="http://chrisdavies.awardspace.com/upload.php">Add Categorys</a>
<?php
} 
require_once 'footer.php';
?>

Link to comment
Share on other sites

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.