Probably a stupid mistake...

phpnutphpnut Junior MemberShared Hoster
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! :)

[PHP]<?php
$gallery = strip_tags($_GET);
$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}'>Link</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}");
}
?>[/PHP]
My ongoing projects...
www.naturesmagazine.com
www.energyreform.org *new domain*
www.photographyavenue.com
----
You may also remember me as imnewtophp...

Comments

  • Zephyr281Zephyr281 Beginner Link Clerk
    It's not that the pre-existing array is gone. It's just that after the data is read by the first mysql_fetch_array, it can't be read again.

    I'm not the est that this, all I would know how to do with this would either be:
    1. Redo the query (I wouldn't do it this way)
    2. Have the first while loop store the data into an array, and use a foreach loop where you have the second while loop.
    I'd change the first while to something like:
    [PHP]
    while($row = mysql_fetch_array($result,MYSQL_ASSOC))
    {
    extract($row);
    if(isset($landing))
    {
    if($landing != "")
    {
    $landing_arr[$countervar] = $landing_id;
    $countervar = $countervar + 1;
    $land = $landing;
    }
    }
    }
    [/PHP]
    And the second to something like:
    [PHP]
    foreach($landing_arr as $value)
    {
    echo "<tr><td><div id='normal'><a href='/galleries/showGallery.php?gallery={$gallery}&landing={$value}'>Link</a></div></td></tr>";
    }
    [/PHP]

    I'm not saying this is the best way to do it, but it's all I can think of.
    arcsig.jpg
Sign In or Register to comment.