Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error in loop perhaps?

    Here is some code that I am having alot of trouble with, and i can't seem to
    figure what what i am doing wrong.

    i want to print out a table. a cell should display 'B' if the query in the database returns a result
    showing that there is a match. Or a cell should display 'A' if the query returns an empty set.


    At the moment, all the cells show 'A' even though there are entries in the database that match.

    I suspect an error in the loop somewhere, but i don't know where.

    Please can anyone help??

    thanks


    PHP Code:

    while ($new_fday <= $tday)
        {
          
          
    $make_date date ("j/n/Y"mktime(0,0,0,$fmonth,$new_fday,$fyear));
          echo 
    "<tr><td><b>$make_date</b></td>";
          while(
    $fromtimex $totime)
          {

            
    $conn mysql_connect();
            
    mysql_select_db("test"$conn);         

            
    $sql "SELECT bookingid FROM booking WHERE roomnum = '$roomsel' and 
            startdate = '$make_date' and  (('$fromtimey' between starttime and endtime) 
            or starttime = '$fromtimey')"
    ;

            
    $result mysql_query($sql$conn) or die(mysql_error());

            
    $num mysql_num_rows($result); // Count number of matching rows        

            
    if($num>0)
            {
            echo 
    "<td>B</td>";
            
            }
              else
              {
               echo 
    "<td>A</td>";
               
              }

            
            
    /*echo "<td>&nbsp</td>";*/
            
    $fromtimex $fromtimex +1;
            
          }
          
    $new_fday $new_fday +1;
          echo 
    "</tr>";
          
    $fromtimex $fromtimey;
        }
    /*end while*/
        
    echo "</table>"

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But the query itself is ok and returns the expected result set? In other words, print out the query, and let it run in phpMyAdmin, and see what kind of results are returned. Apart from that I don't see any syntax errors in the loop.
    De gustibus non est disputandum.

  • #3
    New Coder
    Join Date
    Feb 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i haven't used phpMyAdmin but i have tried the query in mysql
    and i did get the result i expected.

    Is there anything else that could be wrong as to why i dont get the correct display output?

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmh, you could check if the variables $make_date etc. all contain correct values by tracking them during execution of the loop. You could also use var_dump($result) to show you if the selected records actually contain what you expect.

    If that doesn't help, you need to show us the structure of your db tables, and some sample data we can use to test your code on our own servers.
    De gustibus non est disputandum.

  • #5
    New Coder
    Join Date
    Feb 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for your help, i'll give it a try and i'll get back to you with what happens.


  •  

    Posting Permissions

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