"; } [quote] > > > Hilarion[/quote] [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <11rm22ds74cpa88@news.supernews.com> [htmlstate] => on_nl2br [postusername] => Jim Michaels [ip] => jmichae3@yahoo. [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 6 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) -->"; }[quote] > >[quote] >> >> >> Hilarion[/quote] > >[/quote] [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <11rm22ds74cpa88@news.supernews.com> [htmlstate] => on_nl2br [postusername] => Jim Michaels [ip] => jmichae3@yahoo. [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 8 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> How can I get just one row from selected column? - MySQL

How can I get just one row from selected column? - MySQL

Hi. How can I get just one row from selected column and put it into html dropdown list I tried like this: function pobierz_wszystko($tabela,$kolumna) { $zapytanie="SELECT $kolumna FROM $tabela"; $wynik=mysql_query($zapytanie); while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC )) { echo "<option value=$wiersz>$wiersz</option> <br />"; } } <select name="$hname"> <option value="*" selected >All</option> <?php pobierz_wszystko('hotel','hotel_nazwa'); ?> </select> But it doesn't work properly because I'm getting a dropdown list with All,and Array,Array,Array,Array,Array Instead of Array I'd like to have a value from a row. Is it because I'm using mysql_fetch_array($wynik,MYSQL_ASSOC)? or maybe the query is wrong? Thanks Leszek...

  1. #1

    Default How can I get just one row from selected column?

    Hi.
    How can I get just one row from selected column and put it into html
    dropdown list
    I tried like this:

    function pobierz_wszystko($tabela,$kolumna)
    {
    $zapytanie="SELECT $kolumna FROM $tabela";
    $wynik=mysql_query($zapytanie);
    while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    {
    echo "<option value=$wiersz>$wiersz</option> <br />";
    }
    }

    <select name="$hname">
    <option value="*" selected >All</option>
    <?php
    pobierz_wszystko('hotel','hotel_nazwa');
    ?>
    </select>


    But it doesn't work properly because I'm getting a dropdown list with
    All,and Array,Array,Array,Array,Array
    Instead of Array I'd like to have a value from a row.

    Is it because I'm using mysql_fetch_array($wynik,MYSQL_ASSOC)?
    or maybe the query is wrong?

    Thanks
    Leszek


    Leszek Guest

  2. #2

    Default Re: How can I get just one row from selected column?

    If you use mysql_fetch_array($wynik,MYSQL_NUM)
    you can write $wiersz[0] to access the value.
    Also, if the value contains spaces, your option HTML will probably not
    work as expected.

    Leszek wrote:
    > Hi.
    > How can I get just one row from selected column and put it into html
    > dropdown list
    > I tried like this:
    >
    > function pobierz_wszystko($tabela,$kolumna)
    > {
    > $zapytanie="SELECT $kolumna FROM $tabela";
    > $wynik=mysql_query($zapytanie);
    > while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    > {
    > echo "<option value=$wiersz>$wiersz</option> <br />";
    > }
    > }
    >
    > <select name="$hname">
    > <option value="*" selected >All</option>
    > <?php
    > pobierz_wszystko('hotel','hotel_nazwa');
    > ?>
    > </select>
    >
    >
    > But it doesn't work properly because I'm getting a dropdown list with
    > All,and Array,Array,Array,Array,Array
    > Instead of Array I'd like to have a value from a row.
    >
    > Is it because I'm using mysql_fetch_array($wynik,MYSQL_ASSOC)?
    > or maybe the query is wrong?
    >
    > Thanks
    > Leszek
    >
    >
    Dikkie Dik Guest

  3. #3

    Default Re: How can I get just one row from selected column?

    Leszek wrote:
    > Hi.
    > How can I get just one row from selected column and put it into html
    > dropdown list
    > I tried like this:
    >
    > function pobierz_wszystko($tabela,$kolumna)
    > {
    > $zapytanie="SELECT $kolumna FROM $tabela";
    > $wynik=mysql_query($zapytanie);
    > while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    > {
    > echo "<option value=$wiersz>$wiersz</option> <br />";
    > }
    > }
    >
    > <select name="$hname">
    > <option value="*" selected >All</option>
    > <?php
    > pobierz_wszystko('hotel','hotel_nazwa');
    > ?>
    > </select>
    >
    >
    > But it doesn't work properly because I'm getting a dropdown list with
    > All,and Array,Array,Array,Array,Array
    > Instead of Array I'd like to have a value from a row.
    >
    > Is it because I'm using mysql_fetch_array($wynik,MYSQL_ASSOC)?
    > or maybe the query is wrong?
    >
    > Thanks
    > Leszek
    >
    >
    [url]http://www.php.net/manual/en/function.mysql-fetch-array.php[/url]

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    [email]jstucklexattglobal.net[/email]
    ==================
    Jerry Stuckle Guest

  4. #4

    Default Re: How can I get just one row from selected column?

    Leszek wrote:
    > Hi.
    > How can I get just one row from selected column and put it into html
    > dropdown list
    > I tried like this:
    >
    > function pobierz_wszystko($tabela,$kolumna)
    > {
    > $zapytanie="SELECT $kolumna FROM $tabela";
    > $wynik=mysql_query($zapytanie);
    > while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    > {
    > echo "<option value=$wiersz>$wiersz</option> <br />";
    > }
    > }
    The query is wrong among other things.

    proper: Select $kolumna from $tabela limit 1

    You can also use an offset, reference the manual at
    [url]http://dev.mysql.com/doc/refman/4.1/en/select.html[/url]

    Another thing is, if you are *always* going to want just one result, not
    only should you use the proper select, but you should also limit your code
    to only ask for 1 result:

    $wynik=mysql_query($zapytanie);
    $wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC)
    echo "<option value=$wiersz>$wiersz</option> <br />";

    notice the lack of using a "while" statement, which is not appropriate for 1
    result queries.

    -Dave



    Gazelem Guest

  5. #5

    Default Re: How can I get just one row from selected column?

    >> How can I get just one row from selected column and put it into html
    >> dropdown list
    >> I tried like this:
    >>
    >> function pobierz_wszystko($tabela,$kolumna)
    >> {
    >> $zapytanie="SELECT $kolumna FROM $tabela";
    >> $wynik=mysql_query($zapytanie);
    >> while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    >> {
    >> echo "<option value=$wiersz>$wiersz</option> <br />";
    >> }
    >> }
    >
    > The query is wrong among other things.
    >
    > proper: Select $kolumna from $tabela limit 1
    >
    > You can also use an offset, reference the manual at
    > [url]http://dev.mysql.com/doc/refman/4.1/en/select.html[/url]
    >
    > Another thing is, if you are *always* going to want just one result, not
    > only should you use the proper select, but you should also limit your code
    > to only ask for 1 result:
    >
    > $wynik=mysql_query($zapytanie);
    > $wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC)
    > echo "<option value=$wiersz>$wiersz</option> <br />";
    >
    > notice the lack of using a "while" statement, which is not appropriate for 1
    > result queries.

    I think that Leszek wanted to ask "how can I get just one COLUMN from...",
    in which case LIMIT clause will not be what he looks for.
    As others explained - Leszek used the PHP mysql functions output in
    a wrong way, and it had nothing to do with SQL syntax.


    Hilarion
    Hilarion Guest

  6. #6

    Default Re: How can I get just one row from selected column?


    "Hilarion" <hilarionSPAM.op.SMIECI.pl> wrote in message
    news:dpgdhj$t9k$1news.onet.pl...
    >>> How can I get just one row from selected column and put it into html
    >>> dropdown list
    >>> I tried like this:
    >>>
    >>> function pobierz_wszystko($tabela,$kolumna)
    >>> {
    >>> $zapytanie="SELECT $kolumna FROM $tabela";
    >>> $wynik=mysql_query($zapytanie);
    >>> while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    >>> {
    >>> echo "<option value=$wiersz>$wiersz</option> <br />";
    >>> }
    >>> }
    >>
    >> The query is wrong among other things.
    >>
    >> proper: Select $kolumna from $tabela limit 1
    >>
    >> You can also use an offset, reference the manual at
    >> [url]http://dev.mysql.com/doc/refman/4.1/en/select.html[/url]
    >>
    >> Another thing is, if you are *always* going to want just one result, not
    >> only should you use the proper select, but you should also limit your
    >> code to only ask for 1 result:
    >>
    >> $wynik=mysql_query($zapytanie);
    >> $wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC)
    >> echo "<option value=$wiersz>$wiersz</option> <br />";
    >>
    >> notice the lack of using a "while" statement, which is not appropriate
    >> for 1 result queries.
    >
    >
    > I think that Leszek wanted to ask "how can I get just one COLUMN from...",
    > in which case LIMIT clause will not be what he looks for.
    > As others explained - Leszek used the PHP mysql functions output in
    > a wrong way, and it had nothing to do with SQL syntax.

    Actually, he wanted "just one row from a selected column". If he was
    speaking about a *particular* row, I would suggest a WHERE clause (SELECT
    $kolumna FROM $tablea WHERE id=5), or a counter+if approach.
    I am not sure exactly what it is he is trying to do.. maybe trying to pick
    out a row to put a SELECTED attribute on the <option> on or something?
    (speak up!)
    $count=1;
    while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    {
    echo "<option value=$wiersz>$wiersz</option> <br />";
    if (4==count) {
    do something here
    }
    $count++;
    }

    the problem with this is, how are you going to guarantee that there will
    always be more than 4 rows, if this is what he is really asking?

    And if he is wanting just the first row from a SELECT, yeah, a LIMIT 1 would
    be good to append on the statement. but I would suggest the following code
    below in case you get no rows (you can drop the else part if you want):
    He should remove the <br /> tag out of the <select></select> area - it
    should not be beside an <option> tag. it's illegal - it will really mess
    things up for the browser and you may get inconsistent cross-browser
    renderings. I think maybe what he was trying for was \n instead, which the
    browser ignores, but looks good when viewing code.
    $wynik=mysql_query($zapytanie);
    if ($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC)) {
    echo "<option value=$wiersz>$wiersz</option>\n";
    } else {
    echo "<!--no rows.-->";
    }

    >
    >
    > Hilarion

    Jim Michaels Guest

  7. #7

    Default Re: How can I get just one row from selected column?


    "Leszek" <leszekt80poczta.onet.pl> wrote in message
    news:dp0v53$b4r$1news.onet.pl...
    > Hi.
    > How can I get just one row from selected column and put it into html
    > dropdown list
    > I tried like this:
    >
    > function pobierz_wszystko($tabela,$kolumna)
    you are referencing the array wrong. it should be $wiersz[$kolumna] when you
    want to extract data from the column.
    echo "<option value=$wiersz[$kolumna]>$wiersz[$kolumna]</option> <br
    />";

    > {
    > $zapytanie="SELECT $kolumna FROM $tabela";
    > $wynik=mysql_query($zapytanie);
    > while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    > {
    > echo "<option value=$wiersz>$wiersz</option> <br />";
    > }
    > }
    >
    > <select name="$hname">
    > <option value="*" selected >All</option>
    > <?php
    > pobierz_wszystko('hotel','hotel_nazwa');
    > ?>
    > </select>
    >
    >
    > But it doesn't work properly because I'm getting a dropdown list with
    > All,and Array,Array,Array,Array,Array
    > Instead of Array I'd like to have a value from a row.
    >
    > Is it because I'm using mysql_fetch_array($wynik,MYSQL_ASSOC)?
    > or maybe the query is wrong?
    >
    > Thanks
    > Leszek
    >
    >

    Jim Michaels Guest

  8. #8

    Default Re: How can I get just one row from selected column?


    "Jim Michaels" <jmichae3> wrote in message
    news:sZqdnfGR7oThFEDeRVn-vQcomcast.com...
    >
    > "Hilarion" <hilarionSPAM.op.SMIECI.pl> wrote in message
    > news:dpgdhj$t9k$1news.onet.pl...
    >>>> How can I get just one row from selected column and put it into html
    >>>> dropdown list
    >>>> I tried like this:
    >>>>
    >>>> function pobierz_wszystko($tabela,$kolumna)
    >>>> {
    >>>> $zapytanie="SELECT $kolumna FROM $tabela";
    >>>> $wynik=mysql_query($zapytanie);
    >>>> while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    >>>> {
    >>>> echo "<option value=$wiersz>$wiersz</option> <br />";
    >>>> }
    >>>> }
    >>>
    >>> The query is wrong among other things.
    >>>
    >>> proper: Select $kolumna from $tabela limit 1
    >>>
    >>> You can also use an offset, reference the manual at
    >>> [url]http://dev.mysql.com/doc/refman/4.1/en/select.html[/url]
    >>>
    >>> Another thing is, if you are *always* going to want just one result, not
    >>> only should you use the proper select, but you should also limit your
    >>> code to only ask for 1 result:
    >>>
    >>> $wynik=mysql_query($zapytanie);
    >>> $wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC)
    >>> echo "<option value=$wiersz>$wiersz</option> <br />";
    >>>
    >>> notice the lack of using a "while" statement, which is not appropriate
    >>> for 1 result queries.
    >>
    >>
    >> I think that Leszek wanted to ask "how can I get just one COLUMN
    >> from...",
    >> in which case LIMIT clause will not be what he looks for.
    >> As others explained - Leszek used the PHP mysql functions output in
    >> a wrong way, and it had nothing to do with SQL syntax.

    OOPS! code fix. array referenced wrong. didn't catch this until a later
    post. fixed below.
    >
    >
    > Actually, he wanted "just one row from a selected column". If he was
    > speaking about a *particular* row, I would suggest a WHERE clause (SELECT
    > $kolumna FROM $tablea WHERE id=5), or a counter+if approach.
    > I am not sure exactly what it is he is trying to do.. maybe trying to pick
    > out a row to put a SELECTED attribute on the <option> on or something?
    > (speak up!)
    $count=1;
    while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC ))
    {
    echo "<option value=$wiersz[$kolumna]>$wiersz[$kolumna]</option> <br
    />";
    if (4==count) {
    do something here
    }
    $count++;
    }
    >
    > the problem with this is, how are you going to guarantee that there will
    > always be more than 4 rows, if this is what he is really asking?
    >
    > And if he is wanting just the first row from a SELECT, yeah, a LIMIT 1
    > would be good to append on the statement. but I would suggest the
    > following code below in case you get no rows (you can drop the else part
    > if you want):
    > He should remove the <br /> tag out of the <select></select> area - it
    > should not be beside an <option> tag. it's illegal - it will really mess
    > things up for the browser and you may get inconsistent cross-browser
    > renderings. I think maybe what he was trying for was \n instead, which
    > the browser ignores, but looks good when viewing code.
    $wynik=mysql_query($zapytanie);
    if ($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC)) {
    echo "<option value=$wiersz[$kolumna]>$wiersz[$kolumna]</option>\n";
    } else {
    echo "<!--no rows.-->";
    }
    >
    >
    >>
    >>
    >> Hilarion
    >
    >

    Jim Michaels Guest

Similar Threads

  1. Column chart need column to exceed axis maximum value
    By zanedev in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: May 8th, 04:26 PM
  2. Replies: 1
    Last Post: December 14th, 11:53 AM
  3. get selected column
    By Simon Gorski in forum ASP.NET Data Grid Control
    Replies: 4
    Last Post: January 20th, 09:07 AM
  4. Convert an MS Access Yes/No column to a checkbox column in C# datagrid
    By Gregory Rampton in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: August 6th, 04:09 PM
  5. Replies: 0
    Last Post: July 7th, 08:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •