Jump to content

Display information by letter.


Recommended Posts

Guest Remember_me
hello all , i been looking for a tutorial to explain how to display infomation letter. I dont want to sort it. If i am not clear i hope this will make it.

here is the scirpt i am working on.
http://www.active-core.com/te1s1t.php as you can see im using MSQL and php to fetch data. What i cant figure out is when a user clicks on the letter A , i only want to display a column with a the letter A.

here is the code i am using

[code]echo "<center>A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | X | Y | Z</center>";
include("config.php");

//configs
$tablename = news1;
$rowid = newsid;

// rows to show per page
$rowsPerPage = 1;

// by default page
$pageNum = 1;


// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query  = "SELECT * FROM $tablename ORDER BY $rowid LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');
$table = mysql_query("SELECT * FROM $tablename ORDER BY $rowid DESC LIMIT $offset, $rowsPerPage",$connect);

echo '<br';

// print the information
while(list($val) = mysql_fetch_array($result))
{
$myrow = mysql_fetch_array($table);
echo "<center><table cellpadding='0' cellspacing='0' width='627' height='81'>";
echo "<tr><td class='company' height='21' width='627'><b><font color='#3A3A3A'>";
echo $myrow['title'];
echo "</font></b></a></td></tr><tr><td height='2' width='627'></td></tr><tr><td class='companyinfo' height='37' width='627'>";
echo $myrow['text1'];
echo "</td></tr><tr><td class='company' height='21' width='627'><font color='#3A3A3A'>";
echo $myrow['text2'];
echo "</font></td></tr></table><img src='http://www.active-core.com/images/spacertrans.gif' border='0' height='22' width='1'></center>";
}

echo '<br>';

// rows we have in database
$query  = "SELECT COUNT($rowid) AS numrows FROM $tablename";
$result  = mysql_query($query) or die('Error, query failed11');
$row    = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

$self = $_SERVER['PHP_SELF'];

// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link

echo '<center';

// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
    $page = $pageNum - 1;
    $prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
   
    $first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
    $prev  = ' [Prev] ';      // we're on page one, don't enable 'previous' link
    $first = ' [First Page] '; // nor 'first page' link
}

// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
    $page = $pageNum + 1;
    $next = " <a href=\"$self?page=$page\">[Next]</a> ";
   
    $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
    $next = ' [Next] ';      // we're on the last page, don't enable 'next' link
    $last = ' [Last Page] '; // nor 'last page' link
}

// print the page navigation link
echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;

echo '</center>';

?>
[/code]

i give any thanks to anyone who trys to solve this problem.  :'(
Link to comment
https://forums.phpfreaks.com/topic/13297-display-information-by-letter/
Share on other sites

easy.  make an array of all of those letters.  then loop through the array to output them to the screen but make the text that's outputted to the screen a hyperlink that sets a variable equal to something :  I've used this exact method before and it works great.

[code]$alpha = array('a','b','c,'...);
foreach ($alpha as $i) {
  echo "<a href=\"index.php?selected=$i\">$i</a>";
}

if (isset($selected)) {
  $result = mysql_query("SELECT * FROM table WHERE name LIKE '".$_GET['selected']."') or die(mysql_error());
}[/code]
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.