Jump to content

alphabet datbase query


Porkie

Recommended Posts

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

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

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

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.