1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

running 2 queries

Discussion in 'PHP' started by gregd1, Jun 12, 2012.

  1. #1
    Hello,
    I am trying to run 1 query then another query.
    It appears like the second query is returning the same data as the first.
    is there some kind of flush that needs to be done?

    thanks


    
     $query = "SELECT address, city, state, zip, depot FROM store WHERE store='$store'";
      $result1 = mysql_query($query) or die ('Invalid Query - Cannot retrieve equipment Type' .mysql_error() );
      $row=mysql_fetch_array($result1);
      $city = $row['city']; 
      $state = $row['state'];
      $zip = $row['zip'];
      $address = $row['address'];
      $depot = $row['depot'];
      
      $query2 = "SELECT address, city, state, zip FROM depot WHERE depot='$depot'";
      $result2 = mysql_query($query2) or die ('Invalid Query2 - Cannot retrieve equipment Type' .mysql_error() );
      $row2=mysql_fetch_array($result2);
      $depotCity = $row['city']; 
      $depotState = $row['state'];
      $depotZip = $row['zip'];
      $depotAddress = $row['address'];
    
    PHP:
     
    gregd1, Jun 12, 2012 IP
  2. gregd1

    gregd1 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    never mind. I just need to update $row
     
    gregd1, Jun 12, 2012 IP
  3. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #3
    That seriously could of been spotted within the first couple minutes of troubleshooting.... Did you even bother to try to figure it out before posting?
     
    NetStar, Jun 13, 2012 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    What you needed to do is keep track of your variable names. You filled $row2 with data, then took the data from $row, which was the data from the first query, which is why you got the same data with the second query.

    You need to establish a method of working. Either use a new variable name each time or reuse your variable names. Don't switch between the two.
     
    Rukbat, Jun 15, 2012 IP