Re: Alphabetical pagination

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>
> 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:
>                             <?php
>
> if(!isset($_SESSION['RestaurantList']))
>
> {
>                                      // List not grabbed yet, so run
> query and store in $_SESSION
>
>                                                        $sql = "SELECT
> DISTINCT name FROM restaurants  GROUP BY name DESC";
>
> $result = mysql_query($sql) or die(mysql_error()) ;
>
> $count = mysql_num_rows($result);
>
> echo $count;
>
>
> while($row = mysql_fetch_array($result)) {
>
>
>
> $name=array($row['name'],0,1);
>
> //$name = array('name');
>
>                                                        echo "<a
> href=\"page.php?name=" .$name. "\"> $name</a>\n";
>
> }
>
>
>                                                                    }
>
>
>
> $alphabet = range('A', 'Z');
>
> foreach ($alphabet as $letter) {
>
> echo '<a href="' . $_SERVER['PHP_SELF']
>
> . '?letter=' . $letter . '">' . $letter . '</a>';
>
> }
>
>
>
>
>
>
> ?>
>

Well, are you opposed to using Javascript?

//javascript function
<script language="JavaScript">
<!--
function searchLetter(letter) {
document.my_form.letter.value=letter;
document.my_form.submit();
}
//-->
</script>

//You could make a hidden form field to store the value of the letter
selected.
<form name="my_form" method="POST" action="<?php echo $_SERVER['PHP_SELF'];
?>">
<input type="hidden" name="letter" value="<?php echo $_POST['letter']; ?>">
</form>

//Perform your query and search only for the letter if it isn't blank.
<?php
$selected_letter = $_POST['letter'];
if ($select_letter != "") {
$sql = "SELECT DISTINCT name FROM restaurants WHERE name LIKE
'$letter%' GROUP BY name DESC";
}
?>
//Print out all your letters
<?php
$alphabet = range('A', 'Z');

foreach ($alphabet as $letter) {
?>
//Have the links call a javascript function that updates the letter selected
and resubmits the form to perform your new query
<a href="javascript:searchLetter('<?php echo $letter; ?>')">$letter</a>
<?php
}
?>

Something like that. I haven't tested any of that code just typed it up real
quick to give you an idea of one way to possibly do it.

Hope that helps.

Dan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux