A-Z Search

Hi, I have been trying to sort out an A-Z search of books in my myql data base so there are 26 hyperlinks on the page and when you click on letter J for example it calls all the books beginning with the letter J and displays them, I know it is something to do with the $_GET ‘letter’ which changes the url to like search?letter=j.php but not sure, does anybody have a simple solution I have searched for a turtorial for days and am pulling my hair out.

Cheers in advance

What did you search for, and where did you search? And why was it not sufficient? To be honest, I’m surprised that you didn’t find anything that suited your needs, especially since you know it has to do with $_GET variables and the situation is so generic you should have been able to figure it out with google or the PHP manual within minutes.

Edit:
What you’re looking for is this:

[php]

<?php if ($_GET['letter'] == "A") { displayAllBooksStartingWithA(); } ?>

A
[/php]

Since you’re using MySQL as a backend though, I’d suggest this for more efficiency:

[php]

<?php $letter = $_GET['letter']; $sql = "SELECT * FROM books WHERE title LIKE '".$letter."%'"; displayAllTheseBooks(mysql_query($sql)); ?>

A
[/php]

But since this poses a security hole (see the links in my signature), this would be better:

[php]

<?php $letter = "A"; if (strlen($_GET['letter']) == 1 && preg_match("/[A-Z]/", $_GET['letter'])) { $letter = $_GET['letter']; } $sql = "SELECT * FROM books WHERE title LIKE '".$letter."%'"; displayAllTheseBooks(mysql_query($sql)); ?>

A
[/php]

Code not guaranteed to work.

I see where your coming from but didn’t work.

Like I said: code not guaranteed to work. And why did you not answer my questions:

We can’t help you when you provide us so little information about your problem.

I answer politely asked questions, not ones which are full of arrogance and malice, you know nothing about me, the fact I have been doing PHP for 6 weeks, the truth is I have been looking around and I didn’t find a straight forward tutorial.

I am sorry you took Zyppora as being full of arrogance and malice. We are just trying to get our posters to help themselves as much as we try to help them.

Anyway, are you still having a problem or did you get everything figured out?

For your information, I was neutrally requesting more information about your problem, in order to understand the issue better and come up with a better solution. Besides that, voicing my opinion is very much allowed in both my country and the country this forum is hosted in.

If you consider me arrogant, or malicious, then you may say so directly to my face. How I could ever appear malicious in my post is beyond me, but I think I have the right to be at least a little bit arrogant towards someone who requests my help but fails to read the Posting Guidelines, which clearly state:

[b]A problem defined is a problem solved.[/b] So please clearly state what you are tying to accomplish, the goals of your project, before posting. Please state your problem in clear, plain language. Community members are much more likely to answer if you carefully define and explain what it is you want to achieve before posting a question.

You slap up a few lines, trying to describe your problem. Where is the code that you’ve tried? Where are the error messages that you received? Is there anything you do not understand about the code, the error messages or something in the PHP manual? If you fail to provide us with sufficient information concerning your problem, you shouldn’t be surprised to get some questions in return. Not answering them, and on top of that, considering me malicious, makes me feel pretty dumb for wasting my time.

I think I showed my goodwill by posting not one, but three possible scripts that could help you out if you ever decided to put a little bit of effort into tweaking them to suit your needs. As I said, ‘code not guaranteed to work’. That pretty much means: ‘look it over and adapt it, because it will likely not do what you want it to do at first glance.’ Your reply shows to me that you’ve done nothing more than select - copy - paste - run - find out it didn’t work - discard. I find effort a very important part of anything, including becoming a PHP programmer, and you, sir, seem to lack it.

Ragster, there is no need whatsoever to apologize in my stead. I have done what I could, I inquired even though the threadstart was tiny and didn’t comply to the guidelines, but to be called malicious and arrogant is not only horribly mistaken, but tops the definition of hypocrisy if you ask me.

MrReed, I apologize in advance for any arrogant, malicious or any other form of negative undertone in my reply, as I aimed to compile it as neutrally as possible.

Sponsor our Newsletter | Privacy Policy | Terms of Service