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.

How can I use results from one query in a second query?

Discussion in 'PHP' started by rtblizz, Mar 12, 2012.

  1. #1
    I am retrieving results from a query and trying to insert them into a second query..

    
    
     $sqlstring3 = "SELECT ///// ";
    
        $result2 = mysql_query($sqlstring3);
    
    while ($row = mysql_fetch_array($result2, MYSQL_ASSOC))
        {
    		$strquery .= " ".$row["numbers"].", ";
        }
    	
    	mysql_free_result($result2);
    
    
    PHP:
    that code does this

    213, 321, 123, 221, 321,

    which is great but how do insert that into the next query? I am currently doing this.

    
    
    $query = "select * from ??? where number IN (".$strquery.") order by Value";
    
    
    PHP:

    the problem is it gives me this result.

    
    
    $query = "select * from ??? where number IN (213, 321, 123, 221, 321, ) order by Value";
    
    
    PHP:

    which does not work.. I need to end the query with a 321) not a 321, )

    any help on how to alter this

    
    
    while ($row = mysql_fetch_array($result2, MYSQL_ASSOC))
        {
    		$strquery .= " ".$row["numbers"].", ";
        }
    
    
    PHP:
    to get the last value to do 321) not a 321, )???
     
    Last edited: Mar 12, 2012
    rtblizz, Mar 12, 2012 IP
  2. rtblizz

    rtblizz Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    never-mind I figured it out :)
     
    rtblizz, Mar 12, 2012 IP
  3. rtblizz

    rtblizz Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    never-mind I figured it out..
     
    rtblizz, Mar 12, 2012 IP
  4. bluebenz

    bluebenz Well-Known Member

    Messages:
    876
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    138
    #4
    please tell the solution here so dummies like me know how to do that.
    it's a good for beginner.
     
    bluebenz, Mar 12, 2012 IP
  5. ankit1589

    ankit1589 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you can do so with the implode function of php. more details about it can be found in the documentation.

    Cheers.
     
    ankit1589, Mar 12, 2012 IP
  6. lonelygrit

    lonelygrit Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    add this line
    $strquery .= "0";
    affter line
    mysql_free_result($result2);


     
    lonelygrit, Mar 14, 2012 IP