Probably just a stupid mistake...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpnut
Forum Newbie
Posts: 5
Joined: Sat Jul 29, 2006 6:17 pm

Probably just a stupid mistake...

Post by phpnut »

Okay, I've encountered a new problem with a subcategory system in my photo gallery app. The thing seems to be working... it returns the correct amount of rows from the database, but won't format it when using the 'while' loop.
The script should get rows in the database that have the gallery that matches GET information. Then, it checks to see if there is a subcategory, or in this case it's labeled landing. If there is a landing, it adds a 1 to a counter variable. After it checks every row, the program either displays a list of links to the subcategories or redirects to a main gallery.
Here's my problem: If rows are returned, the formatting around where the list of links should go are there, but the links simply won't show up. It's almost like the array I created earlier in the program isn't there.
If anyone can see why this isn't working, I'd really appreciate it! :)

Code: Select all

<?php
$gallery = strip_tags($_GET['gallery']);
$dbhost = "*****";
$dbuser = "*****";
$dbpass = "*****";
$db = "siteinfo";
$connect = mysql_connect($dbhost,$dbuser,$dbpass)
  or die(mysql_error());
$selectdb = mysql_select_db($db,$connect)
  or die(mysql_error());
$query = "SELECT id,landing,landing_id FROM photographs WHERE gallery = '$gallery'";
$result = mysql_query($query);
$countervar = "0";
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
  extract($row);
  if(isset($landing))
    {
      if($landing != "")
        {
          $countervar = $countervar + 1;
          $land = $landing;
        }
    }
}
if($countervar >= "1")
{
  session_start();
include("/files/includes/headerinclude.php");
echo "<body>";
echo "<table border='0' cellspacing='1' cellpadding='1' width='700' align='center'>";
echo "<tr>";
echo "<td colspan='2' valign='bottom' align='left'>";
include("/files/includes/topimageinclude.php");
echo "</td>";
echo "</tr>";
echo "<tr>
      <td valign='bottom' align='left' colspan='2'>";
      include("/files/includes/navbarinclude.php");
echo "</td></tr>";
echo "<tr>";
echo "<td width='100' valign='top' align='left'>";
include("/files/includes/sidebarinclude.php");
echo "</td>";
echo "<td width='600' valign='top' align='left'>";
echo "<table width='600' border='0' cellspacing='1' cellpadding='1'>";
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
  extract($row);
  echo "<tr><td><div id='normal'><a href='/galleries/showGallery.php?gallery={$gallery}&landing={$landing_id}</a></div></td></tr>";
}
echo "</table>";
echo "</td>";
echo "</tr></table>";
include("/files/includes/footerinclude.php");
echo "</body>";
echo "</html>";
}
  else
    {
      header("Location:/galleries/showGallery.php?gallery={$gallery}");
    }
?>
User avatar
darodesign
Forum Newbie
Posts: 19
Joined: Mon Aug 28, 2006 8:58 am
Location: Berlin
Contact:

Post by darodesign »

I've seen only one error:

<a href='/galleries/showGallery.php?gallery={$gallery}&landing={$landing_id} ' <<<<<------------ You've missed the ' , i know this Problem, the Links won't be shown, because the Link name and following tags, are beeing included into the URL!

Regards
phpnut
Forum Newbie
Posts: 5
Joined: Sat Jul 29, 2006 6:17 pm

Post by phpnut »

Thanks, but that doesn't seem to be it. Anyone find anything?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Why are you extracting $row twice? If you have alread set the vars from $row, use them later without the extract.
phpnut
Forum Newbie
Posts: 5
Joined: Sat Jul 29, 2006 6:17 pm

Post by phpnut »

I didn't even realize I extracted twice, but it still is not working...
It will return the amount of rows mysql has sent, so I know there are links to be generated.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
/* Handle var query string data */
$gallery = strip_tags($_GET['gallery']);

/* Set up database connection details */
$dbhost = "*****";
$dbuser = "*****";
$dbpass = "*****";
$db = "siteinfo";

/* Hit the database */
if (!$connect = mysql_connect($dbhost,$dbuser,$dbpass))
{
    die('Could not connect to the database server: ' . mysql_error());
}

if (!mysql_select_db($db,$connect))
{
    die('Could not connect to the database ' . $db . ': ' . mysql_error());
}

$query = "SELECT id,landing,landing_id FROM photographs WHERE gallery = '$gallery'";
if (!$result = mysql_query($query))
{
    die('Could not execute the query: ' . mysql_error());
}

$countervar = "0";
while ($row = mysql_fetch_array($result))
{
    /* Set some vars. Some for now, so for later */
    $landing = $row['landing'];
    $gallery = $row['gallery'];
    $landing_id = $row['landing_id'];

    if (!empty($landing))
    {
        $countervar++;
    }
}

if ($countervar != 0)
{
    session_start();
    include '/files/includes/headerinclude.php';
	echo '
<body>
<table border="0" cellspacing="1" cellpadding="1" width="700" align="center">
	<tr>
		<td colspan="2" valign="bottom" align="left">';

    include '/files/includes/topimageinclude.php';
	echo '
		</td>
    </tr>
    <tr>
        <td valign="bottom" align="left" colspan="2">';

    include '/files/includes/navbarinclude.php';
    echo '
	    </td>
	</tr>
	<tr>
        <td width="100" valign="top" align="left">';
		
	include '/files/includes/sidebarinclude.php';
	echo '
	    </td>
        <td width="600" valign="top" align="left">

		    <table width="600" border="0" cellspacing="1" cellpadding="1">
                <tr>
				    <td>
					    <div id="normal">
						<a href="/galleries/showGallery.php?gallery=' . $gallery . '&landing=' . $landing_id . '">' . $gallery . '</a>
						</div>
				    </td>
				</tr>
			</table>
			
		</td>
	</tr>
</table>';

    include '/files/includes/footerinclude.php';
    echo '
</body>
</html>';
}
else
{
    header('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/galleries/showGallery.php?gallery=' . $gallery);
}
?>
Post Reply