Query Question

This is a discussion on Query Question within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Can anyone advise me or point me to examples where I might figure out how to populate the pulldown below ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-29-2005
Chris
 
Posts: n/a
Default Query Question

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>
Reply With Quote
  #2 (permalink)  
Old 09-29-2005
thehuby
 
Posts: n/a
Default 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>";

Reply With Quote
  #3 (permalink)  
Old 09-30-2005
cjo
 
Posts: n/a
Default 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
Reply With Quote
  #4 (permalink)  
Old 09-30-2005
Kimmo Laine
 
Posts: n/a
Default Re: Query Question

"cjo" <coverlandNOSPAM914@yahoo.com> wrote in message
news:iijpj1h7r956omvhktpkfapjoqa2h9j727@4ax.com...
> 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...



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


Reply With Quote
  #5 (permalink)  
Old 10-02-2005
cover
 
Posts: n/a
Default Re: Query Question

On Fri, 30 Sep 2005 12:40:35 +0300, "Kimmo Laine"
<antaatulla.sikanautaa@gmail.com.NOSPAM.invalid> wrote:

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


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...
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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



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


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0