473,473 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can anyone help, why doesn't this work ??

I have a from with 2 fields:
Company & Name

Depening which is completed, one of the following queries will be run:

if($Company){
$query = "Select C*
From tblsample
Where ID = $Company
Order By Company ASC";
}

if($Name){
$query = "SELECT *
FROM TBLsample
WHERE Contact = "%$Name%"
ORDER BY Contact ASC";
}
$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";
}

This work fine for 'Company', but not for 'Name'

How do I do a wild search using $Name in the Where statement.. ?

Ie $Name = Jim
So %Jim% should result in :
Jim
jimmy
jimm
etc !!

Thanks
Jul 16 '05 #1
4 3326
James <Ja***@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 ').

--

Daniel Tryba

Jul 16 '05 #2
On Sat, 28 Jun 2003 12:22:02 +0000 (UTC), Daniel Tryba
<ne****************@canopus.nl> wrote:
James <Ja***@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 ').


And wildcards in SQL only apply if you use 'LIKE' instead of '='.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #3
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 <Ja***@NotHere.com> wrote:
Thanks, its now working using:

WHERE Contact Like '%$Name%'

Cheers

On Sat, 28 Jun 2003 13:36:19 +0100, Andy Hassall <an**@andyh.co.uk> wrote:
On Sat, 28 Jun 2003 12:22:02 +0000 (UTC), Daniel Tryba
<ne****************@canopus.nl> wrote:
James <Ja***@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 ').


And wildcards in SQL only apply if you use 'LIKE' instead of '='.


Jul 16 '05 #4

"James" <Ja***@NotHere.com> wrote in message
news:dh********************************@4ax.com...
I have a from with 2 fields:
Company & Name

Depening which is completed, one of the following queries will be run:

if($Company){
$query = "Select C*
From tblsample
Where ID = $Company
Order By Company ASC";
}

if($Name){
$query = "SELECT *
FROM TBLsample
WHERE Contact = "%$Name%"
ORDER BY Contact ASC";
}
$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";
}

This work fine for 'Company', but not for 'Name'

How do I do a wild search using $Name in the Where statement.. ?

Ie $Name = Jim
So %Jim% should result in :if($Name){
Jim
jimmy
jimm
etc !!

Thanks


if ( $Company )
{
$query = "Select C* From tblsample Where ID LIKE '%$Company%' Order By
Company ASC";
}
if ( $Name )
{
$query = "SELECT * FROM TBLsample WHERE Contact LIKE '%$Name%' ORDER BY
Contact ASC";
}
Jul 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: RT | last post by:
I have followed the step by step instructions in the login manual Created login page Use LSC01 This works - login and get redirected to the proper page My problem is the cookie variables...
4
by: Jochen Daum | last post by:
Hi, I have to emulate a "file upload" to a Java Servlet which is done with the class URLConnection. The java source basically does URLConnection conn =...
3
by: Gernot Frisch | last post by:
Hi, my menu on www.GLBasic.com doesn't work on Opera 7.23. Can anyone help me please? -- -Gernot Post here, don't email. If you feel you have to mail, revert my
4
by: Iver Erling Årva | last post by:
I have an application that uses a window.open() to open it's own main window where all my programs takes place. I use a timeout so if nothing goes on for 15 minutes the document below is called. To...
4
by: Joseph | last post by:
The idea is to show only one of the <Baby_Div> while hiding all the others. At the moment all I have managed to do is to show each <Baby_Div> in turn as expected, but the problem is that once a...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
11
by: ricolee99 | last post by:
Hi everyone, I'm trying to invoke my .exe application from a remote server. Here is the code: ManagementClass processClass = new ManagementClass ("\\\\" +"RemoteServerName" +...
6
by: Bill foust | last post by:
I'm running into a situation there I think an operator overload would solve the issue, but I'm unable to make it work for some reason. If anyone can help here I would appreciate it. I have a...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
0
by: slishnevsky | last post by:
Hello, I have CrystalReport with 2 input parameters StartDate & EndDate. When I run this report in Preview in VS2005 environment, everything is fine, I get a dialog windows asking to provide input...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.