how would I do this?

Discussion in 'PHP' started by cgo85, Oct 4, 2008.

  1. #1
    I've contructed a feed pulling info my db. It's pulling info from 2 tables. The code below basically pulls from table 'tag_cloud' and then pulls from 'zipcode_tag_cloud'. I want to combine this so that it will just pull the most recent from both of them... so not one first, then the other. Would this be possible?

    $sql = "select * from tag_cloud GROUP BY cityurl ORDER BY number DESC";  
    $rs = mysql_query($sql, $conn);  
    while($row=mysql_fetch_array($rs))  {
    $term4 = str_replace("&", " and ", $row['term']);
    echo "<item>\n";
    echo "<title>$term4</title>\n";
    echo "<link>http://www.abcd.com/city/".$row[abbr]."-".$row[countyurl]."-".$row[cityurl].".html</link>\n";
    echo "<guid>http://www.abcd.com/city/".$row[abbr]."-".$row[countyurl]."-".$row[cityurl].".html</guid>\n";
    echo "<description>$term4 has been added to ".$row['cityurl'].",".$row['abbr']."</description>\n";
    echo "</item>\n";
    }
    $sql = "select * from zipcode_tag_cloud GROUP BY zipcode ORDER BY number DESC";  
    $rs = mysql_query($sql, $conn);  
    while($row=mysql_fetch_array($rs))  {
    $term4 = str_replace("&", " and ", $row['term']);
    echo "<item>\n";
    echo "<title>$term4</title>\n";
    echo "<link>http://www.abcd.com/zipcode/".$row[zipcode].".html</link>\n";
    echo "<guid>http://www.abcd.com/zipcode/".$row[zipcode].".html</guid>\n";
    echo "<description>$term4 has been added to zip code ".$row['zipcode']."</description>\n";
    echo "</item>\n";
    }
    echo "</channel>\n";
    echo "</rss>";
    PHP:

     
    cgo85, Oct 4, 2008 IP
  2. cytech

    cytech Guest

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you pulled it using the same query, how would you parse the information once you had it?

    It seems to me you are pulling and displaying two seperate types of data. It would be better to keep it two distinct pulls.

    Why would you like to include it into one query? Are you running into performance issues?
     
    cytech, Oct 4, 2008 IP
  3. cgo85

    cgo85 Peon

    Messages:
    380
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The only reason is because what will happen is rss reader will only end up displaying the first query because most people only get 10 or so results of a feed. In this case, they will never get the results from the second query. Hopefully, you can understand that. Don't know if there is a better way for me to explain.

    Is there a way to maybe show the results from each query every other time. So like qr1, qr2, q1, qr2... etc.

    Maybe more work than it's worth... I could always just LIMIT the results, but I'd really rather not.
     
    cgo85, Oct 4, 2008 IP