I don't know how to do this..

Discussion in 'PHP' started by adamjblakey, Dec 2, 2007.

  1. #1
    Hi,

    Sorry if this does not make sense but is hard to explain what i am trying to achieve.

    I have a website which has 2 parts to it, one section is where people tell post saying they are going to e.g. city1 on such a date and another section where people can post saying that they want to go to e.g. city1 on such a date.

    What i am trying to do is when a user logs into the website and have posted on section one or two then i want to list any matched items and list them.

    So in code terms what i am trying to do is:

    
    
    $selects = mysql_query("SELECT * FROM table WHERE userid = '$session[id]'");
    $countrows = mysql_num_rows($selects);
    
      if ($countrows > 0){
    
          $results = mysql_query("SELECT * FROM table WHERE city = '???'");
    					
    		$row = mysql_fetch_assoc($results);
    		mysql_free_result($results);
    
                             echo "Match"
         
    
      }
    
    
    Code (markup):
    Cheers,
    Adam
     
    adamjblakey, Dec 2, 2007 IP
  2. Jackel.ca

    Jackel.ca Well-Known Member

    Messages:
    108
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #2
    Is there a reference to the user id on the table that contains city and date?
     
    Jackel.ca, Dec 2, 2007 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Yes in the table there is userid, city and date.
     
    adamjblakey, Dec 2, 2007 IP
  4. krampus

    krampus Active Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #4
    can you describe again what do you need? I didn't understand..
     
    krampus, Dec 2, 2007 IP
  5. Jackel.ca

    Jackel.ca Well-Known Member

    Messages:
    108
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #5
    Rather quick and simple way of doing it..

    
    $query = mysql_query("SELECT * FROM table WHERE userid = '$session[id]' AND date LIKE '%?%' OR city LIKE '%?%'");
    if (mysql_num_rows($query) > 0) {
    	while ($result = mysql_fetch_array($query)) {
    		echo $result['date'] . "/" . $result['city'] . "<br />";
    	}
    }
    
    PHP:
    Modify to fit your desires.
     
    Jackel.ca, Dec 2, 2007 IP
  6. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #6
    Will that work as i cannot see it doing.

    What it needs to do i think.. is go through all the records that a user has and pulls out the city from each record. Then maybe put them into an array and check through all other records to see if any match to this user.
     
    adamjblakey, Dec 3, 2007 IP
  7. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #7
    Any ideas anyone?
     
    adamjblakey, Dec 4, 2007 IP