Jump to content

alphabet datbase query


Porkie

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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}%");

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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.