SELECT DISTINCT into a Drop Box question
Moderator: General Moderators
SELECT DISTINCT into a Drop Box question
Hello everyone,
The query I am running is this:
"SELECT DISTINCT weekending FROM reports"
When I run it directly in the database I get several results back:
[weekending]
|6/13/2009|
|6/6/2009|
...
That part works fine, what I have a question about is how would I get the above data into a drop box to be selected. When I try to return it back from the fuction that query is in I only get ([weekending] => 6/13/2009) back.
Thanks for the help in advance!
The query I am running is this:
"SELECT DISTINCT weekending FROM reports"
When I run it directly in the database I get several results back:
[weekending]
|6/13/2009|
|6/6/2009|
...
That part works fine, what I have a question about is how would I get the above data into a drop box to be selected. When I try to return it back from the fuction that query is in I only get ([weekending] => 6/13/2009) back.
Thanks for the help in advance!
-
spider.nick
- Forum Commoner
- Posts: 72
- Joined: Wed Jul 15, 2009 12:22 pm
- Location: Overland Park, KS
Re: SELECT DISTINCT into a Drop Box question
Post your code back on the forum; however, it sounds like you are not doing something like:hwmetzger wrote:Hello everyone,
The query I am running is this:
"SELECT DISTINCT weekending FROM reports"
When I run it directly in the database I get several results back:
[weekending]
|6/13/2009|
|6/6/2009|
...
That part works fine, what I have a question about is how would I get the above data into a drop box to be selected. When I try to return it back from the fuction that query is in I only get ([weekending] => 6/13/2009) back.
Thanks for the help in advance!
Code: Select all
while( $row = mysql_fetch_array($result) )
Re: SELECT DISTINCT into a Drop Box question
Code: Select all
function get_list()
{
$sql = "SELECT DISTINCT weekending FROM report";
$result = mysql_query($sql);
$item = mysql_fetch_assoc($result);
return $item;
}
But this only returns 1 date instead of 2.
Re: SELECT DISTINCT into a Drop Box question
That's correct. The function mysql_fetch_assoc() always returns exactly ONE ROW. When you use it again against the same result, it returns THE NEXT ROW, etc. So you need to call it in a loop to get all the results, one at a time.hwmetzger wrote:That is what I have so far, I have no idea where to go from there.Code: Select all
function get_list() { $sql = "SELECT DISTINCT weekending FROM report"; $result = mysql_query($sql); $item = mysql_fetch_assoc($result); return $item; }
But this only returns 1 date instead of 2.
http://us.php.net/mysql_fetch_assoc
Re: SELECT DISTINCT into a Drop Box question
So would I do something like:
Code: Select all
function get_list()
{
$sql = "SELECT DISTINCT weekending FROM report";
$result = mysql_query($sql);
while ($item = mysql_fetch_assoc($result) )
return $item;
}
-
spider.nick
- Forum Commoner
- Posts: 72
- Joined: Wed Jul 15, 2009 12:22 pm
- Location: Overland Park, KS
Re: SELECT DISTINCT into a Drop Box question
Nope. Try it yourself [i.e. - apply the code to your project and see if it functions correctly], and *then* post back about problems.hwmetzger wrote:So would I do something like:
Code: Select all
function get_list() { $sql = "SELECT DISTINCT weekending FROM report"; $result = mysql_query($sql); while ($item = mysql_fetch_assoc($result) ) return $item; }
Nick
Re: SELECT DISTINCT into a Drop Box question
The manual reference I gave you has examples to do exactly what you're asking.
You are probably thinking, "Why don't these guys just give me the answer?" Let me tell you why we don't. If our purpose was to offer to code your job for you, there would be few, if any, volunteers. We do get satisfaction from TEACHING people how to do it themselves. It's like the old saying, "Give a man a fish and you feed him for a day. Teach him how to fish and you feed him for life."
You are probably thinking, "Why don't these guys just give me the answer?" Let me tell you why we don't. If our purpose was to offer to code your job for you, there would be few, if any, volunteers. We do get satisfaction from TEACHING people how to do it themselves. It's like the old saying, "Give a man a fish and you feed him for a day. Teach him how to fish and you feed him for life."
Re: SELECT DISTINCT into a Drop Box question
I figgured it out, http://us.php.net/mysql_fetch_assoc didn't help at all