new query field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geraldjr30
    New Member
    • Jan 2009
    • 60

    new query field

    hi,

    i have the following:

    Code:
    $sql="SELECT COUNT(infosection) as TEE FROM tbl_news WHERE dayname ='".$count."'";
    $rs=odbc_exec($conn,$sql);
    if (!$rs)
      {exit("Error in SQL");}
    while (odbc_fetch_row($rs))
    {
      $news=odbc_result($rs, TEE);	
    print "<br>";
    echo $news;
    }
    i am trying to add another field to the query and also a GROUP BY clause. but i cant seem to get it right. I tried:

    Code:
    $sql="SELECT COUNT(infosection) as TEE, shift FROM tbl_news WHERE dayname ='".$count."'";
    $rs=odbc_exec($conn,$sql);
    if (!$rs)
      {exit("Error in SQL");}
    while (odbc_fetch_row($rs))
    {
      $news=odbc_result($rs, TEE, shift);	
    print "<br>";
    echo $shift;
    echo $news;
    }

    not sure what to do...

    thanks in advance,
    geebee
    Last edited by Markus; Jan 12 '09, 03:47 PM. Reason: Added [code] tags. Please read your PMs.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Looking at the manual page for odbc_result, I don't think you can fetch all the rows with one call to it.

    You would probably have to call it once for each field you are trying to collect.

    Comment

    • geraldjr30
      New Member
      • Jan 2009
      • 60

      #3
      ok now i have:

      Code:
      <?php
      $test = array('sunday','monday','tuesday','wednesday','thursday','friday', 'saturday');
      $day=date('w'); //Numeric representation of the day of the week  0 (for Sunday) through 6 (for Saturday)
      $key=each($test);
      while ($key['key']!=$day)
          $key=each($test);
      prev($test);
      prev($test);
      for ($i=0;$i<7;$i++)
      {
          $count = (next($test)) ? current($test) : reset($test);
      
      print "<br>";
      echo $count;
      print "<br>";
      
      
      #################################################
      #DETAIL SECTION
      #################################################
      $conn=odbc_connect('TEST','','');
      if (!$conn)
        {exit("Connection Failed: " . $conn);}
      $sql="SELECT  shift FROM tbl_news WHERE dayname ='".$count."'";
      $rs1=odbc_exec($conn,$sql);
      if (!$rs)
        {exit("Error in SQL");}
      
      while (odbc_fetch_row($rs))
      {
        $SH=odbc_result($rs1, shift);
      print "<br>";
      echo $SH;
      
      }
      
      
      $conn=odbc_connect('TEST','','');
      if (!$conn)
        {exit("Connection Failed: " . $conn);}
      $sql="SELECT  COUNT(infosection) as TEE FROM tbl_news WHERE shift='".$SH."'";
      $rs=odbc_exec($conn,$sql);
      if (!$rs)
        {exit("Error in SQL");}
      
      while (odbc_fetch_row($rs))
      {
        $news=odbc_result($rs,  TEE);
        
      
      print "<br>";
      echo $news;
      
      }
      
      #################################################
      # END OF DETAIL SECTION
      #################################################
      
      print "<br>";
      
      }
      
      ?>
      but i am getting "ERROR IN SQL" on the web page... so what i hoped to achieve is to list each shift, followed by a count for each shit.

      not working...i am really trying to learn this..


      thanks in advance,
      geebee
      Last edited by Markus; Jan 12 '09, 05:37 PM. Reason: Added [code] tags. READ YOUR PMs!

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        See PHP: odbc_errormsg - Manual

        When running queries, while in debugging, you should always use the error functions for your database. It helps a bunch.

        Comment

        • geraldjr30
          New Member
          • Jan 2009
          • 60

          #5
          thanks. i am still learning this, and this is helpful.

          Comment

          Working...