Jump to content

PHP Search Alphabetically By Letter


bnickles1961

Recommended Posts

Hi, I am gonna try and explain this as clear and as best I can relating to what I want to do. I run an internet radio station (Legal) I use SAM Broadcaster. It has (2) search functions a search box where you type in text to search for an artist and the other uses character search letters A-Z. What I want to do is this. The first option (search box) if you type in a single letter....A, B, C etc the search returns everything based on the letter you type into the search box, but the character letters return a search of ONLY the letter you type in, if you click the letter A it returns ONLY artists that begin with A type in B and it returns ONLY artists that start with B , etc. Below is the code for the search box option:

<div id="search">
			<form method="get" action="playlist.php" name="searchParameters">
			<!--Search: <?php InputText('search', $search, '',20); ?>-->
			<!--<input type="submit" value="Go" name="B1"/>-->
			<!-- Display <?php InputCombo('limit', $limit, 25, '5,10,25,50,100', "", "document.forms.searchParameters.submit();"); ?> results--> 

What I want to do is either convert the above code to work like the character button search:

<table>
					<tbody>
						<tr>
							<td>
							
		

								<input type="submit" name="character" class="characterButton" value="All" onclick="document.forms.searchParameters.search.value=''"/>
							</td>
							<td>
								<input <?php echo "0 - 9" == $character? "id='activeCharacter'" : "";?> type="submit" name="character" class="characerButton"value='0 - 9'/>
							</td>

							<?php
							for($charVal = ord('A');$charVal <= ord('Z'); $charVal++) {
								$c = chr($charVal);
								echo "<td>";
								echo "<input ".($character == $c? "id='activeCharacter'" : "")." type='submit' name='character' class='characterButton' value='$c' onclick='document.forms.searchParameters.search.value=\"\"' />";
								echo "</td>";
							}
							?>
						</tr>
					</tbody>
				</table> 

I would like to have it where in  search box, if you type in A it returns ONLY artists that start with A and if you type in B it returns ONLY aretist that start with B. Or simply edit the search character letters code (2nd code I listed) to work as a search box. Hope I explained it clear lol and sorry if I did not input the codes correctly, I am not really sure about code tags on suppor forums. Thanks in advance

 

Link to comment
Share on other sites

<div id="search">
			<form method="get" action="playlist.php" name="character">
			Search: <?php InputText('search', $search, '',20); ?>
			<<input type="submit"  value="search" name="B1"/>
			< Display <?php InputCombo('limit', $limit, 25, '5,10,25,50,100', "", "document.forms.searchParameters.submit();"); ?> results

I want to modify the above code to work like this code:

<table>
					<tbody>
						<tr>
							<td>
							
		

								<input type="submit" name="character" class="characterButton" value="All" onclick="document.forms.searchParameters.search.value=''"/>
							</td>
							<td>
								<input <?php echo "0 - 9" == $character? "id='activeCharacter'" : "";?> type="submit" name="character" class="characerButton"value='0 - 9'/>
							</td>

							<?php
							for($charVal = ord('A');$charVal <= ord('Z'); $charVal++) {
								$c = chr($charVal);
								echo "<td>";
								echo "<input ".($character == $c? "id='activeCharacter'" : "")." type='submit' name='character' class='characterButton' value='$c' onclick='document.forms.searchParameters.search.value=\"\"' />";
								echo "</td>";
							}
							?>
						</tr>
					</tbody>
				</table>

The bottom code is a search by characterbutton I want the top code (searchbox) to work like the characterbutton search where if you type in an artist that starts with "A" it only returns artists that start with the letter "A" type in the letter "B" it olnly returns artists that start with "B" etc. 

Link to comment
Share on other sites

The way it is now, if you type a letter in the search box, it returns everything that contains the letter you typed in but the character search:

 

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

 

what ever letter you click returns Only artists from the letter you click, I want the search box to do the same so I just want to convert the search box into the characterletter so it will work the same if it is possible??

Link to comment
Share on other sites

As far as I can tell, that isn't the code which performs the search. I imagine that the code is found within the InputText() function. Or maybe the actual search happens within PHP and then the page gets re-displayed. It's difficult to know what's happening with what has been shown so far.

Link to comment
Share on other sites

The way it is now, if you type a letter in the search box, it returns everything that contains the letter you typed in but the character search:

 

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

 

what ever letter you click returns Only artists from the letter you click, I want the search box to do the same so I just want to convert the search box into the characterletter so it will work the same if it is possible??

 

Does the regular search box work as you want it to? In other words, if you type the letter A in the search box, does it return the artists that start with A. Or do you get a list like:

  • Alice in Chains
  • Aerosmith
  • Jane's Addiction
  • ...
Edited by cyberRobot
Link to comment
Share on other sites

As I understand the current functionality: There is currently a text input field that does a search of any artists which contain the search term. E.g. if you type in "smith" it would return both "Smithereens" and "Aerosmith". There is also a 'rolodex' search feature that allows the user to click a letter and see all the artists whose names begin with that letter.

 

The issue (I believe) is that if the user enters a single letter in the search field, it is (as by design) returning all artists which contain that letter. E.g. enter the letter "a" an it might return results such as "Aerosmith", "Robert Plant", "Madonna", etc. If I am understanding the OP correctly, he wants the search field to work the same as selecting a letter when the user only uses a single letter in the search field.

 

My guess is that there are different 'search' functions used for the search field vs. the letter selection. Two ways that I can think of implementing this are as follows:

 

1. Inspect the current back-end logic to determine the two processes used. For the search functionality, add a check to see if a single letter was entered. If so, redirect the functionality to the process that handles the letter selection. This would be the "best" solution, but requires you to be able to read and understand the logic as well as to know how to implement this change.

 

2. Add some JavaScript logic to the submit trigger for the search field. Same as above, check to see if a single letter was entered and, if so, call the same action as when a letter is selected. This would likely be easier to implement, but relies on client-side code. Not the best solution, IMO, but a workable one.

Link to comment
Share on other sites

Yes that is exactally what is happening when I do a search with the search box How would I implement the 2 options you were talking about? I have no expeirence in this kind of coding.

 

I already explained "how" from a very general standpoint. If you want details, then you need to provide the specific code where the functionality takes place. The code you provided only creates the HTML form data. To implement #1 requires the server-side code that is called for those two processes. To implement #2 requires the actual code that is generated from the above code that you provided.

 

In either case, someone with sufficient knowledge needs to review the relevant code and then determine (specifically) how to implement. There may be someone here that is generous enough to do that work for free, but it's not me. I was only trying to provide a better explanation of what you were requesting as it seemed there was some confusion.

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.