Solved

Need help with search scripting

Posted on 2006-11-11
124
365 Views
Last Modified: 2013-12-12
I am new to this community. I am a web designer and a friend of mine and I have a server and manage websites (mostly ours but also a few clients). I manage the sites and he does the database management. My friend, an expert at javascript and java programming, is burning out on programming and he doesn't want to do it anymore. I'm stuck, on my own.

So ... now I have to learn PHP (can't use CGI) and database management. I have no problem accessing the database and managing records, and I have no problem connecting to the database with scripts, but I am just learning how to query and return results.

I have been pulling my hair out for a week trying to figure out the following:

I have three independent searches on one page. Each search was designed tol call a separate page. On this same page, there are two text searches, one specific and one open. I need to be able to have success at the simplest text search (open) first before I can move on to the other text search and the drop down menu search.

My first query needs to result in three fields being extracted from the database table. In this case it is town, number, and sub_number. The results need to return on a page in rows (unlimited) but each row hyperlinked. These hyperlinks will be links to internal HTML pages. That's it. I just need to know the proper query syntax and code. If I can make this work, then I will have a better understanding about how to progress further, especially trying to succeed with the other searches on the page.   Do I need to use a parse.php page, or is it better just to have the database connection info on each page.

In any case, I have been working an entire week testing scripts and wasting lots of time and getting frustrated.  Desperate for help.  Thanks in advance.
0
Comment
Question by:theram
  • 68
  • 50
  • 4
124 Comments
 
LVL 27

Expert Comment

by:yodercm
ID: 17921067
Well, here is a very simple example of what you seem to be asking for.  It might not be the full answer, but feel free to ask more.


First the query to your database to get every row should be a simple one (after you set up the mysql connection):

$query = 'SELECT Town, Number, SubNumber FROM Table';
$result = mysql=query($query);


Now you can process the result set in a loop, with each row becoming a link to a new page:

do while ($row = mysql_fetch_array($result))
{
// process each row here
}


Within that loop, you process each row from the database to generate a link based on it like this:

do while ($row = mysql_fetch_array($result))
{
  $town=$row["Town"];
  $number=$row["Number"];
  $subnumber = $row["SubNumber"];
  echo "<a href='the url for the row'>$town $number $subnumber</a>";
}


The url can contain information such as this:

    href='http://process.php?town=$town&number=$number&subnumber=$subnumber'

but if you do this, be sure to pass each $_GET variable in process.php through the php function htmlentities( ) like this:

   $town = htmlentities($GET['town'], ENT_QUOTES);

to protect yourself against mysql injection hacking.


That's a basic outline of how to do what you described.  

There are some good online manuals if you want to look up any of these things:

http://www.htmlhelp.com/reference/html40/

http://www.php.net/manual/en/

http://dev.mysql.com/doc/refman/5.0/en/

and a little writeup on MySQL Injection at
http://www.governmentsecurity.org/articles/SQLInjectionModesofAttackDefenceandWhyItMatters.php


If this doesn't cover what you need to get started, feel free to ask more.  Good luck.
0
 
LVL 19

Assisted Solution

by:VoteyDisciple
VoteyDisciple earned 50 total points
ID: 17921068
<?php
require_once('connect.php');

$query = 'SELECT town, number, sub_number'
. ' FROM your_table'
// . ' WHERE '  // This is where you'd specify your search conditions in SQL
;

$results = mysql_query($query);

echo '<table id="results">' . "\n";
while ($row = mysql_fetch_assoc($results)) {
    echo "<tr>\n";
    echo '<td class="town"><a href="whatever.html">' . $row['town'] . '</a></td>' . "\n";
    echo '<td class="number">' . $row['number'] . '</td>' . "\n";
    echo '<td class="sub_number">' . $row['sub_number'] . '</td>' . "\n";
    echo "</tr>\n";
}
?>

</table>



Here connect.php would perform the database connection.  Definitely don't replicate that in every page.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17921070
$result = mysql=query($query);  should of course be $result = mysql_query($query);
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17921102
and

$town = htmlentities($GET['town'], ENT_QUOTES);

should be

$town = htmlentities($_GET['town'], ENT_QUOTES);

Heh heh, I really did proof-read this first :)
0
 

Author Comment

by:theram
ID: 17922284
Trying out yodercm script first.

Getting error:  

Parse error: parse error, unexpected T_DO, expecting T_WHILE in ..... on line 12

=================================================

Also, what would be the best way to set up the form for this text search?

I have:

<TABLE cellSpacing=2 cellPadding=0 width=540 border=0>
  <TBODY>
  <TR>
    <TD align=right width=190 bgColor=#ffffff><FONT
      face="verdana,arial,helvetica,sans serif" color=#840000 size=2><b>Search by
      Word String</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT> </TD>
    <TD align=left width=350 bgColor=#ffffff><FONT
      face="verdana,arial,helvetica,sans serif" color=#004000 size=3><INPUT
      maxLength=40 size=35 type="text" name="search"> &nbsp;&nbsp;&nbsp; <INPUT type=submit value=Search!>
</FONT></TD></TR></TBODY></TABLE></FORM>
0
 

Author Comment

by:theram
ID: 17922291
Sorry, forgot the first line.  Also, is it "get" or "post" to use from one page to another?

<FORM action="search3.php" method="post">
<TABLE cellSpacing=2 cellPadding=0 width=540 border=0>
  <TBODY>
  <TR>
    <TD align=right width=190 bgColor=#ffffff><FONT
      face="verdana,arial,helvetica,sans serif" color=#840000 size=2><b>Search by
      Word String</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT> </TD>
    <TD align=left width=350 bgColor=#ffffff><FONT
      face="verdana,arial,helvetica,sans serif" color=#004000 size=3><INPUT
      maxLength=40 size=35 type="text" name="search"> &nbsp;&nbsp;&nbsp; <INPUT type=submit value=Search!>
</FONT></TD></TR></TBODY></TABLE></FORM>
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17922386
A good rule of thumb is to use "post" for requests that will change things.  For example, if I submit a form that creates a new user account, that should be posted.  Use "get" for pages where you want the same URL to produce (essentially) the same results every time.

This is definitely a case for the latter: if somebody performs a search and bookmarks the results, you want that bookmark to call up the same search, so you'd definitely use "get" there.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17922458
Sorry, you don't need the DO.  It's just

while ($row = mysql_fetch_array($result))
{
// process each row here
}


If you are sending data from a user via a FORM, then the FORM statement will say method=POST and you will use $_POST to get the data in the processing script.

If you are sending data from a user via a URL, then you will use $_GET to get the data in the processing script.
0
 

Author Comment

by:theram
ID: 17922515
Sorry, but I am going nuts here.  Can one of you give me the final script (with $_POST or $_GET)?  I am getting the two solutions mixed up and nothing is working.

Is my form correct?  Should it be post or get?  The user is simply typing in the name of a town.  The form is tabled on a page with two other searches.  I have a separate connect.php being called: require_once('connect.php'); so this seems fine.  Please help. Shorted myself on sleep to get back to you to figure this out.  Must solve this soon.  Thanks!
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17922658
I didn't check all the syntax of your form, but you should be able to do that by using it in a test webpage script.

You should use method=POST in the form statement, and then use

$userinput = htmlentities($_POST['search'],ENT_QUOTES);

in the processing script (search3.php in your above code) where the 'search' is the name=search in your form.


Here it is in a nutshell the methodology you need to use.

In the screen script, use what you have posted above, subject to testing it by making a test screen and see if it contains and is formatted as you want.

When the user clicks the Submit button, control passes to the processing script, and the value the user entered in the INPUT text box will be passed automatically in the $_POST system array.

In the processing script (search3.php), start by retrieving the user input value as I show just above using $_POST and pass it through the function htmlentites to guard against hacking input.  Then you can use the variable $userinput in whatever way you need to in the rest of the script.


Your original question said you wanted to use hyperlinks.  That would be when you used $_GET for data passed via a URL, but that is totally different than using a FORM, so if you want to do this with a FORM as you have posted in the above code, then forget all about $_GET.
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17922679
I don't mean to add confusion, as either "get" or "post" will certainly WORK.  All that matters to get it functional is that if you've set the method to "get" in your form then you'll use $_GET in your script, and if you've set the method to "post" in your form then you'll use $_POST.  They have to match is all that matters.


I do want to stress, however, that for a search form "get" is technically the more correct method.  This is NOT purely limited to hyperlinks, though that's certainly one place we commonly see the "get" method employed.  It's just as applicable to a form, and the same rules apply.

For a more technical discussion, you might refer to ( http://www.cs.tut.fi/~jkorpela/forms/methods.html ).
0
 

Author Comment

by:theram
ID: 17922700
yodercm,

Does this code look correct?

<?php
require_once('connect.php');

$query = 'SELECT Town, Number, SubNumber FROM Table';
$result = mysql=query($query);
$userinput = htmlentities($_POST['town'],ENT_QUOTES);

while ($row = mysql_fetch_array($result))
{
// process each row here
}

while ($row = mysql_fetch_array($result))
{
  $town=$row["Town"];
  $number=$row["Number"];
  $subnumber = $row["SubNumber"];
  echo "<a href='the url for the row'>$town $number $subnumber</a>";
}

?>


Also, I have been getting fetch errors while testing the scripts:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in ...

Why would this happen?

Thanks!
0
 

Author Comment

by:theram
ID: 17922729
VoteyDisciple,

Thanks for the advice and link.  Have you any recommended final script code for me.  Still having problems.  Getting pretty frustrated.  Just want some final code to test.
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17922736
Looking at the code you posted most recently you've got two loops trying to do the same thing (loop through all rows found by the query).  You can't do that twice though; once fetched, a row "can't" (basically) be fetched again.

Get rid of the first row and you should be okay:

<?php
require_once('connect.php');

$query = 'SELECT Town, Number, SubNumber FROM Table';
$result = mysql=query($query);
$userinput = htmlentities($_POST['town'],ENT_QUOTES);

while ($row = mysql_fetch_array($result))
{
  $town=$row["Town"];
  $number=$row["Number"];
  $subnumber = $row["SubNumber"];
  echo "<a href='the url for the row'>$town $number $subnumber</a>";
}

?>
0
 

Author Comment

by:theram
ID: 17922748
I keep getting this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ...

Why?
0
 
LVL 27

Accepted Solution

by:
yodercm earned 350 total points
ID: 17922749
<?php
require_once('connect.php');

$query = 'SELECT Town, Number, SubNumber FROM Table';
$result = mysql=query($query);   <<<<<<<<<<<<<<<<<<<<As I pointed out in a later post, mysql_query.
$userinput = htmlentities($_POST['town'],ENT_QUOTES);

while ($row = mysql_fetch_array($result))
{
// process each row here
}
>>>>> The above 4 lines are just example with a comment to show you the loop.  The following lines are the correct processing of the rows.  By leaving the above 4 lines in, you have already looped through the result array, and so there was nothing left to process when the actual processing in the below lines is run.  That is why you are getting the Warning error.


while ($row = mysql_fetch_array($result))
{
  $town=$row["Town"];
  $number=$row["Number"];
  $subnumber = $row["SubNumber"];
  echo "<a href='the url for the row'>$town $number $subnumber</a>";
}

?>

The echo statement <a href= etc ...> should be replaced by your form.  href is the method of using hyperlinks, not FORMs.  You need to put your FORM code in place of it.  An easier way than echo for long html strings is to drop out of php, create the html and then back into php.  This is what I have done below.

Here is approximately correct code for your screen display script.  Make sure you are using the correct Table name in the script.  "Table" should be your actual MySQL table name, and the fields should be the correct field names from that table.

<?php
require_once('connect.php');

$query = 'SELECT Town, Number, SubNumber FROM Table';
$result = mysql_query($query);
$userinput = htmlentities($_POST['town'],ENT_QUOTES);

while ($row = mysql_fetch_array($result))
{
  $town=$row["Town"];
  $number=$row["Number"];
  $subnumber = $row["SubNumber"];
 // leave php and write html form  
  ?>

  <FORM action="search3.php" method="post">
  <TABLE cellSpacing=2 cellPadding=0 width=540 border=0>
  <TBODY>
  <TR>
    <TD align=right width=190 bgColor=#ffffff>
        <FONT face="verdana,arial,helvetica,sans serif" color=#840000 size=2>
        <b>Search by Word String</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </FONT> </TD>
    <TD align=left width=350 bgColor=#ffffff>
        <FONT face="verdana,arial,helvetica,sans serif" color=#004000 size=3>
        <INPUT maxLength=40 size=35 type="text" name="search"> &nbsp;&nbsp;&nbsp;
        <INPUT type=submit value='Search!'>
        </FONT></TD>
    </TR>
  </TBODY>
  </TABLE>
  </FORM>

  <?php
  // return to php mode
}

?>


The other thing that concerns me is that you are retrieving values from the database, but not using them.  Instead you are letting the user type in the text name as input.  Why do you need to get values from the database?  Should these values be used in a dropdown list, instead of allowing the user to type them in?
0
 

Author Comment

by:theram
ID: 17922774
No.  The names (not including sub variations) amount to 1440.  I have split them into drop down tables as one search (which I will work on later).  The other text search is by the actual "Number" and then the third search is by "Town" (the one we are working on).  I just want to offer all three options.

Going to test the above script now.
0
 

Author Comment

by:theram
ID: 17922831
Still getting the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

I am placing the php code on a page called search3.php and the form code is the third table on search.php (main search page).

Do you realize that the form is on a separate page (search.php) and search3.php is the page referred for the results of the word string search?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17922904
<?php
require_once('connect.php');

$query = 'SELECT Town, Number, SubNumber FROM Table';
$result = mysql_query($query);
$userinput = htmlentities($_POST['town'],ENT_QUOTES);  <<<<<< GET RID OF THIS LINE, it belongs in search3.php

while ($row = mysql_fetch_array($result))
{
  $town=$row["Town"];
  $number=$row["Number"];
  $subnumber = $row["SubNumber"];
 // leave php and write html form  
  ?>

  <FORM action="search3.php" method="post">
  <TABLE cellSpacing=2 cellPadding=0 width=540 border=0>
  <TBODY>
  <TR>
    <TD align=right width=190 bgColor=#ffffff>
        <FONT face="verdana,arial,helvetica,sans serif" color=#840000 size=2>
        <b>Search by Word String</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </FONT> </TD>
    <TD align=left width=350 bgColor=#ffffff>
        <FONT face="verdana,arial,helvetica,sans serif" color=#004000 size=3>
        <INPUT maxLength=40 size=35 type="text" name="search"> &nbsp;&nbsp;&nbsp;
        <INPUT type=submit value='Search!'>
        </FONT></TD>
    </TR>
  </TBODY>
  </TABLE>
  </FORM>

  <?php
  // return to php mode
}

?>


Follow the query with an echo to see what the error really is:


$result = mysql_query($query);
echo mysql_error( );
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17922972
Theram, take a deep breath and slow down.  You're even confusing me with what you are trying to do, and I cannot give you advice when you change what it is that you want.  Also, no one can 'give you finished code to test' without full access to your database and server.

YOU have to learn this, understand it yourself.  I will answer your questions and tell you the general approach to use, but you have to do your part.

So, one more time, let me explain the general methodology.

You will have two different scripts.  The first one I'll call the screen script, and in it you will display the user input forms in your table or however you want it to look.  The second one is the processing script, and in it you will retrieve the user's input and process it however you want.

The screen script:

1.  Retrieve whatever information you need from your MySQL database using mysql_query.  If you need help in formulating a query, first look at your database tables carefully, then read the manual I posted above on SELECT.

2.  Create the html tables and FORMs and user INPUT statements.  For this, you will use html similar to what you posted above, and incorporate any data from the mysql query that you need.  You will also want to understand my example of switching in and out of php, because you will want to use php variables in html statements.

The processing script:

1.  Retrieve the user inputs using the $_POST method I showed you.

2.  Do whatever processing you need to do with the user input values.

3.  Redisplay the screen script.

NOW, sort out the different pieces to this and understand how each one works, and THEN go back and write some code based on the examples you have been given by me and by voteydisciple.  When you have done that, you will be able to ask more specific questions and then we might be able to help you more.

Good luck.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17922980
Also, when I replaced the echo statement with your FORM html, that was a mistake.  You don't want to create a table for each row of your database result.  You (and subsequently I) have mixed up the simple processing of each row of the table with creating a user text input form.

So just start over and follow the recipe I gave you just above.

My guess on your mysql error is that you haven't replaced 'Table' with your actual table name, or the field names with the correct names from your database table.  Am I right?
0
 

Author Comment

by:theram
ID: 17923025
yodercm

Okay, here's what has been happening...

First, my table word in connect.php had two letters mixed up.  Fixed that.  Next time I will use that echo error syntax to check.

Secondly, tried out VoteyDisciple's script and it returned the hyperlinks, except that when I plugged in a town name beginning with "A" it returned ALL the towns that start with "A" -- which is not what I want.  I want only the town that is entered by the user.

Third, your script returned a blank page.  Should I put the PHP script on both the main page and the results page (search3.php)?

We are almost there.  Sorry about the delay with the table mistake.
0
 

Author Comment

by:theram
ID: 17923063
VoteyDisciple,

Any way to fix that output to restrict it to only the text (town) that is typed?  No town is less than 4 letters long.

Thank you?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17923070
I never gave you a script, only example code.  If you are talking about the table processing while loop, then see my above post about the FORM should not be in the loop.

However, now you are back to wanting hyperlinks.  Which do you want, hyperlinks or forms?  Votey's code does exactly the same as my original echo statement in the while loop did, but I thought now you want to use a form rather than hyperlinks.  

PLEASE be more exact about what you want, otherwise we are going to continue going around in circles.  Can you lay out a simple statement like pseudo code of what you want your scripts to do?
0
 

Author Comment

by:theram
ID: 17923127
Okay, here's what I wanted:

First, I have a search page with three independent searches.  It is a currency search from a database populated with town names and corresponding catalog numbers.  Each search calls a different php page.

The most simple search is the text search for a town and can produce multiple results.  That is the third form on my page.  The second search searches for a number -- a more specific search.  The first search has drop down menus that will either be populated by hard code or be called from the database.

Each search produces a page with hyperlinks to specific HTML pages I will have in a directory.

So what I wanted to work on first was the simplest form search -- by town.  I'll work on the others after I get this one done.

That's it.  Simple text search on a master page for a town that produces links on another page.

0
 

Author Comment

by:theram
ID: 17923336
VoteyDisciple or yodercm,

The script is working except the limit to the exact text.  Almost there.  Can you help?

Thank you.
0
 

Author Comment

by:theram
ID: 17923347
Think I may have it.

 $query = "select * from search WHERE town='$search'";

Let me know.  Ready to close.  But first, where does the additional code go to format/align a table in case I want to do this?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17923372
OK, let's take the user-specified town case first.

screen script:

1. No database query needed.  Just create the FORM pretty much as you showed before, user enters town name and clicks the Submit button.

processing script:

1. Get the user input from $_POST as I showed.

Next step:  Do you need anything from the database about the town?  If so, is there guaranteed to be just one town by that name in the database?  If more than one, how will you process the multiple rows?  What happens if a user misspells the town or enters something that doesn't exist?

Answer these, and I'll give you the next step.

0
 

Author Comment

by:theram
ID: 17923610
yodercm

Okay, back.

First, regarding my request for formatting tables -- I can try to find some code to either call a .css template or I will install a style sheet into the output page.  Do you think this is better than simple HTML formatting?

Now, to answer your question ... Yes, there are some town names with multiple entries, mainly because there are some distinct currencies for some towns.  There are also sub-variations.  However, I was mainly going to deal with that via HTML pages that will link to sub-variant pages.

Actually, the output seems to be following in order by either the id key or the sub-variant

Example output now:  

Altheide       L27
Altheide       L27.1
Altheide       L27.2

These are linked and will call distinct separate HTML pages.  What I need now is a bit of code for this script that will  return an error message and a back link or new search link.


=================================================

My next project is to create another search result page for the second form search that deals with the specific L number.  The number ranges from 1 to 1440 and can return variants as above  I am guessing that it will require basically copying the search3.php that we created and inserting some additional code.  Should I create a new question for this or should we continue on after the above solution is found?  Thank you.

0
 

Author Comment

by:theram
ID: 17923661
yodercm

Well, I figured out the second search.  Just need error code and return.

Last project is the drop down menus after that.  Feeling like I actually accomplished something today.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17923706
OK, then after getting the user input value into $search, you need to access the table:

First set up the html table for your output page with the hyperlinks:

?>
<table>
<tr><th>This is the table containing the links</th></tr>
<?

Now query the database and for each matching town, put out a table row with the link in it.

$query = "SELECT * FROM Table WHERE Town='$search'";
$result =  mysql_query($query);
echo mysql_error();
if (mysql_num_rows($result) <= 0)
{
  // in here you will put the code to handle a town that doesn't exist in the database if needed
}
while ($row = mysql_fetch_array($result))
{
  $town=$row["Town"];   //<<<<< or whatever the correct field names are for Town, Number, SubNumber
  $number=$row["Number"];
  $subnumber=$row["SubNumber"];
  $hyperlink="This is a link to $town..... ";  //<<<<< construct the link url that you need here
  echo "<tr><td>$hyperlink</td></tr>";  //<<<<<< echo the link url to the output table row
}

echo "</table>";

After this, you can do your mysql_close on the connection and exit, or whatever else you need.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17923710
On CSS:  YES!  Absolutely CSS is the way to go.  Use a separate CSS file that you load in the beginning of each script that creates an output screen.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17923724
Here's how you do a dropdown list from the database rows:
?>
<form method=post action="process script goes here">
<select name='usertown'>
<?

$query = "SELECT * FROM Table";
$result =  mysql_query($query);
echo mysql_error();

while ($row = mysql_fetch_array($result))
{
  $town=$row["Town"];   //<<<<< or whatever the correct field names is for Town
  echo "<option value=$town>$town</option>";  //<<<<<< echo the link url to the output table row
}

?>
</select>
</form>
<?



In the processing script, you will do similarly as before to get the selected value:

$usertown=htmlentities($_POST["usertown"], ENT_QUOTES);
0
 

Author Comment

by:theram
ID: 17923736
Is this the proper heading for the start of the code?

<?php
require_once('connect.php');
?>
<table>
<tr><th>This is the table containing the links</th></tr>
<? ....etc.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17923797
Yes.  

Any time you are using php, you start with <?

When you want to change to raw html, just shut the php with ?>

If you want to echo a php variable inside raw html, just enclose it with <?  ?>,
for example:

<TD>This is a town name -- <? echo $townname; ?> </TD>

If you want to output a quick short html, you can do it directly in php with

echo "<TD>This is a town name -- $townname</TD>";

I usually use the echo for short html with php variables in it, and switch out of php to html for longer stuff like setting up an entire table.
0
 

Author Comment

by:theram
ID: 17923881
Do the html and body tags go in a php page?  Do I put the stylesheet/css like this:


<link rel="stylesheet" href="search.css" >
<center>
<body class="search_body" style="margin:0">
<TABLE BGCOLOR="#FFFFFF" BORDER=1 CELLPADDING=2 CELLSPACING=0 width=640>

or this way

<html>
<head>
<link rel="stylesheet" href="search.css" >
<title>Site Search</title>
</head>
<body class="search_body" style="margin:0">
<center>
<TABLE BGCOLOR="#FFFFFF" BORDER=1 CELLPADDING=2 CELLSPACING=0 width=640>

Thank you!
0
 

Author Comment

by:theram
ID: 17923921
The dropdown menus are going to be a big challenge because I may want to populate it from the database.  But, for now, I am very happy about the other two searches.

One last thing for tonight:

My hyperlinks are not working now with the table script

Before, the syntax was:  

echo '<td class="town"><a href="whatever.html">' . $row['town'] . '</a></td>' . "\n";

Now it :

$hyperlink="This is a link to $town  ";  //<<<<< construct the link url that you need here

How do I construct the link URL for the new line?
0
 

Author Comment

by:theram
ID: 17924039
yodercm

Just need to know how to make that hyperlink work.  Right now it only returns text.  Thanks!
0
 

Author Comment

by:theram
ID: 17924052
I keep figuring things out from other pages here at the Exchange.  Got that one answered.

I think I can close this out soon and give points, but maybe you can suggest first how to populate seven drop down menus with selections from the database.  Just town and number are the two fields.  That's my last question.  I would rather not have all the selections hard coded into the menus because it probably requires much more memory/resources than calling the fields from the database.  What do you think?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924068
If the town name is 'abcd', then what exactly do you want the hyperlink to be?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924085
You do a dropdown list from the database in the way I showed you in the post that starts --

Here's how you do a dropdown list from the database rows:
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924090
<head>
<link rel='stylesheet' type='text/css' href='your css script name goes here'>
0
 

Author Comment

by:theram
ID: 17924096
Do you actually put the PHP code on the main search page with the drop down menus and the other two text searches?

Here's a sample table -- there are seven lined up on top of each other:

<TABLE cellspacing=2 celpadding=5 width=600 border=0>
  <TBODY>
  <TR>
  <FORM action="search1.php" method="post">
    <input type="hidden" name="usertown" value="group">
    <TD align=middle width=110 bgColor=#840000><FONT
      face="verdana,helvetica,sans serif" color=#ffffff
      size=4><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;1-200&nbsp;&nbsp;&nbsp;&nbsp;</STRONG></FONT> </TD>
    <TD align=left width=425 bgColor=#840000><FONT
      face="verdana,arial,helvetica,sans serif" size=2>
      <SELECT name='usertown'>
      <OPTION value="Aachen" selected>Aachen (L1)
      <OPTION value="Achim">Achim (L2)
      <OPTION value="Ahaus">Ahaus (L3)
      <OPTION value="Ahaus">Ahaus (L3.1)
      <OPTION value="Ahaus">Ahaus (L3.2)
      <OPTION value="Ahaus">Ahaus (L3.3)
      <OPTION value="Ahlbeck">Ahlbeck (L4)
      <OPTION value="Ahlbeck">Ahlbeck (L4.1)
      <OPTION value="Ahlbeck">Ahlbeck (L4.2)
      <OPTION value="Ahlen">Ahlen (L5)</OPTION></SELECT>
      </FONT></TD>
    <TD align=right width=100><FONT face="verdana,arial,helvetica,sans serif"
      size=2><INPUT type=submit value=Search!>
</FONT></TD></FORM></TR></TBODY></TABLE>

0
 

Author Comment

by:theram
ID: 17924104
<head>
<link rel='stylesheet' type='text/css' href='your css script name goes here'>

so, no <html> or <body> tags?

======================================

Also, is this the proper way to close the page out?

}

echo "</table></center>";

?>

0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924147
<OPTION value="Ahaus">Ahaus (L3.2)
 Where do these names and numbers come from?  The database?  If so, then you can just query and retrieve the values into variables like you did the town name.  Then construct the option by

echo "<OPTION value=$townname>$townname (L$number.$subnumber)</OPTION>";

Note: I'm not sure if that . will be considered concatenation in this statement, but if so, then you can use

echo "<OPTION value=$townname>$townname (L".$number.".".$subnumber.")</OPTION>";

0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924153
Yes, use the normal html tags for the script.  I just was indicating that the stylesheet line goes in the <HEAD> section.


End your script with

closing the table, closing the database connection, and exit.

echo "</table></center>";
mysql_close();     //<<<<<< you should look this up in the mysql manual and make it match the connection you used
exit();
?>
0
 

Author Comment

by:theram
ID: 17924265
Have a question.  Is it really necessary to close the connection each time?  The access to the database is not open to the general public.  It will require a general username/pass to access this database search.

I am trying to figure out why my back link and bottom table is disappearing after the closing syntax.  Have to figure out how to place the bottom of the table in the echo area.

=========================================================

The names and numbers come from the database.  I don't know exactly how to query the database to populate the menu, but here is the first attempt from a friend of mine:

<TABLE cellSpacing=2 cellPadding=3 width=600 border=0>
  <TBODY>
  <TR>
  <FORM action="results.do" method="post">
    <input type="hidden" name="method" value="group">
    <TD align=middle width=110 bgColor=#840000><FONT
      face="verdana,helvetica,sans serif" color=#ffffff
      size=4><STRONG>1-200</STRONG></FONT> </TD>
    <TD align=left width=425 bgColor=#840000><FONT
      face="verdana,arial,helvetica,sans serif" size=2>
      <SELECT name="number">
        <c:forEach items="${search1}" var="searchItem">
              <OPTION value="${searchItem.number}">${searchItem.town} (${searchItem.number})
        </c:forEach>
        </SELECT>
      </FONT></TD>
    <TD align=right width=100><FONT face="verdana,arial,helvetica,sans serif"
      size=2><INPUT type=submit value=Search!>
</FONT></TD></FORM></TR></TBODY></TABLE>

Can you make sense of this?
0
 

Author Comment

by:theram
ID: 17924282
Fixed the closing problem.  Now all that is remaining is the drop-down menu situation and then it is finished.
0
 

Author Comment

by:theram
ID: 17924596
The final and big challenge now is the drop down search.  Have to find a way to populate those tables on the main page as soon as the page is opened.  Please advise.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924821
>>>>Have a question.  Is it really necessary to close the connection each time?  The access to the database is not open to the general public.  It will require a general username/pass to access this database search.

This is not the reason you close it.  MySQL allows a limited number of connections at a time, and if you leave them open until they close by default (not sure how long they persist), and have a high enough number of simultaneous users, you can run out.

So yes, always close your connection when done.   Besides, I'm not a fan of lazy programming.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924823
What your friend showed you may be workable, I don't want to take the time to parse it out.  It is complex, messy, difficult to read, and difficult to debug.  Try doing it the way I showed you, I think you'll find it much easier to understand.
0
 

Author Comment

by:theram
ID: 17924866
Okay, we're in the final stretch.  I have finally figured out and found some code for the drop down menus:

<?

$db_server = "localhost";
$db_user = "*****";
$db_pass = "*****";
$db = "*******";

$con = mysql_connect($db_server,$db_user,$db_pass) or die("Unable to connect to MySQL");

mysql_select_db($db, $con);

$sql = "SELECT town,number FROM search ORDER BY town ASC";

$result=mysql_query($sql);

echo '<select name="list">';
while ($row = mysql_fetch_assoc($result)) {
echo '<option value="' . $row["town"] . '"> ' . $row["number"] . '</option>';

}

echo '</select>';

?>



This seems to work very well except that I can't get two fields into the menu rows.  Only the number shows up.

I need the menu items formatted to look like this:

Berlin  [L84]

Then I will have to figure out how the processing page is going to make the hyperlink go to the town.

Almost there.  Can you do this?
0
 

Author Comment

by:theram
ID: 17924869
Almost forgot ...

How do I limit the search for each drop-down menu?  I want a certain range of numbers for each of the seven menu boxes.

Thank you very much!
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924913
To format your option line:

echo '<option value="' . $row["town"] . '"> ' . $row["number"] . '</option>';

I hate messy, hard-to-read code, so I'm changing this to my style:

$town=$row["town"];
$number=$row["number"];   //I'm assuming the L is included in this field already
echo "<option value=$town>$town [$number]</option>";

Notice that what you want displayed is simply written as text between the > and the <

0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924927
>>How do I limit the search for each drop-down menu?  I want a certain range of numbers for each of the seven menu boxes.

If you mean limiting the search from the database by Number, you can add it to the WHERE clause of the query.

$query= "SELECT * FROM Table WHERE Number>'$lowlimit' AND Number<'$highlimit'";

If you mean limiting the options displayed by a hardcoded value, you can use IF when generating the options.

$town=$row["town"];
$number=$row["number"];   //I'm assuming the L is included in this field already
if ($number>$lowlimit && $number<$highlimit)
  echo "<option value=$town>$town [$number]</option>";

Don't forget to set the variables $lowlimit and $highlimit to some values first.
0
 

Author Comment

by:theram
ID: 17924949
Perfect!  (By the way, how do put an extra blank space in between words?)

Okay, now I am down to being able to process a selection to hyperlinked results like the other two searches , but basing it on one of the fields of the menu selections (either town or number).  Once I am able to get this search to process, then I am finished.  Excellent!

Will check with you later today about your advice.  Thanks!
0
 

Author Comment

by:theram
ID: 17924962
Missed your last post.  Will check it out.  

Yes, the L is already in the number field.

Do you mean define $lowlimit and $highlimit by substituting numbers or ?  I want to limit each menu box with the number.  Do I do something like:  $highlimit="1000"  placed above the town and number definitions?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17924969
Yes, you can set

$lowlimit=1000;
$highlimit=5000;

or whatever values you want.
0
 

Author Comment

by:theram
ID: 17924971
Please clarify the query lines

$sql = "SELECT town,number FROM search ORDER BY town ASC";
$query= "SELECT * FROM Table WHERE Number>'$lowlimit' AND Number<'$highlimit'";

Do these both go in the same area?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17925039
You make a variable ( you can call it $sql or $query or $abc, doesn't matter).  You set it to the MySQL query you want to use.  Then you use that variable in the mysql_query.

You'd be a lot better off if you'd try to understand what the code is doing, instead of trying to piece together code fragments from several sources.
0
 

Author Comment

by:theram
ID: 17926608
I appreciate the advice, but I learn by example and don't have a lot of time now.  I was abandoned suddenly in the middle of the project and have spent more than a week hunting for a solution and scripts.  I've learned a lot about PHP and MySQL this past week, but I just want to finish this.


Can the query go on the line under the sql query?

===================================

It appears that the filter is not working.

$query = "SELECT * FROM search WHERE number>'$lowlimit' AND number<'$highlimit'";

The table is "search

$lowlimit="1";
$highlimit="500";

It is not limiting the data to 500 as a high limit.

===================================

I'll work on the final process page and see if I have any further questions.  Thanks!


0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:theram
ID: 17927625
Need some help retrieving the result from the drop down search.  Would like to close this out soon, award points and move on.  Thanks!
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17927632
$lowlimit="1";
$highlimit="500";

should be

$lowlimit=1;
$highlimit=500;

because they are numbers, not character strings.

Make sure these two lines are ahead of the query itself.

DO keep them in ' 's in the query though, as mysql will recognize them as numbers.


>>>Can the query go on the line under the sql query?
I don't understand this question.
0
 

Author Comment

by:theram
ID: 17927673
Is this correct?  My editor shows the numbers incorrectly in a pink color:

<?

$sql = "SELECT * FROM search ORDER BY town ASC";

$lowlimit=1;
$highlimit=500;
$query = "SELECT * FROM search WHERE number>'$lowlimit' AND number<'$highlimit'";
$result=mysql_query($sql);

echo '<select name="list">';
while ($row = mysql_fetch_assoc($result))
{

$town=$row["town"];
$lindman=$row["number"];   //I'm assuming the L is included in this field already
echo "<option value=$town>$town - [$number]</option>";

}

echo '</select>';

?>
0
 

Author Comment

by:theram
ID: 17927747
There?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17927823
No, it's not correct.  

1.  You have 2 MySQL SELECT queries set up, one in $sql and one in $query.  Which one do you intend to use?
2.  mysql_fetch_assoc should be mysql_fetch_array
3.  These two lines are wrong:

$lindman=$row["number"];   //I'm assuming the L is included in this field already
echo "<option value=$town>$town - [$number]</option>";

because you set up the variable $lindman but then echo out the variable $number.  It should probably be

$lindman=$row["number"];   //I'm assuming the L is included in this field already
echo "<option value=$town>$town - [$lindman]</option>";


Fix these things and then I'll look again.
0
 

Author Comment

by:theram
ID: 17927872
yodercm,

Sorry about the confusion.  I was simply working with "number" for this solution so as to make the example and work easier.  However, let's just use lindman from now on instead of number because that is the actual field in the database.

I changed the code.  Here it is.  It returns everything from L1 to L5 (and variations in between like 3.1, 4.1, etc.) but it will not go to the limit of L500.  L is part of the database entry/field.

So here is the code for the 1st of the seven like search tables:

<?

$lowlimit=1;
$highlimit=500;
$query = "SELECT * FROM search WHERE lindman>'$lowlimit' AND lindman<'$highlimit'";
$result=mysql_query($sql);

echo '<select name="list">';
while ($row = mysql_fetch_array($result))
 
{

$town=$row["town"];
$lindman=$row["lindman"];   //I'm assuming the L is included in this field already
echo "<option value=$town>$town - [$lindman]</option>";

}

echo '</select>';

?>


Does this look correct?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17927923
OK, if the L is included in the database field, then you have a character field instead of a numeric field, right?

So what does the data in that field look like exactly?  

How is the field defined (CHAR, VARCHAR, TEXT, or what)?

Do you have any control over the field definition?  That is, can you make it a numeric field and forget about the L?

0
 

Author Comment

by:theram
ID: 17927929
The lindman field is VARCHAR
0
 

Author Comment

by:theram
ID: 17927948
I have another field in the database that is the same as lindman but without the L.  Should we use that?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17928000
If the other field is numeric, then yes, because the number comparison in the query is far, far easier than a string comparison would be.
0
 

Author Comment

by:theram
ID: 17928009
okay, let me try it
0
 

Author Comment

by:theram
ID: 17928112
Bad news and good news.

The following script works only if $sql is used versus $query, limiting the the numbers to between 1 and 500 as preferred.

HOWEVER, the towns do not sort in order.  Can an ORDER BY be put in the same $sql query statement?



$lowlimit=1;
$highlimit=500;
$sql = "SELECT * FROM search WHERE pretty_lindman>'$lowlimit' AND pretty_lindman<'$highlimit'";
$result=mysql_query($sql);

echo '<select name="list">';
while ($row = mysql_fetch_assoc($result))
{

$town=$row["town"];
$pretty_lindman=$row["pretty_lindman"];   //I'm assuming the L is included in this field already
echo "<option value=$town>$town - [$pretty_lindman]</option>";

}

echo '</select>';

?>
0
 

Author Comment

by:theram
ID: 17928130
you wrote:

mysql_fetch_assoc should be mysql_fetch_array


mysql_fetch_array doesn't make the limit statement work.  Only the mysql_fetch_assoc does the job.
0
 

Author Comment

by:theram
ID: 17928322
Looks as if I have everything working on the main search page and the processing pages.  All I have to do now is to be able to join the LIMIT and ORDER BY statements.  I think I am going to eliminate the subnumber entries in the database and simply keep only the whole numbers.  I'll use the subnumbers on the hyperlinked HTML pages.

Let me know how we can improve the SELECT statement to work with LIMIT and ORDER BY and then we are finished.
0
 

Author Comment

by:theram
ID: 17928744
Okay, I think I have everything working now.  I filtered it actually by making each of the seven tables query by id in the database instead of by town or number.  Works perfectly.

However, I have one final problem.  When I call the pages from any of the searches, I get a hyperlink as wanted, but I forgot that each entry needs to hyperlink to an interior html page.  Do I need to make a field in the database for a hyperlink page to each database entry?  Please help ASAP.  I want to finish.  Thank you.
0
 

Author Comment

by:theram
ID: 17928761
Missed another problem

I have this in the results page for the drop down:

$town=$row['town'];
$lindman=$row['lindman'];
$hyperlink="<a href=\"$href\">$lindman</a>.<a href=\"$href\">$town</a>";
//<<<<< construct the link url that you need here
echo "<tr><td align=center>$hyperlink</td></tr>";  //<<<<<< echo the link url to the output table row

Unfortunately, it outputs multiple identical town name links and two lindman number links.  Some towns have multiple entries, but only one unique lindman number.  I only want it to output the selected row from the drop down menu row that has a distinct lindman number but attaches the name, too.  Please advise.
0
 

Author Comment

by:theram
ID: 17928870
Okay, fixed the problem with the town and number.  Is this correct?

$hyperlink="<a href=\"$href\">$lindman</a>  --  $town";
0
 

Author Comment

by:theram
ID: 17929260
Problem.  Need to make the hyperlink go to a page like L1.php in a particular directory.

Can you give me an example?
0
 

Author Comment

by:theram
ID: 17929317
There?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17929381
mysql_fetch_array doesn't make the limit statement work.  Only the mysql_fetch_assoc does the job.

How you fetch the final array has nothing to do with the limit you have placed on the query itself.  Whatever makes you think this is a different problem than which function you use.  However, if you have it working, it won't matter for your simple application.


$hyperlink="<a href=\"$href\">$lindman</a>  --  $town";  

This is ok, but you could also use

$hyperlink="<a href=\"$href\">$lindman  --  $town";</a>

Whatever is between the  >  and the  <  will appear as the link to the user.  Whatever the variable $href is set to will be the processing script for this link.


If the hyperlink script can be constructed directly from the information in the database, you can do that.  For example, given the town=Lisle and the lindman=3, you can construct the link as

$href=$town.$lindman.".php";   //<<<< this will cause $href to equal "Lisle3.php"

However, if you need a more general name for your processing script, then you will need to create a database field to store it for each town/lindman/etc.  In that case, you will retrieve the script name just like you retrieve the Town and Lindman fields from the mysql query, and then set $href equal to that value.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17929410
P.S.  If the directory containing the processing script is different than the one that the screen script is in, then be sure you construct or store the URL including the full directory path name.  
0
 

Author Comment

by:theram
ID: 17929459
I simply want the output to create a link as follows (for example) after retrieving the Lindman number of "L1":

http://www.mydomain.net/directory/directory/pages/L1.php

Can this be done from just the echo command?


$href=$town.$lindman.".php";
$town=$row['town'];
$lindman=$row['lindman'];
$hyperlink="<a href=\"$href\">$lindman  --  $town";</a>
echo "<tr><td align=center>$hyperlink</td></tr>";
0
 

Author Comment

by:theram
ID: 17929556
There?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17929776
Your line of code

$href=$town.$lindman.".php";

will set the variable $href (your actual link) to the town name and lindman number, for example to ChicagoL1.php.

If you want just the lindman number, then specify just the lindman number, as in

$href=$lindman.".php";

0
 
LVL 27

Expert Comment

by:yodercm
ID: 17929805
So now, if you want to specify the full path, put it into the $href variable as follows:

$href = "http://www.mydomain.net/directory/directory/pages/" . $lindman . ".php";

This concatenates (the dots are concatenation) the directory path to the lindman number from the variable $lindman, then to the ".php" to assemble the full link.
0
 

Author Comment

by:theram
ID: 17934169
It's not working.

I can't get the lindman number to combine with the .php
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17934613
That's not a very helpful description of the problem.  What happens when you code the line I gave you?

Try echoing $lindman and $href immediately after this line of code, and see what you get.

$href = "http://www.mydomain.net/directory/directory/pages/" . $lindman . ".php";
echo "lindman=$lindman, href=$href";

Then show me the result.
0
 

Author Comment

by:theram
ID: 17934625
I'll go echo it now, but what is was returning was just .../.php    NO LINDMAN NUMBER.

Testing now
0
 

Author Comment

by:theram
ID: 17934629
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17934674
OK, the variable $lindman is not set.  So go back to where you think you are giving it a value,

(probably here:  $lindman=$row['lindman'];  )

and see what's wrong.  Either you are using the wrong field name, or the query isn't working, or the value in the database field is null.

You can use echo again there to see what values you're getting for the query results.

0
 

Author Comment

by:theram
ID: 17934697
Check this out:

 $query = "SELECT town, lindman, pretty_lindman FROM search WHERE pretty_lindman = '$search'";
 $results = mysql_query($query) or die("Error In Query: $sql." . mysql_error());
 $pretty_lindman = htmlentities($_GET['pretty_lindman'], ENT_QUOTES);

 while($row = mysql_fetch_assoc($results))
0
 

Author Comment

by:theram
ID: 17934725
I was using the field without the L (which is pretty_lindman) to get a result from the searchbox where one can search by lindman number
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17934767
This line ...

$pretty_lindman = htmlentities($_GET['pretty_lindman'], ENT_QUOTES);

has nothing whatsoever to do with the query and should not be there.  It's used only to retrieve and check user input from a form (which I believe in your case is actually the $search).  You should be using a line like this when you get the $search value that the user entered, but NOT on things retrieved from the database query.

Within the while loop, you are getting the values from the database query, one of which is lindman.  Then you want to use that value to construct the link.

So after you get the value of lindman from the $row, echo it out and see what you got.
0
 

Author Comment

by:theram
ID: 17934812
Okay, let's backtrack a few minutes to straighten this out.

First, I am working on the search2.php, which is the search by Lindman number.

So, please correct any code in the form and the processing page and I think we will be on our way to the finish.

==============================================

On the main search page:

<FORM action="search2.php" method="GET">
<TABLE cellspacing=2 cellpadding=1 width=380 border=0>
  <TBODY>
  <TR>
    <TD align=left valign=middle width=200 bgColor=#ffffff><FONT
      face="verdana,arial,helvetica,sans serif" color=#840000 size=2><b>Search by Lindman number</b></FONT></TD><TD align=center valign=top width=180 bgColor=#ffffff><FONT
      face="verdana,arial,helvetica,sans serif" color=#840000 size=3><STRONG> L </STRONG>
      <INPUT maxLength=4 size=4 type="text" name="search"> &nbsp;&nbsp;&nbsp;
      <INPUT type=submit value='Search!'>
</FONT></TD></TR></TBODY></TABLE>
</FORM>

============================================

On the processing page (search2.php):

<?php
require_once('connect.php');
?>
<html>
<head>
<title>Site Search</title>
<link type="text/css" href="search.css" rel="stylesheet">
</head>
<body class="search_body" style="margin:0">
<center><br><br><br><br><br>
<TABLE BGCOLOR="#C46225" BORDER=0 CELLPADDING=10 CELLSPACING=5 width=540>
<tr><th align=center class="search_title">Notgeld Serienscheine Search Results</th></tr>
<?

 $query = "SELECT town, lindman, pretty_lindman FROM search WHERE pretty_lindman = '$search'";
 echo "SELECT town, lindman, pretty_lindman FROM search WHERE pretty_lindman = '$search'";
 $results = mysql_query($query) or die("Error In Query: $sql." . mysql_error());
 $pretty_lindman = htmlentities($_GET['pretty_lindman'], ENT_QUOTES);

 while($row = mysql_fetch_assoc($results))
 {
 $href = "http://www.mydomain.net/directory/pages/".$lindman.".php";
 echo "lindman=$lindman, href=$href";
 $town=$row['town'];
 $lindman=$row['lindman'];
 $hyperlink="<a href=\"$href\">$lindman</a>";
 echo "<tr><td align=center>$hyperlink<br><br><h3>$town</h3></td></tr>";
}

?>

<tr><td align=center><a href="search.php"><h3>Back to Search</h3></a></td></tr></table></center>

</body>
</html>
0
 

Author Comment

by:theram
ID: 17934974
Third search on page is similar but asks for town name.
0
 

Author Comment

by:theram
ID: 17935155
There?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17935222
You didn't remove the line I told you to remove.

You haven't echo'ed out the variables I told you to echo out.

YOU have to do the testing on this, I can't.  So fix what I told you, and then start echo'ing out variables until you see exactly what is happening in the code.
0
 

Author Comment

by:theram
ID: 17935252
Yes, but I wanted to make sure you approve the total code first.  Does it look okay?
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17935273
I cannot tell if it's 'ok'.  I don't have access to your server, to your database, or to your complete code.  I can't debug this for you.  My job is to answer a question, to explain how to do something you need to do, not to write, test, or debug your program for you.

No, it does NOT look ok.  I already told you what to change, and you haven't done it.  Make the changes I told you and then test it.  Find out what the values of the variables are by echoing them out at strategic points.  This is your job.

The typical 500 point question takes an expert around 10 minutes to answer.  I've put almost 3 days into trying to help you.  You have to do your part.
0
 

Author Comment

by:theram
ID: 17935304
Parse error: parse error, unexpected T_WHILE in /home/notgeld/public_html/newlook/search2.php on line 19
0
 

Author Comment

by:theram
ID: 17935344
I went back to some previous code and now I am getting a link back that works, but it only goes to the first directory.

<?

$query = "SELECT * FROM search WHERE pretty_lindman='$search'";
$result =  mysql_query($query);
echo mysql_error();
if (mysql_num_rows($result) <= 0)
{
 
}
while ($row = mysql_fetch_array($result))
{
  $href = "http://www.notgeld.net/newlook/pages/";
  $town=$row['town'];
  $lindman=$row['lindman'];
  echo "<tr><td align=center><a href='.php?id=" . $row['lindman'] . "'>" . $row['lindman'] . "</a><h2>$town</h2></td><tr>";
}

echo "<tr><td align=center><a href=\"search.php\"><h3>Back to Search</h3></a></td></tr></table></center>";
mysql_close();    
exit();
?>

It goes to http://www.mydomain.net/newlook/pages/

instead of  http://www.mydomain.net/newlook/

How can I change this?
0
 

Author Comment

by:theram
ID: 17935349
Sorry, tired.  Have it reversed.


It goes to http://www.mydomain.net/newlook/

instead of  http://www.mydomain.net/newlook/pages/
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17935410
Put in a lot of echo statements on all the variables where you use them, and see what their actual values are.

I use statements like

echo "Debug 1 variablename=$variablename<br>";  

to echo out $variablename, and number each one of them differently, so I know exactly where the echo came from.

Do this.  Throughout your php code.
0
 

Author Comment

by:theram
ID: 17935619
Here is the result of the process page for the drop down menu search (search1.php) for the first entry in the database.

http://www.mydomain.net/newlook/search1.php?town=group&town=Aachen

The resulting link is

http://www.mydomain.net/newlook/.php

Can you tell something from this?

0
 

Author Comment

by:theram
ID: 17935650
DEBUG RESULTS

<?

$result = mysql_query("SELECT town, lindman FROM search WHERE town LIKE '$town'");
echo "Debug 1 town=$town<br>";  
//$search=htmlentities($_GET['lindman'],ENT_QUOTES);
echo mysql_error();
if (mysql_num_rows($result) <= 0)
{
 
}
while ($row = mysql_fetch_assoc($result))
{
  $href=$lindman.".php";
echo "Debug 2 lindman=$lindman<br>";  
  $town=$row['town'];
echo "Debug 3 town=$town<br>";  
  $lindman=$row['lindman'];
echo "Debug 4 lindman=$lindman<br>";  
  $hyperlink="<a href=\"$href\">$lindman</a>";
 echo "<tr><td align=center>$hyperlink</td></tr>";
echo "Debug 5 hyperlink=$hyperlink<br>";  
 echo "<tr><td align=center><h2>$town</h2></td><tr>";
}


Debug 1 town=Aachen
Debug 2 lindman=
Debug 3 town=Aachen
Debug 4 lindman=L1
Debug 5 hyperlink=
0
 

Author Comment

by:theram
ID: 17935724
NEW DEBUG  

Debug 1 town=
Debug 2 lindman=number
Debug 3 town=Aachen
Debug 4 lindman=L1
Debug 5 hyperlink=


<?

$result = mysql_query("SELECT * FROM search WHERE town='$search'");
echo "Debug 1 town=$town<br>";  
//$search=htmlentities($_GET['lindman'],ENT_QUOTES);
echo mysql_error();
if (mysql_num_rows($result) <= 0)
{
  // in here you will put the code to handle a town that doesn't exist in the database if needed
}

while ($row = mysql_fetch_assoc($result))
{
  $href=$lindman.".php";
echo "Debug 2 lindman=$lindman<br>";  
  $town=$row['town'];
echo "Debug 3 town=$town<br>";  
  $lindman=$row['lindman'];
echo "Debug 4 lindman=$lindman<br>";  
  $hyperlink="<a href=\"$href\">$lindman</a>";
 echo "<tr><td align=center>$hyperlink</td></tr>";
echo "Debug 5 hyperlink=$hyperlink<br>";  
 echo "<tr><td align=center><h2>$town</h2></td><tr>";
}
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17935861
http://www.mydomain.net/newlook/search1.php?town=group&town=Aachen

This URL has two different arguments both named town.  That won't work because when search1.php does the $_GET['town'] to retrieve them, it will only get one of the values.  If you are passing two arguments, you need two names.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17935870
>>>The resulting link is

>>>http://www.mydomain.net/newlook/.php

>>>Can you tell something from this?

I can tell that the variable that should fill in the name of the script (whatever.php) is null, so you're getting only the .php part.

Go back to where that variable should be set, and use echo to figure out why it's null.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17935878
WHERE town LIKE '$town'");

should be

WHERE town='$town'");

You only use LIKE if you are using wildcard matching, and then you would need the % wildcard characters.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17935899
Here is one of your problems:

while ($row = mysql_fetch_assoc($result))
{
  $href=$lindman.".php";     <<<<<<<<<<<<<<<< You are setting $href to a value including $lindman BUT.....
echo "Debug 2 lindman=$lindman<br>";  
  $town=$row['town'];
echo "Debug 3 town=$town<br>";  
  $lindman=$row['lindman'];   <<<<<<<<<<<<<<< You aren't setting the value of $lindman until here.
echo "Debug 4 lindman=$lindman<br>";  
  $hyperlink="<a href=\"$href\">$lindman</a>";
 echo "<tr><td align=center>$hyperlink</td></tr>";
echo "Debug 5 hyperlink=$hyperlink<br>";  
 echo "<tr><td align=center><h2>$town</h2></td><tr>";
}
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17935915
I don't understand why the debug 5 value of $hyperlink is coming up null...

  $hyperlink="<a href=\"$href\">$lindman</a>";
 echo "<tr><td align=center>$hyperlink</td></tr>";
echo "Debug 5 hyperlink=$hyperlink<br>";  

but I have a feeling it has something to do with the quotes.

Try changing it to this

$hyperlink="<a href=$href>$lindman</a>";
echo "<tr><td align=center>$hyperlink</td></tr>";
echo "Debug 5 hyperlink=$hyperlink<br>";  

and see if the Debug 5 value is correct.
0
 

Author Comment

by:theram
ID: 17936077
NEW DEBUG

Debug 1 town=
Debug 2 town=Aachen
Debug 3 lindman=L1
Debug 4 lindman=L1
Debug 5 hyperlink=L1


while ($row = mysql_fetch_assoc($result))
{  
  $town=$row['town'];
echo "Debug 2 town=$town<br>";  
  $lindman=$row['lindman'];
echo "Debug 3 lindman=$lindman<br>";  
  $hyperlink="<a href=$href>$lindman</a>";
  $href=$lindman.".php";
echo "Debug 4 lindman=$lindman<br>";
echo "<tr><td align=center>$hyperlink</td></tr>";
echo "Debug 5 hyperlink=$hyperlink<br>";
echo "<tr><td align=center><h2>$town</h2></td><tr>";
}
0
 

Author Comment

by:theram
ID: 17936110
DEBUG of SEARCH on main page... see if you can find the probable mistake, please.

<TABLE cellSpacing=2 cellPadding=3 width=600 border=0>
  <TBODY>
  <TR>
   <FORM action="search1.php" method="GET">
   <input type="hidden" name="search" value="number">
    <TD align=center valign=middle width=130 bgColor=#840000><FONT
      face="verdana,helvetica,sans serif" color=#ffffff
      size=4><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1-200&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</STRONG></FONT> </TD>
    <TD align=left width=405 bgColor=#840000><FONT
      face="verdana,arial,helvetica,sans serif" size=2>
<?

$lowlimit=1;
$highlimit=10000;
$sql = "SELECT * FROM search WHERE id>'$lowlimit' AND id<'$highlimit'";
$result=mysql_query($sql);

echo '<select name="search">';
while ($row = mysql_fetch_assoc($result))
{

$town=$row['town'];
$lindman=$row['lindman'];   //I'm assuming the L is included in this field already
echo "<option value=$town>$town - [$lindman]</option>";

}

echo '</select>';

?>

</FONT></TD>
<TD align=right width=100><FONT face="verdana,arial,helvetica,sans serif"
      size=2><INPUT type=submit value=Search!>
</FONT></TD></FORM></TR></TBODY></TABLE>
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17939906
Here's one error:

  $hyperlink="<a href=$href>$lindman</a>";
  $href=$lindman.".php";

You have to set $href BEFORE you use it to set $hyperlink.

Reverse these two lines.

  $href=$lindman.".php";
  $hyperlink="<a href=$href>$lindman</a>";

0
 
LVL 27

Expert Comment

by:yodercm
ID: 17940007
If you use this FORM statement

 <FORM action="search1.php" method="GET">

Then you have to use $_GET to retrieve the INPUT values in search1.php.

The preferred method is to use

 <FORM action="search1.php" method="POST">

and $_POST to retrieve the input, because the POST system of data handling is more secure and will handle larger data strings.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17940038
In your last post at Date: 11/13/2006 09:53PM PST

1.  I don't see any Debug output.

2.  In the query $sql = "SELECT * FROM search WHERE id>'$lowlimit' AND id<'$highlimit'";
where did id come from? Per your post at Date: 11/12/2006 10:06PM PST, I thought the field name was pretty_lindman.
0
 

Assisted Solution

by:theram
theram earned 100 total points
ID: 17941833
First, I was experimenting and reversed the two lines and the required lindman number began to appear.  Then I simply added the exact url to the $href and now everything works well.

Secondly, Where does $_POST go in the code?

Third, In the query $sql = "SELECT * FROM search WHERE id>'$lowlimit' AND id<'$highlimit'"; the "id" came from the comment in my post post at Date: 11/13/2006 01:58AM PST  Because the id is an exact number field, it seems to work perfectly to search and populate the drop down tables exactly.   If the limits are, say, 1 and 10000 from the id column, which is the first column in my table and the KEY, then you get an exact query and pull down from the database.  However, using the other columns that have either, say, 123 or L123, then you get a different result if you query by "lindman" because the query treats any result that has a 1 in the front -- like 1200 -- as being between 1 and 500.  So I figured out that limiting by "id"was the most exact solution for results.  I bet there is a code that can fix that problem, and I probably should use it so that I don't have to change the "id" range in the future.  Have a suggestion?

So, for now, the coding works perfectly.  

I will go change the GET to POST and see if it all still works fine.  But, please, tell me where the $_POST goes in the code.

====================================================

Here is the code on each of the three PROCESSING pages that works:

<?
$result = mysql_query("SELECT * FROM search WHERE town='$search'");
echo mysql_error();
if (mysql_num_rows($result) <= 0)
{
 
}
while ($row = mysql_fetch_assoc($result))
{
  $town=$row['town'];
  $lindman=$row['lindman'];
  $href = "http://www.mydomain.net/newlook/pages/".$lindman.".php";
  $hyperlink="<a href=\"$href\">$lindman</a>";
 echo "<tr><td align=center>$hyperlink</td></tr>";
 echo "<tr><td align=center><h2>$town</h2></td><tr>";
}

echo "<tr><td align=center><a href=\"search.php\"><h3>Back to Search</h3></a></td></tr></table></center>";
mysql_close();    
exit();
?>

================================================

Here's the code from the first search (drop down menus) where each of the seven drop downs has different high and low limit values.  I probably could use a more refined code to create the tables, but I can live with what I have unless you have a better suggestion:


<?

$lowlimit=1;
$highlimit=10000;
$sql = "SELECT id, town, lindman FROM search WHERE id>'$lowlimit' AND id<'$highlimit'";
$result=mysql_query($sql);

echo '<select name="search">';
while ($row = mysql_fetch_array($result))
{

$town=$row['town'];
$lindman=$row['lindman'];
echo "<option value=$town>$town - [$lindman]</option>";

}

echo '</select>';

?>

=========================================

Then, the second search where the Lindman number (without the L) is entered:

<FORM action="search2.php" method="GET">
<TABLE cellSpacing=2 cellPadding=1 width=380 border=0>
  <TBODY>
  <TR>
    <TD align=left valign=middle width=200 bgColor=#ffffff><FONT
      face="verdana,arial,helvetica,sans serif" color=#840000 size=2><b>Search by Lindman number</b></FONT></TD><TD align=center valign=top width=180 bgColor=#ffffff><FONT
      face="verdana,arial,helvetica,sans serif" color=#840000 size=3><STRONG> L </STRONG>
      <INPUT maxLength=4 size=4 type="text" name="search"> &nbsp;&nbsp;&nbsp;
      <INPUT type=submit value='Search!'>
</FONT></TD></TR></TBODY></TABLE></FORM>


======================================================

Then, the third search where the town name is entered:

<FORM action="search3.php" method="GET">
  <TABLE cellSpacing=2 cellPadding=0 width=540 border=0>
  <TBODY>
  <TR>
    <TD align=right width=190 bgColor=#ffffff>
        <FONT face="verdana,arial,helvetica,sans serif" color=#840000 size=2>
        <b>Search by Word String</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </FONT> </TD>
    <TD align=left width=350 bgColor=#ffffff>
        <FONT face="verdana,arial,helvetica,sans serif" color=#004000 size=3>
        <INPUT maxLength=40 size=35 type="text" name="search"> &nbsp;&nbsp;&nbsp;
        <INPUT type=submit value='Search!'>
</FONT></TD></TR></TBODY></TABLE></FORM>

====================================

Okay, that's it.  How about a suggestion for the first search regarding the high and low limits, but also about where to put the $_POST.  Thank you.  Will close out as soon as I hear back from you.



0
 
LVL 27

Expert Comment

by:yodercm
ID: 17942291
Four days and I get an assist?  Thank you very much and good luck.
0
 

Author Comment

by:theram
ID: 17955011
yodercm,

First of all, I contacted customer service about my question, about accept, about points.  Told them I wanted to split the points, giving you 400 and a grade of A.  Then, after you posted your ungrateful remark, I called them again to find out if I had done anything wrong, and they told me that it was quite surprising that you would gripe over 400 points and a grade of A.

I agree. It's not only surprising, but ridiculous.  I spent days trying to find scripts and code for what seems to be a less than complex form page and results page, and it was quite difficult to find anything close anywhere on the Web.  Then I happened upon EE and noticed that many experts were displaying complete scripts/code in response to questions by newbies and experts alike. I thought this was great, and then signed up for the premium service.  After describing my problem, two of you chimed in.  VoteyDisciple was quite precise and courteous and offered excellent advice, and I even started out with some of his code.  It's too bad he didn't continue on with me.  However, he opted to let you continue offering advice.

Some of you advice was good, some not.  I appreciate the advice and snippets you gave to me, but you often waited many hours before getting back to me. Consequently, what should have lasted only a day turned into many days.  In some cases, you didn't really give me the best answer.  In between the time gaps, I searched hours elsewhere on the Web for examples and code, doing some experimenting and finding solutions on my own. In the end, your attitude sucked.  I was getting closer and closer to the solution, and you just kept getting nastier.  Well, I finally figured it out, and I deserve a little credit, too.  Can't believe you -- 400 points and an A grade and you bitch.  I spent an entire week trying to figure this out, neglecting my normal life, my wife, my dogs, my sleep, etc., just to focus and get this finished (waiting hours for responses from you) and you bitch.

EE is a great service, but I hope I can find someone more precise and courteous next time around.

"Thank you very much" to you, also.
0
 
LVL 27

Expert Comment

by:yodercm
ID: 17955281
I hope you can find someone who doesn't sleep, who can debug code without complete information, who doesn't mind that you don't try what s/he suggests, who doesn't care that you continually change what you want, and who loves it that you just expect him/her to write the entire program for you in the blind.

Now, before either of us gets nasty about this, I have some suggestions for you next time you use EE.

1.  Give a much more precise statement of what you need to learn.  Prepare ahead so you can explain exactly what you want to do, and how you want it to work, before you post.  Don't post in a panic and then keep changing the description of what you need.

2.  Give full database information including table names and fields.  If you prefer to keep this non-public, then you can use faked names, but then YOU will be responsible for changing the code that you are given to reflect the correct names.

3.  Implement and test what an expert gives you, and feed back full precise information about what happened with it.

4.  Understand the code you are given by studying it, looking up the functions or techniques, and learning exactly what it does while you are implementing and testing it.

Experts here are most happy to help people, and they give their time for free.  Occasionally experts actually write seqments of code for people.  But writing two full scripts is something that experts get paid to do.  

Yes, I got very frustrated with your attitude.  I was constantly going around in circles because you refused to try and understand it yourself, you couldn't even define what you wanted, you changed things over and over, you gave me incomplete information repeatedly, and you posted code expecting me to VISUALLY debug it when I didn't have the information necessary to do so.

You also demanded instant replies and attention, including several times showing irritation that I didn't respond immediately.  Try to remember that experts are not devoting 100% of their time to you, or even to this board.  Some of us occasionally sleep or go buy groceries.  Your constant "There?" posts were annoying.

I'm sorry you got stuck with doing this for yourself on short notice, and I hope you will continue to use the EE service when you need help.  I also hope you will appreciate what you are getting and treat the experts who help you with courtesy and cooperation.

I was not at all annoyed that you gave points to VoteyDisciple.  I was annoyed that you gave them to yourself.
0
 

Author Comment

by:theram
ID: 17960324
yodercm and humeniuk,

I didn't award points to myself, and that's what bothers me about yodercm's response.  I talked to customer service and explained the situation.  I didn't quite understand the point award system.  It's not that easy to comprehend at first.  I called to ask about how to split it because VoteyDisciple helped a little and I was not totally satisfied with yodercm's answers or attitude. I told cs that I ended up having to find solutions myself as I waited hours between answers, and that I was desirous of giving some points to VoteyDisciple for his assistance.  CS asked me if I provided some of the solution myself, and I told him I did, and he awarded some points to me.  It was unexpected and no big deal from my point of view. The points don't mean anything to me, only results.

Sorry, but my venture into EE was out of desperation because simple form examples and solutions seem to lacking on the Web and I was under some time pressure.  No doubt that there was some misunderstanding.  What was frustrating is that yodercm would answer a question, and when I would respond with another pertinent question within seconds to minutes, then I would not hear back for hours.  It wasn't a question of whether experts devoting 100% of their time to my question, it was that I was sitting there working on the solution and after getting some script/code and testing it right away, I was trying to relay results or questions back about the results.  Yes, some of us occasionally sleep or go buy groceries, but not in the middle of working on a programming problem while exchanging comments.

I do appreciate what I am getting, but I also expect to be treated with courtesy and cooperation.

That's it.  I'll use the service again, but I hope to have a better experience next time around.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now