Connecting Tech Pros Worldwide Help | Site Map

Query Question

  #1  
Old September 29th, 2005, 03:25 PM
Chris
Guest
 
Posts: n/a
Can anyone advise me or point me to examples where I might figure out
how to populate the pulldown below automatically with a query when the
page is first opened?

I have a database with the dogs names in there that I would very much
like to populate through a db query of that table versus having to
hardcode the box when changes occur. Database name=dogs and
table=dogs_tbl

<html>
<head>
<title>Dog Name Database Query</title>
</head>
<body>
<tr>
<td valign=top align=center width=400>
<font color=white>.</font><br>
<font color=black face=ARIEL><p>
<form method="" action="">
<center>
<table border="1">
<tr>
<td>Dog Name:</td>
<td><select name="dogname">
<option value = "all">All</option>
<option value = "spot">Spot</option>
<option value = "snoopy">Snoopy</option>
<option value = "oscar">Oscar</option> etc...
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit"
value="Submit"></td>
</tr>
</table>
</form><p>
</td>
</tr></table></center><p>
</body>
</html>
  #2  
Old September 29th, 2005, 03:35 PM
thehuby
Guest
 
Posts: n/a

re: Query Question


Something like this should suffice - assuming you are using MySQL
anyway.

HTH

Rick
www.e-connected.com

$conn = mysql_connect( "localhost", "<USERNAME>", "<PASSWORD>" );
mysql_select_db ( "dogs", $conn );

$sql = "SELECT * FROM dogs_tbl";
$rs = mysql_query( $sql, $connection );

$html = "<select name='dogname'>";
while($row = mysql_fetch_row($rs)) {
$dogname = $row['dogname']; //this assumes that the column name is
'dogname'
$html .= "<option value='" .$dogname. "'>" .$dogname. "</option>";
}

$html .= "</select>";

  #3  
Old September 30th, 2005, 06:45 AM
cjo
Guest
 
Posts: n/a

re: Query Question


Used some of the code you posted and got it working - thank you. Is
there a way to keep duplicates out in a query? If you had three
entrys for 'spot', five for 'oscar' and so on, how would you keep the
duplicates out of the query?

Also something I discovered, for the life of me, I couldn't make the
php query code run properly within an html TABLE document (even though
the extension is .php)

I have been using a table type html doc because it looks neater with
the three pulldowns within it.

thanks again for any help...

Chris
  #4  
Old September 30th, 2005, 10:45 AM
Kimmo Laine
Guest
 
Posts: n/a

re: Query Question


"cjo" <coverlandNOSPAM914@yahoo.com> wrote in message
news:iijpj1h7r956omvhktpkfapjoqa2h9j727@4ax.com...[color=blue]
> Used some of the code you posted and got it working - thank you. Is
> there a way to keep duplicates out in a query? If you had three
> entrys for 'spot', five for 'oscar' and so on, how would you keep the
> duplicates out of the query?
>
> Also something I discovered, for the life of me, I couldn't make the
> php query code run properly within an html TABLE document (even though
> the extension is .php)
>
> I have been using a table type html doc because it looks neater with
> the three pulldowns within it.
>
> thanks again for any help...[/color]


Use keyword DISTINCT for that. It reduces duplicates to a single entry.

--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
antaatulla.sikanautaa@gmail.com.NOSPAM.invalid


  #5  
Old October 2nd, 2005, 03:15 PM
cover
Guest
 
Posts: n/a

re: Query Question


On Fri, 30 Sep 2005 12:40:35 +0300, "Kimmo Laine"
<antaatulla.sikanautaa@gmail.com.NOSPAM.invalid> wrote:
[color=blue]
>Use keyword DISTINCT for that. It reduces duplicates to a single entry.[/color]

Worked great - thanks. Also, thanks ALL for emailed & posted replies.

This little project leaves me with one remaining question... So far, I
have a page that when loaded reads a MySQL database column and
populates a dropdown (pulldown) menu. On that page there are input
options for a couple of other things such as the dog's age and owners
name so I end up with variables 'dogname', 'ownername', 'dogage'.

So I have the page loading fine and then I'll type into a text box,
ownername & dogage and click "enter" - for whatever reason, ownername
& dogage show up but the origninal 'dogname' variable apparently has
lost it's data or has not made it.

On my second page that shows what was input to the database, I'm using
$dogname = $_POST['dogname'];
$dogage = $_POST['dogage'];
$ownername = $_POST['ownername'];

with a print command to successfully echo the data entry results to
the screen but again, the original $dogname doesn't appear to make it
since the contents are blank.

After I've successfully queried the database for dogname, how do I
successfully pass along that data with dogage and ownername.

thanks very much for any help...
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Integrated Query Question cover answers 3 January 3rd, 2006 01:55 AM
simple query question: return latest Scott Frankel answers 7 November 23rd, 2005 02:55 AM
Access 2000 "Between" query question Jaycee66 answers 1 November 12th, 2005 07:29 PM
Basic Query Question MX1 answers 3 November 12th, 2005 07:28 PM
sql sub query question with count Spark answers 4 July 20th, 2005 02:12 AM