HELP, php

Discussion in 'OT Technology' started by babygodzilla, Jul 25, 2003.

  1. babygodzilla

    babygodzilla I love rice

    Joined:
    Nov 5, 2001
    Messages:
    3,108
    Likes Received:
    0
    so im using php and querying results from my mySQL DB and thats all fine. after that, this is the structure i have:

    $result[0]:
    -$row01
    -$row02
    -$row03

    $result[1]:
    -$row11
    -$row12
    -$row13

    not completely accurate with the names but you get the idea. now what i want to do is compare the values of each row in $result[0] with each row in $result[1] so i do a

    PHP:
    while($row0 mysql_fetch_array($result[$y], MYSQL_BOTH))
    {
                
    //...do stuff
      
    while($row1 mysql_fetch_array($result[$z], MYSQL_BOTH))
      {
          
    //...do stuff
      
    }
    }
    so now itll access $row01 and compare it to $row11 thru $row13. problem is, when it comes to $row02 and $row03, and it hits the second while loop, the loop will be skipped since the end of $row1 has been reached during the $row01 loop.
    question is, is there a way to move back to $row11 ?
     
  2. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Is it possible to rework your SQL query(es)?

    The only other thing I can think of at the moment is to retrieve all your records/rows for each query and toss them in their own arrays. THEN compare the 2 arrays. I'm wondering if there's other ways to do what you're trying to do, but there isn't enough info to be able to tell...
     
  3. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    yeah u should be able to compair them using sql...

    doing that will

    a) cleaner code
    b) better scaling
    c) easier to remember wtf u were doing 1 year down the line
     
  4. babygodzilla

    babygodzilla I love rice

    Joined:
    Nov 5, 2001
    Messages:
    3,108
    Likes Received:
    0
    yes that's what im doing right now. put them all in a separate array. it's kinda long but it works. is there any shorter way?
     
  5. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    SQL will really be your friend. MySQL almost (but not yet) supports subselects which might fit what you're trying to do. Otherwise, its a matter of rethinking the problem you're trying to solve and finding a smarter way of solving it.

    I'm assuming you are executing two seperate query executions and then trying to compare them. In doing so, you're site is taking a performance hit (2 calls cost more (taker longer) then just 1 call).

    Can you provide more details on the data you're trying to compare? Why are you taking the approach you described above? Do you have access to change the database/table layout (is it even an option)? How comfy are you with SQL?
     
  6. babygodzilla

    babygodzilla I love rice

    Joined:
    Nov 5, 2001
    Messages:
    3,108
    Likes Received:
    0
    i can get my way around SQL. i have a database of classes consisting of, among others, start and end times. my code lets users to choose certain classes, and then check the validity of those choices. one of the things i have to do is check for time-conflicts. so i put all classes chosen by the user in the array $rows. these whiles loops i was using take one row and compare it to all the other rows.

    yes, i have access to the database, and freedom to change it or stuff...
     
  7. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    ahh... Ok. So you're dealing with date/time comparisons...

    Why not do the date comparison from within the SQL query? You could run a query that takes the class time the user is looking to sign up with and see if it conflicts with any of their existing classes by running the query and seeing if it brings back any results (this is just one way of doing it).
     

Share This Page