text comparison

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toocool

    #1

    text comparison

    Hi, I'm having a problem with one query. My database has the following
    fields: id(int), time(int), and groupfield(enum - 5 possibilities). I
    want to select all the rows where the time is between let's say 12 and
    24 and the group is specified by the user using a html drop list. The
    variable is named $group. Please help me to write that query. Thanx in
    advance. Here's some part of the code for convenience:

    <?php
    if($group != "" && $group != "nic")
    {
    $link=mysql_pco nnect("localhos t", "t00c00l", "") or die ("cannot
    connect");
    mysql_select_db ("t00c00l_uk_db ") or die ("Problem w/ database");
    // and below is my problem... how to add the condition about the
    right group
    $query2="SELECT * FROM pareto WHERE (time<=24 && time>12)";
    $result2=mysql_ query("$query2" ) or die ("No luck this time");
    $array[]= mysql_num_rows( $result2);
    mysql_free_resu lt($result2);

    mysql_close($li nk);
    }
    else
    {
    ?>

    <form action="<? echo $PHP_SELF; ?>" method="post">
    <BR><BR><BR>
    GRUPA: <BR>
    <select name="group">
    <option selected value="nic">-----
    <option value="aaa">aaa
    <option value="bbb">bbb
    <option value="ccc">ccc
    <option value="ddd">ddd
    <option value="eee">eee
    <option value="fff">fff
    </select>
    <input type="submit" value="GO">
    </form>


    <?
    }
    ?>
  • sks

    #2
    Re: text comparison

    Something simple like

    select * from table where time >= 12 and time <= 24 and group=XXX



    [color=blue]
    > Hi, I'm having a problem with one query. My database has the following
    > fields: id(int), time(int), and groupfield(enum - 5 possibilities). I
    > want to select all the rows where the time is between let's say 12 and
    > 24 and the group is specified by the user using a html drop list. The
    > variable is named $group. Please help me to write that query. Thanx in
    > advance. Here's some part of the code for convenience:
    >
    > <?php
    > if($group != "" && $group != "nic")
    > {
    > $link=mysql_pco nnect("localhos t", "t00c00l", "") or die ("cannot
    > connect");
    > mysql_select_db ("t00c00l_uk_db ") or die ("Problem w/ database");
    > // and below is my problem... how to add the condition about the
    > right group
    > $query2="SELECT * FROM pareto WHERE (time<=24 && time>12)";
    > $result2=mysql_ query("$query2" ) or die ("No luck this time");
    > $array[]= mysql_num_rows( $result2);
    > mysql_free_resu lt($result2);
    >
    > mysql_close($li nk);
    > }
    > else
    > {
    > ?>
    >
    > <form action="<? echo $PHP_SELF; ?>" method="post">
    > <BR><BR><BR>
    > GRUPA: <BR>
    > <select name="group">
    > <option selected value="nic">-----
    > <option value="aaa">aaa
    > <option value="bbb">bbb
    > <option value="ccc">ccc
    > <option value="ddd">ddd
    > <option value="eee">eee
    > <option value="fff">fff
    > </select>
    > <input type="submit" value="GO">
    > </form>
    >
    >
    > <?
    > }
    > ?>[/color]


    Comment

    Working...