Forum Moderators: coopster
Now, using this in the database query is fairly simple too:$letters = range('A', 'Z');
$links = '';
// Loop through the array of letters
for($i = 0; $i < 26; $i++) {
$spacer = ($i == 0)? '' : ' | ';
$links .= $spacer . '<a href="/mypage.php?filter=' . $letters[$i] . '>' . $letters[$i] . '</a>';
}
echo $links;
if(isset($_GET['filter'])) {
$where = ' WHERE author_name LIKE "' . mysql_real_escape_string($_GET['filter']) . '%"';
} else {
$where = '';
}
$sql = 'SELECT * FROM authors_table' . $where . ' ORDER BY author_name ASC';
$result = mysql_query($sql);
// etc...
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_stockholm2010, $stockholm2010);
$query_papers = "SELECT * FROM papers";
$papers = mysql_query($query_papers, $stockholm2010) or die(mysql_error());
$row_papers = mysql_fetch_assoc($papers);
$totalRows_papers = mysql_num_rows($papers);
if(isset($_GET['filter'])) {
$where = ' WHERE familyname LIKE "' . mysql_real_escape_string($_GET['filter']) . '%"';
} else {
$where = '';
}
$sql = 'SELECT * FROM familyname' . $where . ' ORDER BY familyname ASC';
$result = mysql_query($sql);
?>
<head>
</head>
<body>
<p><?php $letters = range('A', 'Z');
$links = '';
// Loop through the array of letters
for($i = 0; $i < 26; $i++) {
$spacer = ($i == 0)? '' : ' | ';
$links .= $spacer . '<a href="sort.php?filter=' . $letters[$i] . '>' . $letters[$i] . '</a>';
}
echo $links;?> </p>
<div>
<table class="tableResultsHeader"width="692" id-="id-""myTable">
<thead>
<tr>
<th width="244" class="rightborder" ><h3 align="left">Paper title </h3></th>
<th width="206" class="rightborder" ><h3 align="left">Corresponding Author</h3></th>
<th width="227" class="bottom" ><h3 align="left">Institution</h3></th>
</tr>
</thead>
<?php do { ?>
<tbody>
<tr>
<td width="244" valign="middle" class="tableResults" ><h4><a href="uploads/<?php echo $row_results['file'];?>"><?php echo $row_results['papertitle']; ?></a><br />
</h4></td>
<td width="206" class="tableResults"><h4><?php echo $row_results['firstname']; ?> <?php echo $row_results['familyname']; ?><br />
</h4></td>
<td width="227" class="tableResultsBottom"><h4><?php echo $row_results['institution']; ?><br />
</h4></td>
</tr>
</tbody>
<?php } while ($row_papers = mysql_fetch_assoc($papers)); ?>
</table>
</div>
</body>
</html>
<?php
mysql_free_result($papers);
?>
$links .= $spacer . '<a href="/mypage.php?filter=' . $letters[$i] . '>' . $letters[$i] . '</a>';
$links .= $spacer . '<a href="/mypage.php?filter=' . $letters[$i] . '">' . $letters[$i] . '</a>'; With this system, I strongly suggest you set up an index on your author_name column, and limit it to the first character of the author name. Will greatly speed up this script.$letters = range('A', 'Z');
$letters_real = array();
for($i = 0; $i < 26; $i++) {
$sql = 'SELECT id FROM authors_table WHERE author_name LIKE "' . $letters[$i] . '%" LIMIT 1';
$result = mysql_query($sql);
if(mysql_fetch_row($result)) {
$letters_real[] = $letters[$i];
}
}
$links = '';
$count = count($letters_real);
for($i = 0; $i < $count; $i++) {
$spacer = ($i == 0)? '' : ' | ';
$links .= $spacer . '<a href="/mypage.php?filter=' . $letters_real[$i] . '">' . $letters_real[$i] . '</a>';
}