472,958 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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 3296
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.