Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 05-31-2007, 7:40 PM   #1
C. David Rossen
 
C. David Rossen's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Select records from result of drop down selection

Hello:

I think I have what would be an easy solution for most people that know
mysql. I just don't know it very well.

I have a membership database of a professional organization of lawyers,
cpa's, etc. There is a field called "designation" (laywers, cpa's, clu's,
etc). I am going to build a search form with a drop down box so they can
search by designation. How would I write the select statement? The table
name is directory.

select from directory where designation = ???????? order by LastName ASC

Not sure how to reference the designation choice from the drop down list in
the select statement.

I also wanted to do a text search for LastName

select from directory where LastName like ?????? order by LastName ASC

If someone can lend a novice a hand, I'd greatly appreciate any help. Thanks
in advance.

David


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 05-31-2007, 7:40 PM   #2
Joseph Melnick
 
Joseph Melnick's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Select records from result of drop down selection

Mr. Rossen Wrote,

"C. David Rossen" <cdrossen@cdrmarketing.com> wrote in message
news:46GdnZb7fO1suiffRVn-sw@comcast.com...
> Hello:
>
> I think I have what would be an easy solution for most people that know
> mysql. I just don't know it very well.
>
> I have a membership database of a professional organization of lawyers,
> cpa's, etc. There is a field called "designation" (laywers, cpa's, clu's,
> etc). I am going to build a search form with a drop down box so they can
> search by designation. How would I write the select statement? The table
> name is directory.
>
> select from directory where designation = ???????? order by LastName ASC
>
> Not sure how to reference the designation choice from the drop down list
> in
> the select statement.
>
> I also wanted to do a text search for LastName
>
> select from directory where LastName like ?????? order by LastName ASC
>
> If someone can lend a novice a hand, I'd greatly appreciate any help.
> Thanks
> in advance.
>
> David
>


Hello David,

You propably have a finite set of designations with a short form for each
CPA
An individual may have multiple of these designations so if you want to pick
up all that have a CPA designation
then use the INSTR() function to capture this set like this


select * from directory where INSTR('CPA',designation) > 0 order by LastName
ASC

The html form

<select name="designation">
<option name="CPA">CPA</option>
<option name="CLU">CLU</option>
....
</select>

And in your language of choice you will need to replace the 'CPA' in the
above query string before submitting it to your database.

With PHP / MySQL.

<?php
$dbhost = "localhost";
$dbuser = "myuser";
$dbpass = "mypassword";
$dbname = "mydatabase";

$dblink = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $dblink);
$designation =
(array_key_exists('designation',$_REQUEST))?$_REQU EST['designation']:"None";

$query = "select name,designation,phone from directory where
INSTR('".$designation."',designation) > 0 order by LastName ASC";
$result = mysql_query($query,$dblink) or die('select from directory failed:
' . mysql_error());
while($row = mysql_fetch_array($result)) {
// echo the list
echo $row['name']." ".$row['designation']." ".$row['phone']."<br>";
}
?>

The second $query would be similar to this assuming PHP and an search form
input field name of LastName:

$LastName =
(array_key_exists('LastName',$_REQUEST))?$_REQUEST ['LastName']:"";
$query = "select name,designation,phone from directory where LastName like
'".$LastName."%' order by LastName ASC";

Hope this gets you off to a running start.

Joseph Melnick
JM Web Consultants
Toronto, ON, Canada
http://www.jphp.com/


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-31-2007, 7:40 PM   #3
C. David Rossen
 
C. David Rossen's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Select records from result of drop down selection

Joseph:

Thank you very much for all the help.

Actually, this morning I figured out something that seems to work but quite
different from what you have given me. I'll run it by you and maybe you can
see if I may run into trouble even though it works.

First, I created an HTML page for both forms (1 to search by designation,
the other to do the name search). For the designation search, the name of
the drop down is "designation" and the value of each selection is whatever
it is (attorney, cpa, etc). The action of that form is as follows:

<form action="http://www.ekcepc.org/designation.php" method="post">

Then here is how I did the section of the designation.php file:

//select the database
mysql_select_db("ekcep001");

$Designation=$_POST['Designation'];

//select table and criteria
$result = mysql_query("select * from directory where Designation =
'$Designation' ORDER BY LastName ASC");

//get the content
while($r=mysql_fetch_array($result))
{

$LastName=$r["LastName"];
$FirstName=$r["FirstName"];
$Company=$r["Company"];
$StreetAddress=$r["StreetAddress"];
$City=$r["City"];
$State=$r["State"];
$Zip=$r["Zip"];
$Phone=$r["Phone"];
$Fax=$r["Fax"];
$Email=$r["Email"];
$Designation=$r["Designation"];

//display the results
echo
"<center>
<table border='0' width='50%' cellspacing='0' cellpadding='6'>
<tr>
<td bgcolor='#F7EFCE'>
<font face='Arial'><span style='font-size: 9pt'>
<b>$LastName, $FirstName</b><br>
$Company<br>
$StreetAddress<br>
$City, $State $Zip<br>
<b>Tel:</b> $Phone<br>
<b>Fax:</b> $Fax<br>
<a href='mailto:$Email'>$Email</a><br>
<b>Designation:</b> $Designation<br>
</tr>
<tr>
<td><hr color='green'></td>
</tr>
</table>
</center>";
}
?>

For the name search, I simply have a text box on HTML page and action is:

<form action="http://www.ekcepc.org/lastname.php" method="post">

Then here is how I did the section of the lastname.php file:

//select the database
mysql_select_db("ekcep001");

$LastName=$_POST['LastName'];

//select table and criteria
$result = mysql_query("select * from directory where LastName = '$LastName'
ORDER BY LastName ASC");

//get the content
while($r=mysql_fetch_array($result))
{

$LastName=$r["LastName"];
$FirstName=$r["FirstName"];
$Company=$r["Company"];
$StreetAddress=$r["StreetAddress"];
$City=$r["City"];
$State=$r["State"];
$Zip=$r["Zip"];
$Phone=$r["Phone"];
$Fax=$r["Fax"];
$Email=$r["Email"];
$Designation=$r["Designation"];

//display the results
echo
"<center>
<table border='0' width='50%' cellspacing='0' cellpadding='6'>
<tr>
<td bgcolor='#F7EFCE'>
<font face='Arial'><span style='font-size: 9pt'>
<b>$LastName, $FirstName</b><br>
$Company<br>
$StreetAddress<br>
$City, $State $Zip<br>
<b>Tel:</b> $Phone<br>
<b>Fax:</b> $Fax<br>
<a href='mailto:$Email'>$Email</a><br>
<b>Designation:</b> $Designation<br>
</tr>
<tr>
<td><hr color='green'></td>
</tr>
</table>
</center>";
}
?>

Both of them seem to work. Are there any advantages of doing it the way you
layed out? Perhaps there are some hidden dangers with the way I did it. Let
me know. Thanks again.

David

"Joseph Melnick" <jmelnick@jphp.com> wrote in message
news:CJqdnaw_C4Zp3ybfRVn-3w@rogers.com...
> Mr. Rossen Wrote,
>
> "C. David Rossen" <cdrossen@cdrmarketing.com> wrote in message
> news:46GdnZb7fO1suiffRVn-sw@comcast.com...
> > Hello:
> >
> > I think I have what would be an easy solution for most people that know
> > mysql. I just don't know it very well.
> >
> > I have a membership database of a professional organization of lawyers,
> > cpa's, etc. There is a field called "designation" (laywers, cpa's,

clu's,
> > etc). I am going to build a search form with a drop down box so they can
> > search by designation. How would I write the select statement? The table
> > name is directory.
> >
> > select from directory where designation = ???????? order by LastName ASC
> >
> > Not sure how to reference the designation choice from the drop down list
> > in
> > the select statement.
> >
> > I also wanted to do a text search for LastName
> >
> > select from directory where LastName like ?????? order by LastName ASC
> >
> > If someone can lend a novice a hand, I'd greatly appreciate any help.
> > Thanks
> > in advance.
> >
> > David
> >

>
> Hello David,
>
> You propably have a finite set of designations with a short form for each
> CPA
> An individual may have multiple of these designations so if you want to

pick
> up all that have a CPA designation
> then use the INSTR() function to capture this set like this
>
>
> select * from directory where INSTR('CPA',designation) > 0 order by

LastName
> ASC
>
> The html form
>
> <select name="designation">
> <option name="CPA">CPA</option>
> <option name="CLU">CLU</option>
> ...
> </select>
>
> And in your language of choice you will need to replace the 'CPA' in the
> above query string before submitting it to your database.
>
> With PHP / MySQL.
>
> <?php
> $dbhost = "localhost";
> $dbuser = "myuser";
> $dbpass = "mypassword";
> $dbname = "mydatabase";
>
> $dblink = mysql_connect($dbhost, $dbuser, $dbpass);
> mysql_select_db($dbname, $dblink);
> $designation =
>

(array_key_exists('designation',$_REQUEST))?$_REQU EST['designation']:"None";
>
> $query = "select name,designation,phone from directory where
> INSTR('".$designation."',designation) > 0 order by LastName ASC";
> $result = mysql_query($query,$dblink) or die('select from directory

failed:
> ' . mysql_error());
> while($row = mysql_fetch_array($result)) {
> // echo the list
> echo $row['name']." ".$row['designation']." ".$row['phone']."<br>";
> }
> ?>
>
> The second $query would be similar to this assuming PHP and an search form
> input field name of LastName:
>
> $LastName =
> (array_key_exists('LastName',$_REQUEST))?$_REQUEST ['LastName']:"";
> $query = "select name,designation,phone from directory where LastName like
> '".$LastName."%' order by LastName ASC";
>
> Hope this gets you off to a running start.
>
> Joseph Melnick
> JM Web Consultants
> Toronto, ON, Canada
> http://www.jphp.com/
>
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-31-2007, 7:40 PM   #4
Joseph Melnick
 
Joseph Melnick's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Select records from result of drop down selection

Mr. Rossen Wrote:

"C. David Rossen" <cdrossen@cdrmarketing.com> wrote in message
news:ibednRncQ8Lz0CbfRVn-oQ@comcast.com...
> Joseph:
>
> Thank you very much for all the help.
>
> Actually, this morning I figured out something that seems to work but
> quite
> different from what you have given me. I'll run it by you and maybe you
> can
> see if I may run into trouble even though it works.
>
> First, I created an HTML page for both forms (1 to search by designation,
> the other to do the name search). For the designation search, the name of
> the drop down is "designation" and the value of each selection is whatever
> it is (attorney, cpa, etc). The action of that form is as follows:
>
> <form action="http://www.ekcepc.org/designation.php" method="post">
>
> Then here is how I did the section of the designation.php file:
>
> //select the database
> mysql_select_db("ekcep001");
>
> $Designation=$_POST['Designation'];


// $Designation could be an empty or may not exist.
// the following line will allow you to set $Designation yp a value of your
choosing
// with the added benefit of sending a known value to your database via
your query.
// You might also validate this value to protect your database for type,
length, format and content.
// string, three to 6 characters in length?, of your know set Lawyer, CPA,
CLU...
$Designation =
(array_key_exists('Designation',$_POST))?$_POST['Designation']:"";


>
> //select table and criteria
> $result = mysql_query("select * from directory where Designation =
> '$Designation' ORDER BY LastName ASC");
>
> //get the content
> while($r=mysql_fetch_array($result))
> {
>
> $LastName=$r["LastName"];
> $FirstName=$r["FirstName"];
> $Company=$r["Company"];
> $StreetAddress=$r["StreetAddress"];
> $City=$r["City"];
> $State=$r["State"];
> $Zip=$r["Zip"];
> $Phone=$r["Phone"];
> $Fax=$r["Fax"];
> $Email=$r["Email"];
> $Designation=$r["Designation"];
>
> //display the results
> echo
> "<center>
> <table border='0' width='50%' cellspacing='0' cellpadding='6'>
> <tr>
> <td bgcolor='#F7EFCE'>
> <font face='Arial'><span style='font-size: 9pt'>

// just a sylistic note: if you know about css then you should know that the
<font> tag is redundant here.
<span style='font-family: Arial, sans-serif; font-size: 9px'>

> <b>$LastName, $FirstName</b><br>
> $Company<br>
> $StreetAddress<br>
> $City, $State $Zip<br>
> <b>Tel:</b> $Phone<br>
> <b>Fax:</b> $Fax<br>
> <a href='mailto:$Email'>$Email</a><br>
> <b>Designation:</b> $Designation<br>
> </tr>
> <tr>
> <td><hr color='green'></td>
> </tr>
> </table>
> </center>";
> }
> ?>
>
> For the name search, I simply have a text box on HTML page and action is:
>
> <form action="http://www.ekcepc.org/lastname.php" method="post">
>
> Then here is how I did the section of the lastname.php file:
>
> //select the database
> mysql_select_db("ekcep001");
>
> $LastName=$_POST['LastName'];
>
> //select table and criteria
> $result = mysql_query("select * from directory where LastName =
> '$LastName'
> ORDER BY LastName ASC");
>
> //get the content
> while($r=mysql_fetch_array($result))
> {
>
> $LastName=$r["LastName"];
> $FirstName=$r["FirstName"];
> $Company=$r["Company"];
> $StreetAddress=$r["StreetAddress"];
> $City=$r["City"];
> $State=$r["State"];
> $Zip=$r["Zip"];
> $Phone=$r["Phone"];
> $Fax=$r["Fax"];
> $Email=$r["Email"];
> $Designation=$r["Designation"];
>
> //display the results
> echo
> "<center>
> <table border='0' width='50%' cellspacing='0' cellpadding='6'>
> <tr>
> <td bgcolor='#F7EFCE'>
> <font face='Arial'><span style='font-size: 9pt'>
> <b>$LastName, $FirstName</b><br>
> $Company<br>
> $StreetAddress<br>
> $City, $State $Zip<br>
> <b>Tel:</b> $Phone<br>
> <b>Fax:</b> $Fax<br>
> <a href='mailto:$Email'>$Email</a><br>
> <b>Designation:</b> $Designation<br>
> </tr>
> <tr>
> <td><hr color='green'></td>
> </tr>
> </table>
> </center>";
> }
> ?>
>
> Both of them seem to work. Are there any advantages of doing it the way
> you
> layed out? Perhaps there are some hidden dangers with the way I did it.
> Let
> me know. Thanks again.
>
> David
>


The use of INSTR() allows for more flexibility in finding a specific
designation in a string where more than one may occur.

The use of LIKE allows for more flexibility in finding like lastnames.

Also you could investigate the SOUNDEX() function where you can compare
whether a string sounds like a lastname in a column.

The PHP function ARRAY_KEY_EXISTS() in the construct presented allows you
to deal with a scemario where your user does not give you an expected
request and set your variable to a default value and enhances flexibilty.

Nothing wrong with your approach here but there are a number of ways to
accomplish these tasks.

Keep in mind that you should:

Never trust client input!
Always test your work.
Always expect that your clients will use your application in ways you do not
expect.
When things go wrong that it will be you who has to figure out how they
broke your program.

Joseph Melnick
JM Web Consultants
Toronto, ON, Canada
http://www.jphp.com/



> "Joseph Melnick" <jmelnick@jphp.com> wrote in message
> news:CJqdnaw_C4Zp3ybfRVn-3w@rogers.com...
>> Mr. Rossen Wrote,
>>
>> "C. David Rossen" <cdrossen@cdrmarketing.com> wrote in message
>> news:46GdnZb7fO1suiffRVn-sw@comcast.com...
>> > Hello:
>> >
>> > I think I have what would be an easy solution for most people that know
>> > mysql. I just don't know it very well.
>> >
>> > I have a membership database of a professional organization of lawyers,
>> > cpa's, etc. There is a field called "designation" (laywers, cpa's,

> clu's,
>> > etc). I am going to build a search form with a drop down box so they
>> > can
>> > search by designation. How would I write the select statement? The
>> > table
>> > name is directory.
>> >
>> > select from directory where designation = ???????? order by LastName
>> > ASC
>> >
>> > Not sure how to reference the designation choice from the drop down
>> > list
>> > in
>> > the select statement.
>> >
>> > I also wanted to do a text search for LastName
>> >
>> > select from directory where LastName like ?????? order by LastName ASC
>> >
>> > If someone can lend a novice a hand, I'd greatly appreciate any help.
>> > Thanks
>> > in advance.
>> >
>> > David
>> >

>>
>> Hello David,
>>
>> You propably have a finite set of designations with a short form for each
>> CPA
>> An individual may have multiple of these designations so if you want to

> pick
>> up all that have a CPA designation
>> then use the INSTR() function to capture this set like this
>>
>>
>> select * from directory where INSTR('CPA',designation) > 0 order by

> LastName
>> ASC
>>
>> The html form
>>
>> <select name="designation">
>> <option name="CPA">CPA</option>
>> <option name="CLU">CLU</option>
>> ...
>> </select>
>>
>> And in your language of choice you will need to replace the 'CPA' in the
>> above query string before submitting it to your database.
>>
>> With PHP / MySQL.
>>
>> <?php
>> $dbhost = "localhost";
>> $dbuser = "myuser";
>> $dbpass = "mypassword";
>> $dbname = "mydatabase";
>>
>> $dblink = mysql_connect($dbhost, $dbuser, $dbpass);
>> mysql_select_db($dbname, $dblink);
>> $designation =
>>

> (array_key_exists('designation',$_REQUEST))?$_REQU EST['designation']:"None";
>>
>> $query = "select name,designation,phone from directory where
>> INSTR('".$designation."',designation) > 0 order by LastName ASC";
>> $result = mysql_query($query,$dblink) or die('select from directory

> failed:
>> ' . mysql_error());
>> while($row = mysql_fetch_array($result)) {
>> // echo the list
>> echo $row['name']." ".$row['designation']." ".$row['phone']."<br>";
>> }
>> ?>
>>
>> The second $query would be similar to this assuming PHP and an search
>> form
>> input field name of LastName:
>>
>> $LastName =
>> (array_key_exists('LastName',$_REQUEST))?$_REQUEST ['LastName']:"";
>> $query = "select name,designation,phone from directory where LastName
>> like
>> '".$LastName."%' order by LastName ASC";
>>
>> Hope this gets you off to a running start.
>>
>> Joseph Melnick
>> JM Web Consultants
>> Toronto, ON, Canada
>> http://www.jphp.com/
>>
>>

>
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: , , , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP: SELECT only last last few records that were created within last 5 minutes Neeper Database 0 05-31-2007 7:39 PM
Select while in Bill Y. Barool Database 2 05-31-2007 7:39 PM
Paradise Garage genre vinyl records for sale galafuze Ebay Technical Questions 0 05-31-2007 12:06 AM
Cheap Article Database (54,356 Records) + Free Package Momo Market Place 3 07-10-2006 6:20 AM


Featured Websites




All times are GMT +1. The time now is 12:40 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98