www.webdeveloper.com
Results 1 to 9 of 9

Thread: [RESOLVED] hopefully, this is last prob with rss feed!

  1. #1
    Join Date
    Aug 2004
    Location
    San Antonio, TX
    Posts
    564

    resolved [RESOLVED] hopefully, this is last prob with rss feed!

    Ok, everything works! almost, lol!

    http://www.childsinc.com/rss <=try it out

    i have added the selected option to my forms to keep track of where you are however when i get a name form the DB like "What's News - US" and it gets placed into the url like "What%27s+News+-+US". This does not cause a problem with actually getting the feed.

    Where the problem is: I can't seem to figure out why i can't GET the type form the url when it looks like this "What%27s+News+-+US" and compare it to the value coming form the DB like "What's News - US"

    therefore, no selected option is echo'd when i GET the type fromt he url and compare it to the DB key?

    i've tried to use urldecode and other functions with no luck, any suggestions?

    if you go here: http://www.childsinc.com/rss/index.p...%27s+News+-+US
    you will see what i mean - they type box defaults back to the first entry coming form the db whereas if you check a different type without any quote or space in the name, it becomes the selected on like it's supposed to be.

    here is all the code: I hope you can use it after we get it fine tuned

    PHP Code:
    <?php 
    session_start
    ();
    include(
    "db_config.php");
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>RSS Feeds</title>
    <style type="text/css">
    <!--
    body {
        background: #000000 url(bg.jpg) repeat-x;
        color: silver;
        font-size: small;
        font-family: Verdana, arial, sans-serif;
    }
    #container {
        width: 800px;
        min-height: 480px;
        position: absolute;
        left: 50%;
        margin-left: -400px;
        margin-top: 10px;
        background-color: #000000;
        border: 1px silver inset;
        color: silver;
    }
    #header {
        width: 798px;
        height: 62px;
        background: #000000 url(header.jpg) no-repeat;
        color: silver;
    }
    #contents {
        padding: 10px;
    }
    -->
    </style>
    </head>
    <body>
    <div id="container">
        <div id="header"></div>
        <div id="contents">
    <?php
        
    echo "\t\t<p><a href='index.php'>Start Over?</a></p>\n";
        
    $rep_str = array("/cnn/i""/fox/i""/msnbc/i");
        
    $with_str = array("CNN""FOX""MSNBC");

        echo 
    "\t\t<p>Please select a source for your RSS Feed:</p>\n";

        echo 
    "\t\t<form action='".$_SERVER['PHP_SELF']."' method='get'>\n\t\t\t<select name='source'>\n";
        foreach(
    db_query("SHOW TABLES FROM $db_name") as $row)
        {
            foreach(
    $row as $value)
            {
                echo 
    "\t\t\t\t<option value='$value' ";
                if (isset(
    $_GET['source']) && $value == $_GET['source']){echo "selected='selected'>";}else{echo">";}
                
    $new_value preg_replace($rep_str$with_strucwords(str_replace("_"" "$value)));
                echo 
    "$new_value</option>\n";
            }
        }
        echo 
    "\t\t\t</select>\n\t\t\t<input type='submit' value='Get Source!' />\n\t\t</form>\n";

    if(isset(
    $_GET['source']))
    {
        
    $new_value preg_replace($rep_str$with_strucwords(str_replace("_"" "$_GET['source'])));

        echo 
    "\t\t<p>Please select the type of feed offered by <strong>".$new_value."</strong></p>\n";

        echo 
    "\t\t<form action='".$_SERVER['PHP_SELF']."' method='get'>\n";
        echo 
    "\t\t\t<input type='hidden' name='source' value='".$_GET['source']."' />\n";
        echo 
    "\t\t\t<select name='type'>\n";
        foreach(
    db_query("SELECT `type`    FROM `{$_GET['source']}`") as $row)
        {
            foreach(
    $row as $value)
            {
                echo 
    "\t\t\t\t".'<option value="'.$value.'"';
                if (isset(
    $_GET['type']) && $value == $_GET['type']){echo "selected='selected'>";}else{echo">";}
                echo 
    "$value</option>\n";
            }
        }
        echo 
    "\t\t\t</select>\n\t\t\t<input type='submit' value='Get it!' />\n\t\t</form>\n";
    }

    if(isset(
    $_GET['source']) && isset($_GET['type']))
    {
        foreach(
    db_query("SELECT `url` FROM `".$_GET['source']."` WHERE `type` = ".'"'.$_GET['type'].'"') as $row)
        {
            foreach(
    $row as $value)
            {
                
    $rssstring file_get_contents($value);
                
    preg_match_all("#<title>(.*?)</title>#s",$rssstring,$titel); 
        
                
    preg_match_all("#<image>(.*?)</image>#s",$rssstring,$images);
                
    $img_num=count($images[0]);

                
    preg_match_all("#<item>(.*?)</item>#s",$rssstring,$items); 
                
    $n=count($items[0]);

                for(
    $i=0;$i<$n;$i++)
                {
                    
    $rsstemp$items[0][$i];
                    
    preg_match_all("#<title>(.*?)</title>#s",$rsstemp,$titles); 
                    
    $title[$i]= $titles[1][0];
                    
    preg_match_all("#<pubDate>(.*?)</pubDate>#s",$rsstemp,$dates); 
                    
    $date[$i]= $dates[1][0];
                    
    preg_match_all("#<link>(.*?)</link>#s",$rsstemp,$links); 
                    
    $link[$i]= $links[1][0];
                }

                for(
    $i=0;$i<$img_num;$i++)
                {
                    
    $rssimg$images[0][$i];
                    
    preg_match_all("#<url>(.*?)</url>#s",$rssimg,$urls); 
                    
    $img_url[$i]= $urls[1][0];
                    
    preg_match_all("#<width>(.*?)</width>#s",$rssimg,$widths); 
                    
    $img_width[$i]= $widths[1][0];
                    
    preg_match_all("#<height>(.*?)</height>#s",$rssimg,$heights); 
                    
    $img_height[$i]= $heights[1][0];
                    
    preg_match_all("#<description>(.*?)</description>#s",$rssimg,$descrip); 
                    
    $img_alt[$i]= $descrip[1][0];
                    
    preg_match_all("#<link>(.*?)</link>#s",$rssimg,$img_links); 
                    
    $img_link[$i]= $img_links[1][0];
                }    

                echo 
    "\t\t<p><a href='$img_link[0]' target='blank'><img src='$img_url[0]' width='$img_width[0]' height='$img_height[0]' title='$img_alt[0]' border='0' /></a></p>\n";
                echo 
    "\t\t<h4>".$titel[1][0]."</h4>\n";    
                echo 
    "\t\t<table cellspacing='5'>\n\t\t\t<tr><th>Date</th><th>Time</th><th>Content</th></tr>\n";
                for(
    $i=0;$i<$n;$i++)
                {
                    
    $timestamp=strtotime($date[$i]);
                    
    $cal=date('Y/m/d'$timestamp);
                    
    $clock=date('H:i'$timestamp);
                    if(!empty(
    $title[$i])) echo "\t\t\t<tr>\n\t\t\t\t<td>".$cal."</td><td>".$clock."</td>\n\t\t\t\t<td><a href=".$link[$i].">".$title[$i]."</a></td>\n\t\t\t</tr>\n";
                }
                echo 
    "\t\t</table>\n";
            }
        }
    }

    function 
    db_query($sql) {

        include(
    "db_config.php");

        
    $conn mysql_connect($db_host$db_user$db_pass);
        if (!
    $conn
        {
               echo 
    "Unable to connect to the database: " mysql_error();
               exit;
        } 
        if (!
    mysql_select_db("$db_name")) 
        {
               echo 
    "Unable to select db_name: " mysql_error();
               exit;
        }
        
    $result mysql_query($sql);
        if (!
    $result
        {
               echo 
    "Could not successfully run query ($sql) from DB: " mysql_error();
               exit;
        }
        if (
    mysql_num_rows($result) == 0
        {
               echo 
    "No rows found.";
               exit;
        }
        while(
    $row mysql_fetch_assoc($result))
        {
                   foreach(
    $row as $key => $value)
                   {
                       
    $results[][$key] = $value;
                   }
        }
        
    mysql_free_result($result);
        
    mysql_close($conn);
        return 
    $results;
    }
    ?>
        </div>
    </div>
    </body>
    </html>

    Answers to all your questions can be found at: PHP Manual

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    use a couple of string replaces to change the " " to "+" and the "'" to "%27"
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,384
    Quote Originally Posted by chazzy
    use a couple of string replaces to change the " " to "+" and the "'" to "%27"
    Or the urlencode() function.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Aug 2004
    Location
    San Antonio, TX
    Posts
    564
    this is the line that determines whether or not to add a selected field:

    PHP Code:
    if (isset($_GET['type']) && $value == $_GET['type']){echo "selected='selected'>";}else{echo">";} 
    $value looks like this = What's News - US
    in the url, it looks like = What%27s+News+-+US

    it shouldn't matter that it looks like that becasue the script still uses that form to retrieve the data from the DB, BUT, why doesn't "What's News - US" == "What%27s+News+-+US" ??

    i have tried to use urlencode, decode, rawurl, http_spec_charc, htmlentit (i am abbreviating of course)

    i can't seem to get $value == $_GET['type'] ?

    Answers to all your questions can be found at: PHP Manual

  5. #5
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    because that's not in urlencode format

    PHP Code:
    $text="What's News - US";
    $text2 strreplace(" ","+",$text);
    $text3 strreplace("'","%27",$text2);
    if(
    $text3 == $value){
    echo 
    $text3;
    echo 
    "\n<br />They're the same";
    echo 
    $value;

    Last edited by chazzy; 04-06-2006 at 08:19 AM.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  6. #6
    Join Date
    Aug 2004
    Location
    San Antonio, TX
    Posts
    564
    I give up!!!!

    I'v tried using str_replace, but I tried it again the same way you suggested Chazzy and it still doesn't work - I think it has something to do with the fact that I have an ' in the string coming form the DB. Other data that has & in it works just fine or even ones with a space between words. They work fine. It's the strings that have the ' in the word that doesnt work properly.

    I tried addslashes moreslashes backslashes noslashes encode decode nocode morecode and I just give up!!

    If you figure this one out I'll send you a Korean cookie!

    Answers to all your questions can be found at: PHP Manual

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,384
    I'm not up to reading all that code right now, but can you put an echo statement or two in to see exactly what the two variables being compared actually are? Something like:
    PHP Code:
    echo "<pre>";
    echo 
    "\$value          = '$value'\n";
    echo 
    "\$_GET['source'] = '{$_GET['source']}'";
    echo 
    "</pre>\n"
    That should make it easier to see exactly what the difference is between the two strings (and using the PRE tags will show any newlines that may be lurking about).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  8. #8
    Join Date
    Aug 2004
    Location
    San Antonio, TX
    Posts
    564
    PHP Code:
    if (isset($_GET['type']) && $value == stripslashes($_GET['type'])){echo "selected='selected'>";}else{echo">";} 

    Answers to all your questions can be found at: PHP Manual

  9. #9
    Join Date
    Aug 2004
    Location
    San Antonio, TX
    Posts
    564
    I think i really screwed something up somewhere because I went back to my original copy (ALWAYS MAKE BACKUPS BEFORE MAKING CHANGES) and added stripslashes, it worked - GRRRR!!!

    Thanks all!

    Answers to all your questions can be found at: PHP Manual

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles