Guest Remember_me Posted June 30, 2006 Share Posted June 30, 2006 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 numberif(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' linkecho '<center';// print 'previous' link only if we're not// on page oneif ($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 pageif ($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 linkecho $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. :'( Quote Link to comment https://forums.phpfreaks.com/topic/13297-display-information-by-letter/ Share on other sites More sharing options...
Guest Remember_me Posted June 30, 2006 Share Posted June 30, 2006 i think i solved it. Quote Link to comment https://forums.phpfreaks.com/topic/13297-display-information-by-letter/#findComment-51230 Share on other sites More sharing options...
thepip3r Posted June 30, 2006 Share Posted June 30, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/13297-display-information-by-letter/#findComment-51277 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.