Porkie Posted June 16, 2009 Share Posted June 16, 2009 hi i want the alphabet a-b-c-d-e-f-g etc.... at the bottom of my page.When a user clicks on say "a" , my database will find all bands begining with "a". What sort off code will i be looking at here for the query of the database? Any help will be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/162456-alphabet-datbase-query/ Share on other sites More sharing options...
chronister Posted June 16, 2009 Share Posted June 16, 2009 click here and hit the First Result Quote Link to comment https://forums.phpfreaks.com/topic/162456-alphabet-datbase-query/#findComment-857492 Share on other sites More sharing options...
Porkie Posted June 16, 2009 Author Share Posted June 16, 2009 nah thats not the problem its how i link the alphabet thing so when a user clicks a letter the sql query runs, i mean how do i make it link the alphabet to the query system? Code <body> A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z </body> <?php $sql = mysql_query("SELECT * FROM Bands WHERE bandname LIKE value%"); while ($row = mysql_fetch_row($sql)) { echo "$row[0] $row[1] $row[2] <br />"; } ?> </html> cheers in advance Quote Link to comment https://forums.phpfreaks.com/topic/162456-alphabet-datbase-query/#findComment-857514 Share on other sites More sharing options...
.josh Posted June 16, 2009 Share Posted June 16, 2009 $alpha = range('A','Z'); function linkify(&$letter) { $letter = "<a href='?l={$letter}'>{$letter}</a>"; } array_walk($alpha,'linkify'); $alpha = implode(' - ',$alpha); echo $alpha; $search = (in_array(strtolower($_GET['l']),range('a','z'))? $_GET['l'] : 'A'; $sql = mysql_query("SELECT * FROM Bands WHERE bandname LIKE '{$search}%"); Quote Link to comment https://forums.phpfreaks.com/topic/162456-alphabet-datbase-query/#findComment-857528 Share on other sites More sharing options...
Porkie Posted June 16, 2009 Author Share Posted June 16, 2009 thanks for the reply mate Parse error: syntax error, unexpected ';' in /home/myuklive/public_html/Test/erm.php on line 23 Line 23$search = (in_array(strtolower($_GET['l']),range('a','z'))? $_GET['l'] : 'A'; } Quote Link to comment https://forums.phpfreaks.com/topic/162456-alphabet-datbase-query/#findComment-857534 Share on other sites More sharing options...
.josh Posted June 16, 2009 Share Posted June 16, 2009 damn man... I did the hard part for you. Can't find a simple syntax error? $search = (in_array(strtolower($_GET['l']),range('a','z')))? $_GET['l'] : 'A'; Quote Link to comment https://forums.phpfreaks.com/topic/162456-alphabet-datbase-query/#findComment-857539 Share on other sites More sharing options...
Porkie Posted June 16, 2009 Author Share Posted June 16, 2009 On the show results, i get an error, im i doing something wrong? Thanks Crayon Violent help much appreciated. ErrorWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/myuklive/public_html/Test/erm.php on line 26 Line26while($row = mysql_fetch_array($sql)) Code <?php $con = mysql_connect("localhost","myuklive_forum","615455"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myuklive_Bands", $con); $alpha = range('A','Z'); function linkify(&$letter) { $letter = "<a href='?l={$letter}'>{$letter}</a>"; } array_walk($alpha,'linkify'); $alpha = implode(' - ',$alpha); echo $alpha; $search = (in_array(strtolower($_GET['l']),range('a','z')))? $_GET['l'] : 'A'; $sql = mysql_query("SELECT * FROM Bands WHERE bandname LIKE '{$search}%"); while($row = mysql_fetch_array($sql)) { echo $row['bandname']; echo "<br />"; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/162456-alphabet-datbase-query/#findComment-857557 Share on other sites More sharing options...
Philip Posted June 16, 2009 Share Posted June 16, 2009 It is because your query failed. Do you need to edit the column or table names? Quote Link to comment https://forums.phpfreaks.com/topic/162456-alphabet-datbase-query/#findComment-857560 Share on other sites More sharing options...
Alex Posted June 16, 2009 Share Posted June 16, 2009 And there's also a missing ' $sql = mysql_query("SELECT * FROM Bands WHERE bandname LIKE '{$search}%'"); Quote Link to comment https://forums.phpfreaks.com/topic/162456-alphabet-datbase-query/#findComment-857563 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.