My form and results are on one page.
If I use :
if ($Company) {
$query = "Select Company, Contact
From tblworking
Where ID = $Company
Order By Company ASC";
}
if ($Name ) {
$query = "SELECT *
FROM TBLWorking
WHERE Contact Like '%$Name%'
ORDER BY Contact";
}
$result = mysql_query($query);
$number = mysql_numrows($result);
for ($i=0; $i<$number; $i++) {
$CompanyName = mysql_result($result,$i,"Company");
$ContactName = mysql_result($result,$i,"Contact");
Print "Company: $CompanyName";
Print "<P>Name: $ContactName";
}
As soon as I enter the page it searchs using $Name, even though I have not
entered any information.
This results in me getting a complete list printed on screen, with out me
having to search.
How do I get this to show just the form, then the form and the results ?
Thanks
On Sat, 28 Jun 2003 15:38:53 +0100, James <James@NotHere.com> wrote:
[color=blue]
>Thanks, its now working using:
>
>WHERE Contact Like '%$Name%'
>
>Cheers
>
>On Sat, 28 Jun 2003 13:36:19 +0100, Andy Hassall <andy@andyh.co.uk> wrote:
>[color=green]
>>On Sat, 28 Jun 2003 12:22:02 +0000 (UTC), Daniel Tryba
>><news_comp.lang.php@canopus.nl> wrote:
>>[color=darkred]
>>>James <James@nothere.com> wrote:
>>>> $q="SELECT ... Contact = "%$Name%" ORDER BY Contact ASC";
>>> ^begin string ^endstring
>>> ^beginstring ^endstring
>>>
>>>Learn the differences between " and ' and the use of these within a
>>>string (
http://nl.php.net/manual/en/language.types.string.php).
>>>
>>>Other problems are realted to sql.
>>>
>>>-wildcards (%) only work on strings AFAIK
>>>-strings need to be quoted (eg ').[/color]
>>
>> And wildcards in SQL only apply if you use 'LIKE' instead of '='.[/color][/color]