Jump to content

Alphabetical Links Disappear (solved)


thechris

Recommended Posts

On my page I have it so that it will list out all the anime but you can narrow your search by clicking on the alphabet on the top but when you click on one of the letters the alphabetical list disappears.

[code]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>iAnime Downloads</title>
<link href="Styles/basic.css" rel="stylesheet" type="text/css">
<link href="Styles/nav.css" rel="stylesheet" type="text/css">
<link href="Styles/menu.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style2 {color: #FFFFFF}
-->
</style>
<?php require_once('Connections/connectDB.php'); ?>
</head>

<body>
<div id="wrapper">
<div id="titlebar"><img src="Images/ban.png"></div>
<div id="nav">
<ul>
<li><a href="home.php">Home</a></li>
    <li><a href="downloads.php">Downloads</a></li>
    <li><a href="forum.php">Forums</a></li>
    <li><a href="support.php">Support</a></li>
    <li><a href="ianime.php">iAnime</a></li>
</ul>
</div>
<div id="top"><img src="Images/top.png"></div>
<div id="main content">
<div id="alphabet">
<?php
global $Key;
$Key = $_REQUEST['Key'];

if (!$Key) {
  $ASCII= 65; # uppercase (+32 for lowercase)
  $i = 1;
  while ($i < 27) {
    $Char = chr($ASCII);
    echo("<a href='?Key=$Char'>$Char</a>");
    if($i < 26) {
    echo(" - ");
    }
    $i++;
    $ASCII++;
  }
} else {
  $SQL = sprintf("SELECT anime_name, type  FROM Videos WHERE anime_name LIKE '$Key' ORDER BY anime_name ASC");
}
?>
</div>
<div id="list"><center>
<?php
mysql_select_db($database_connectDB, $connectDB);
$query_Recordset1 = "SELECT anime_name, type FROM Videos WHERE anime_name LIKE '$Key%' ORDER BY anime_name ASC";
$Recordset1 = mysql_query($query_Recordset1, $connectDB) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<br>
<table width="375" border="0">
  <tr bgcolor="#FF00FF">
    <td width="81"><span class="style2">Type</span></td>
    <td width="284"><span class="style2">Name</span></td>
  </tr>
  <?php do { ?>
  <tr>
      <td><?php echo $row_Recordset1['type']; ?></td>
      <td><?php echo $row_Recordset1['anime_name']; ?></td>
  </tr>
  <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>

</center>
</div>
</div>
<div id="bottom">
<div id="word">
&copy; <?php echo date('Y'); ?>
</div>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

[/code]
Link to comment
https://forums.phpfreaks.com/topic/25863-alphabetical-links-disappear-solved/
Share on other sites

It looks to me that it's because you have the while loop (where you create the list of letters) inside of an if statement.  If Key is NOT set then it creates the list.  Well when the user selects a letter, you set that value.

Try changing the following:
[code]
if (!$Key) {
  $ASCII= 65; # uppercase (+32 for lowercase)
  $i = 1;
  while ($i < 27) {
    $Char = chr($ASCII);
    echo("<a href='?Key=$Char'>$Char</a>");
    if($i < 26) {
    echo(" - ");
    }
    $i++;
    $ASCII++;
  }
} else {
  $SQL = sprintf("SELECT anime_name, type  FROM Videos WHERE anime_name LIKE '$Key' ORDER BY anime_name ASC");
}
[/code]

to:
[code]
$ASCII= 65; # uppercase (+32 for lowercase)
$i = 1;
while ($i < 27) {
  $Char = chr($ASCII);
  echo("<a href='?Key=$Char'>$Char</a>");
  if($i < 26) {
    echo(" - ");
  }
  $i++;
  $ASCII++;
}

if ($Key) {
  $SQL = sprintf("SELECT anime_name, type  FROM Videos WHERE anime_name LIKE '$Key' ORDER BY anime_name ASC");
}
[/code]

Archived

This topic is now archived and is closed to further replies.

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