The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> "Search" Though 900 entries, Quick link search
daviddavid
post Jun 6 2016, 06:07 PM
Post #1


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



Hello,
I am looking for the simplest way to have a search box that if someone types in the same text as listed it will go to a linked page that I have laid out.

For example,

Aba992aa

takes you to

566.html

while

BBb224bb

takes you to

380.html

I am trying to lay out and sort what pages are suppose to be returned at what time, however, the part that's making me really concerned is that when I lay it all out how can I get it in the page quickly and easily.

I don't want to have to send them a linked xls file that has hyperlinks to our log in pages on our website but I'm running out of ideas!

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 7 2016, 07:36 AM
Post #2


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



This is best done with a server-side script (e.g. PHP) rather than client-side javascript.

If there are just a few URLs you might use IF/ELSE conditions:

CODE
if($userinput=='Aba992aa')
{
    $url='566.html';
}
else if($userinput=='BBb224bb')
{
    $url='380.html';
}
else if(...)
...etc

If there's a match, redirect to the URL using the Location header: http://php.net/manual/en/function.header.php

But if there are many URLs, you could use an associative array to map each userinput/URL as a key/value pair instead of lots of IF/ELSEs:

CODE
$userinput_url=array(
    'Aba992aa'=>'566.html',
    'BBb224bb'=>'380.html',
);

Then use the foreach() function to compare each array key with the text the user submitted, and redirect with the Location header. See
http://php.net/manual/en/language.types.array.php
http://php.net/manual/en/control-structures.foreach.php

QUOTE
the part that's making me really concerned is that when I lay it all out how can I get it in the page quickly and easily.

Just let the search form submit to the PHP script (that can be a separate file with its own URL, as specified in the form's ACTION attribute).

QUOTE
I don't want to have to send them a linked xls file that has hyperlinks to our log in pages on our website

Is this intended as a kind of password login? Then it's better not redirect the user, since he could then share the URL with others. It's better to let the server-side script generate the entire protected content. You could also use HTTP authentication, see http://htmlhelp.com/faq/html/publish.html#password
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
daviddavid
post Jun 7 2016, 04:00 PM
Post #3


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



Ok the PHP array looks like a good way, but I want to keep it all as simple as possible.

I'm very intimidated by this!

I'm ok with generating the information in the array because I can use the concatinate functions of excel to put text, symbols and other things together to match the arrays syntax.

I'm reading the PHP links provided. I honestly don't even know how to program a form in php!

Do I need to enable php on the server side with the web host?


as for security the web host has everything in the directory password protected so it's ok if they get the link. It's kind of hokey but it works.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
daviddavid
post Jun 7 2016, 04:37 PM
Post #4


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



Ok I checked by running a hello world php page, the server in the secured mode does accept php.

It's ok if all the list is exposed to the end user as well in the source code of the page.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 7 2016, 04:46 PM
Post #5


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



QUOTE(daviddavid @ Jun 7 2016, 11:00 PM) *

I honestly don't even know how to program a form in php!

See http://php.net/manual/en/tutorial.forms.php

QUOTE
Do I need to enable php on the server side with the web host?

Most paid hosts offer it by default, but usually you need a .php extension on the files running PHP scripts (this can be changed).

QUOTE
as for security the web host has everything in the directory password protected so it's ok if they get the link. It's kind of hokey but it works.

Didn't understand that part, how can the user view the page if it's PW-protected? Note that I'm talking about the real pages, like www.yoursite.com/566.html.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
daviddavid
post Jun 7 2016, 06:19 PM
Post #6


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



The password protection seems to keep logged in for a while. The server has some feature I found in the control panel and enabled. It allowed me to protect a whole directory with a password. so if they type in yoursite.com/2294.html if they were logged in it will let them view it, if not they'll be prompted for a password.

I tried making a google sheet, and I was very excited about it, until I realized that they'll have to log in with a google account to type in my search box.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 7 2016, 08:16 PM
Post #7


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



QUOTE(daviddavid @ Jun 8 2016, 01:19 AM) *

The password protection seems to keep logged in for a while. The server has some feature I found in the control panel and enabled. It allowed me to protect a whole directory with a password. so if they type in yoursite.com/2294.html if they were logged in it will let them view it, if not they'll be prompted for a password.

That might be HTTP authentication. With that you'll stay logged in until the whole browser (not just the window or tab) is closed.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 8 2016, 02:29 PM
Post #8


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



Here's an example. I put both the PHP script, array and HTML form in the same file, but it's possible to include e.g. the array from a separate file to make things neater.

I strip all whitespace from the user input, so you can't use whitespace in the key codes. This feature can be removed.

The pages (566.html, etc) are assumed to be in the web root directory. If you want them somewhere else, the script must be modified a little.

CODE
<?php
// this script must be placed at the very top before ALL web page content, including whitespace.

$default='<h2>Enter code below.</h2>'; // default message when form is first loaded

$error='<h2>Wrong code, no match!</h2>'; // error message if wrong code is submitted

$url_list=array(
    'Aba992aa'=>'566.html',
    'BBb224bb'=>'380.html',
);


// --- nothing to configure below ---

$feedback=$default;

if(isset($_POST['userinput']) && trim($_POST['userinput'])!='') // check if non-empty form was submitted
{
    // strip all whitespace from user-submitted data
    $userinput=preg_replace('/\s/', '', $_POST['userinput']);

    // compare user input with array keys
    foreach ($url_list as $key => $value)
    {
        if($userinput===$key)
        {
            $url='//'.$_SERVER['HTTP_HOST'].'/'.$value;
            header("Location: $url"); // send redirect header to browser
            exit;
        }
    }
    $feedback=$error; // print error message if no redirection took place
}
?>
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>

<?php echo $feedback; // optional feedback message ?>

<form method="post">
<input type="text" name="userinput" value="BBb224bb">
<input type="submit" value="Send">
</form>

</body>
</html>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
daviddavid
post Jun 9 2016, 04:54 PM
Post #9


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



I just did a test with three entrees, it works great!

Excel won't let me put ' in a cell so, I simply put + because the php doesn't have any in it.
Then when I mix all the info together to make the aray all the spots that are ' are +

I then open the php file in notepad, do a replace + with '

I'm going to try to code about 200 of them today and see how it looks then put it in an iframe!

Thank you for this help, this is much better then any of the ideas I had had so far.

I'll be back to let people know how it's going. I'm posting this after getting simply a few in there to work!!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
daviddavid
post Jun 16 2016, 03:12 PM
Post #10


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



Ok after putting in a bunch of entries, Somehow, it seems to not find some of them in the list!



Attached File(s)
Attached File  List.php ( 37.34k ) Number of downloads: 250
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 16 2016, 03:38 PM
Post #11


Programming Fanatic
********

Group: Members
Posts: 1,638
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



How about posting a few keys that are not found.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 16 2016, 04:00 PM
Post #12


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



I can see several duplicates, at least from line 1013 and down.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 16 2016, 04:03 PM
Post #13


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



QUOTE(daviddavid @ Jun 16 2016, 10:12 PM) *

Ok after putting in a bunch of entries, Somehow, it seems to not find some of them in the list!

You mean the error message is printed when you submit an entry, even though it exists as an array key?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
daviddavid
post Jun 16 2016, 06:00 PM
Post #14


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



yes! it does the modified error string the serial number not entered

One thing to note is there IS some duplicates, and there not sorted, could that be something that causes trouble?
If not I won't mess with it. I've got many many more serial numbers to get in if I can!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 16 2016, 08:29 PM
Post #15


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



QUOTE(daviddavid @ Jun 17 2016, 01:00 AM) *

yes! it does the modified error string the serial number not entered

Could you give an example of such a code?

QUOTE
One thing to note is there IS some duplicates, and there not sorted, could that be something that causes trouble?

Sorting order shouldn't matter, but duplicate keys will be overwritten:

CODE
$test=array(
'a'=>'foo',
'a'=>'bar',
);

echo $test['a']; // "bar"

See the PHP manual's page on arrays for more examples.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
daviddavid
post Jun 17 2016, 10:44 AM
Post #16


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



I've deleted all duplicate keys. However, I'm still having trouble finding some of them which are in the list.

here it is live

http://godenovo.com/p/listedbeta.html

I had about 250 duplicates.

It's held in an iframe, Eventually when I publish it, I'm going to put it as the main page (or some other way to make it work) because clicking return to machine doesn't work because I coded in html to simulate the back button, since each page isn't categorized by machine.

I started doing that because sometimes rarely some brands are interchangeable.

I just tried serial number

86000144

which should take me to 355.html (in the p directory)

The list I attached shows + where ' should be because excel won't let me use ' which is fine because when I put it in php I simply do a find and replace all + with ' because the original php doesn't have + signs
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
daviddavid
post Jun 17 2016, 12:27 PM
Post #17


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



Should I try organizing my array in a different format like something like this?

Array
(
[0] => Array
(
[0] => Black Canyon City
[1] => Chandler
[2] => Flagstaff
[3] => Gilbert
[4] => Glendale
[5] => Globe
)

or that wouldn't help?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 17 2016, 02:22 PM
Post #18


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



QUOTE(daviddavid @ Jun 17 2016, 05:44 PM) *

I just tried serial number

86000144

which should take me to 355.html (in the p directory)

Try changing

CODE
if($userinput===$key)

to

CODE
if($userinput==$key)

(with a == instead of ===).

Longer answer: it seems integer keys are type cast as integers even if the integers are quoted, as explained on http://php.net/manual/en/language.types.array.php :

Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand "08" will not be cast, as it isn't a valid decimal integer.
Floats are also cast to integers, which means that the fractional part will be truncated. E.g. the key 8.7 will actually be stored under 8.

So my script didn't work because I used a === comparison operator, which compares both value and type. But form data is always considered to be of string type, so the string $userinput could never be identical with the integer $key, even if they have the same value.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
daviddavid
post Jun 17 2016, 05:38 PM
Post #19


Newbie
*

Group: Members
Posts: 10
Joined: 6-June 16
Member No.: 24,302



That seemed to do it! Now I'm designing the page with that php form in it, I only tested it on a few but it's working much better. I can't wait to keep testing it next week!

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 17 2016, 06:17 PM
Post #20


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



Good! Let me know if any more issues show up.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 20th August 2019 - 03:41 PM