Link to home
Start Free TrialLog in
Avatar of theram
theram

asked on

Need help with search scripting

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.
Avatar of Cornelia Yoder
Cornelia Yoder
Flag of United States of America image

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.
SOLUTION
Avatar of VoteyDisciple
VoteyDisciple

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$result = mysql=query($query);  should of course be $result = mysql_query($query);
and

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

should be

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

Heh heh, I really did proof-read this first :)
Avatar of theram
theram

ASKER

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>
Avatar of theram

ASKER

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>
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.
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.
Avatar of theram

ASKER

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!
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.
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 ).
Avatar of theram

ASKER

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!
Avatar of theram

ASKER

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.
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>";
}

?>
Avatar of theram

ASKER

I keep getting this error:

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

Why?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of theram

ASKER

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.
Avatar of theram

ASKER

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?
<?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( );
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.
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?
Avatar of theram

ASKER

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.
Avatar of theram

ASKER

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?
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?
Avatar of theram

ASKER

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.

Avatar of theram

ASKER

VoteyDisciple or yodercm,

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

Thank you.
Avatar of theram

ASKER

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?
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.

Avatar of theram

ASKER

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.

Avatar of theram

ASKER

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.
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.
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.
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);
Avatar of theram

ASKER

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.
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.
Avatar of theram

ASKER

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!
Avatar of theram

ASKER

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?
Avatar of theram

ASKER

yodercm

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

ASKER

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?
If the town name is 'abcd', then what exactly do you want the hyperlink to be?
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:
<head>
<link rel='stylesheet' type='text/css' href='your css script name goes here'>
Avatar of theram

ASKER

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>

Avatar of theram

ASKER

<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>";

?>

<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>";

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();
?>
Avatar of theram

ASKER

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?
Avatar of theram

ASKER

Fixed the closing problem.  Now all that is remaining is the drop-down menu situation and then it is finished.
Avatar of theram

ASKER

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.
>>>>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.
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.
Avatar of theram

ASKER

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?
Avatar of theram

ASKER

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!
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 <

>>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.
Avatar of theram

ASKER

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!
Avatar of theram

ASKER

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?
Yes, you can set

$lowlimit=1000;
$highlimit=5000;

or whatever values you want.
Avatar of theram

ASKER

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?
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.
Avatar of theram

ASKER

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!


Avatar of theram

ASKER

Need some help retrieving the result from the drop down search.  Would like to close this out soon, award points and move on.  Thanks!
$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.
Avatar of theram

ASKER

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>';

?>
Avatar of theram

ASKER

There?
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.
Avatar of theram

ASKER

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?
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?

Avatar of theram

ASKER

The lindman field is VARCHAR
Avatar of theram

ASKER

I have another field in the database that is the same as lindman but without the L.  Should we use that?
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.
Avatar of theram

ASKER

okay, let me try it
Avatar of theram

ASKER

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>';

?>
Avatar of theram

ASKER

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.
Avatar of theram

ASKER

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.
Avatar of theram

ASKER

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.
Avatar of theram

ASKER

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.
Avatar of theram

ASKER

Okay, fixed the problem with the town and number.  Is this correct?

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

ASKER

Problem.  Need to make the hyperlink go to a page like L1.php in a particular directory.

Can you give me an example?
Avatar of theram

ASKER

There?
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.
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.  
Avatar of theram

ASKER

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>";
Avatar of theram

ASKER

There?
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";

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.
Avatar of theram

ASKER

It's not working.

I can't get the lindman number to combine with the .php
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.
Avatar of theram

ASKER

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

Testing now
Avatar of theram

ASKER

lindman=, href=http://www.mydomain.net/directory/pages/.php
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.

Avatar of theram

ASKER

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))
Avatar of theram

ASKER

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
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.
Avatar of theram

ASKER

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>
Avatar of theram

ASKER

Third search on page is similar but asks for town name.
Avatar of theram

ASKER

There?
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.
Avatar of theram

ASKER

Yes, but I wanted to make sure you approve the total code first.  Does it look okay?
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.
Avatar of theram

ASKER

Parse error: parse error, unexpected T_WHILE in /home/notgeld/public_html/newlook/search2.php on line 19
Avatar of theram

ASKER

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?
Avatar of theram

ASKER

Sorry, tired.  Have it reversed.


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

instead of  http://www.mydomain.net/newlook/pages/
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.
Avatar of theram

ASKER

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?

Avatar of theram

ASKER

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=
Avatar of theram

ASKER

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>";
}
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.
>>>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.
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.
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>";
}
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.
Avatar of theram

ASKER

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>";
}
Avatar of theram

ASKER

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>
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>";

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.
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Four days and I get an assist?  Thank you very much and good luck.
Avatar of theram

ASKER

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.
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.
Avatar of theram

ASKER

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.