On 7/15/09 10:30 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
On Wednesday 15 July 2009 16:21:22 tedd wrote:
> At 12:38 PM -0700 7/14/09, Miller, Terion wrote:
> >I am trying to make a page that displays a-z like a b c d e etc as links
> >then when you click open one it reloads itself and shows only the query
> >results that go with that letter...i'm not getting it....I get a page that
> >says ARRAY over and over...
> >
> >What I have so far:
>
> -snip-
>
> Why not have MySQL sort the data instead of using php?
>
> For example (from memory -- use with caution)
>
> SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1
>
> Then just change the offset to go up and down the list.
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
You could do what Tedd suggested, but use MySQL to actually limit the results
it returns you by using a like clause, i.e. WHERE `somefield` LIKE 'a%'.
*ducks to avoid people throwing things at him. I know it's slow!*
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
Hi all thanks for all the suggestions, I really had no idea this was going to
be so difficult..I am a bit closer..well I have the alphabet showing up now I
just have to get it to actually pull results..LMAO
Here is my code as it is today, I have by end of day to get it to work...yikes
the stress is unbearable, there are a million pagination scripts out there but
I can't find any good alpha ones I can understand.
Ok what I have so far: the top part lists all the restaurant names, the bottom
part has the alpha pagination ...neither links to the results of a
query...yet... Bit by bit right?
<?php
$sql = "SELECT DISTINCT name
FROM restaurants WHERE name LIKE
'$index_letter%' GROUP BY name DESC";
$result = mysql_query($sql) or die(mysql_error()) ;
$count =
mysql_num_rows($result);
while($row =
mysql_fetch_array($result)) {
$name=$row['name'];
//prints out restaurant name with link .....
echo "<a href=\"details.php?name=" .$name.
"\"> $name</a>\n<br>"; }
}
//alphabetical pagination
links if
(!isset($_GET['letter'])) {$letter = "A";} else {$letter = $_GET['letter'];}
echo '<div
align="center"><b>';
for ($i=65; $i<90; $i++) {
if ($letter!= chr($i)) {echo '<a
href="browse.php?letter='.chr($i).'">';}
echo chr($i)." ";
if ($letter!= chr($i)) {echo '</a>';}
}
echo "</b></div><p>";
$query="SELECT * FROM
restaurants WHERE name LIKE '".$letter."%'";
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php