For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > December 2004 > Newbie search









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie search
phatnugs420@comcast.net

2004-12-03, 3:57 pm

Hi there I'm interested in doing a simple search with mysql and php.. Right
now it finds both of the fields:

SELECT * FROM itltest WHERE jobnum='$jobnum' AND custID='$custID


What I want it to do is to find all custID within the jobnum if the jobnum
is left blank in the field.. Any help would be appreciated!

Chip

2004-12-03, 3:57 pm

I'm sure someone has a better way to do this
but this worked for me.

if (isset( $_POST['jobnum'] ))
{
$jobnum = strval( $_POST['jobnum'] );
}
else
{
$jobnum = "%";
}
if (isset( $_POST['custID'] ))
{
$custID = strval( $_POST['custID'] );
}
else
{
$custID = "%";
}

The % wildcard requires using LIKE it won't work with =,

WHERE jobnum LIKE '$jobnum' AND custID Like 'custID'

Might help to see your code.






<phatnugs420@comcast.net> wrote in message
news:BDD506DE.B0E9%phatnugs420@comcast.net...
> Hi there I'm interested in doing a simple search with mysql and php..

Right
> now it finds both of the fields:
>
> SELECT * FROM itltest WHERE jobnum='$jobnum' AND custID='$custID
>
>
> What I want it to do is to find all custID within the jobnum if the jobnum
> is left blank in the field.. Any help would be appreciated!
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com