Jump to content

pouncer

Members
  • Posts

    324
  • Joined

  • Last visited

    Never

Everything posted by pouncer

  1. The html form is built dynamically. <form method ='post' action='index.php' name='rss_record'> <input name='txtRSS_15' type='text' id='txtRSS' size='70' value='http://slashdot.org/rss/slashdot.rss'/> <input name='update' type='submit' value='Update'/> <input name='delete' type='submit' value='Delete'/> <input name='view_rss' type='submit' value='View'/> <input type='hidden' name='rss_id' value='15'> </form>
  2. for e.g whats the difference between @mysql_insert and mysql_insert and for e.g if (!$rss_data = @file_get_contents($link)) { echo "Sorry, no RSS feed was found at <b>$link</b>"; } when i removed the @ from t@file_get_contents the page threw an error. but when i remove the @ from mysql_insert - no error?
  3. if (isset($_POST['update'])) { $rss_id = $_POST['rss_id']; $link = $_POST["txtRSS_" . $rss_id]; updateLink($rss_table, $rss_id, $link); } elseif (isset($_POST['delete'])) { $rss_id = $_POST['rss_id']; deleteLink($rss_table, $rss_id); } elseif (isset($_POST['view_rss'])) { $rss_id = $_POST['rss_id']; $link = $_POST["txtRSS_" . $rss_id]; viewRSS($link); } It's just if statements, but the contents of some of them are the same like the $rss_id variables.
  4. just trying to make the code smaller i guess
  5. /* * Check if an RSS Feed link already exists in the database. */ function rssExists($link, $rss_table) { $check_link = mysql_query("SELECT * FROM `$rss_table` where rsslink='$link'") or die("Query error: <b>". mysql_error()); $rows = mysql_num_rows($check_link); if ($rows == 1) return true; else return false; } Is it possible to do it without using a query?
  6. I've got this code at the to of my index.php <? require_once("database.php"); require_once("functions.php"); $db = new Database(); $db->Connect(); ?> The Connect() method is just the mysql_connect(...) stuff. So everytime I refresh my index.php, is my web app always executing the mysql_connect?? is there a better way to do it so it just connects once when i open the index.php and not again and again...
  7. As part of form validation, i want to throw a msgbox, instead of something like echo "blah blah" i dont want to use javascript incase clientsides have javascript disabled?
  8. I currently use PHP to do this: $rsslink = $_POST['txtRSS']; if ($rsslink == "") echo "<b>You didn't specify any link to add.</b>"; But I want to replace it with javascript and throw a msgbox onto the screen instead. Any ideas anyone?
  9. foreach ($rss_xml->channel->item as $item) { $item_title = $item->title; $item_link = $item->link; $item_description = $item->description; echo " <h3><a href='$item_link'>$item_title</a></h3> <p>$item_description</p> <p><a href='$item_link'>Continue reading $item_title</a></p> \n"; } foreach ($rss_xml->item as $item) { $item_title = $item->title; $item_link = $item->link; $item_description = $item->description; echo " <h3><a href='$item_link'>$item_title</a></h3> <p>$item_description</p> <p><a href='$item_link'>Continue reading $item_title</a></p> \n"; } the only thing that is different is the 'foreach' lines foreach ($rss_xml->channel->item as $item) foreach ($rss_xml->item as $item) but the stuff inside it is the same. so is there a way to cut down the amount of duplicated code?
  10. Brian I hope you can help me, the code you posted now works fine for: http://www.php.net/news.rss but i also want it to work for the likes of http://www.shanedj.com/blog/feed/rss/ too
  11. hmmm i see!! is there a way to make it work for all kinds of rss then? or will the code you posted do that now?
  12. view_rss.php <? $rss_url = "http://www.php.net/news.rss"; if (!$rss_data = @file_get_contents($rss_url)) { echo "<p>No RSS found at $rss_url</p><p>Hmmm thats not meant to happen. RSS Fail!</p>"; } else { $rss_xml = SimpleXML_Load_String($rss_data); $channel_title = $rss_xml->channel->title; $channel_link = $rss_xml->channel->link; foreach ($rss_xml->channel->item as $item) { $item_title = $item->title; $item_link = $item->link; $item_description = $item->description; echo "<h3><a href=\"$item_link\">$item_title</a></h3><p>$item_description</p><p class=\"text_right\"><a href=\"$item_link\">Continue reading $item_title</a></p>\n"; } } ?> Doesn't seem to display nothing for me. but when i try another rss link like $rss_url = "http://www.shanedj.com/blog/feed/rss/"; then it works fine, any ideas whats going wrong guys?
  13. echo " <table border=0> <tr><th bgcolor=#E1E4F2>RSS Feeds getTotalLinks($rss_table)</th></tr> "; how can i make it execute the getTotalLinks($rss_table) function within echo "..." without closing the php tags?
  14. yes i checked that. curl is supported. could you give me that regex?
  15. Ok can someone then tell me a regex to check if the link is actually an appropriate web link then?
  16. function isValidRSSLink($link) { //return true if the link is a valid rss feed link like // www.php.net/news.rss } can someone help me with a function to check if the link is a valid url to a rss feed page? i think all rss feeds end in .xml or .rss ?
  17. how do i make variables global then, so i can use them across other pages too? and also how can i do it so i dnt have to include it in my function
  18. but i want to make $rss_table a global variable so i can use it anywhere in any pages that 'include functions.php', is this possible?
  19. Ok problem seems to be with the table name $rss_table = "rss_links"; function rssExists($link) { $check_link = mysql_query("SELECT * FROM `$rss_table` where rsslink='$link'") or die("Query error: <b>". mysql_error()); $rows = mysql_num_rows($check_link); if ($rows == 1) return true; else return false; } Query error: Incorrect table name '' it doesnt recognise the variable table, why is this?
  20. Ok thanks I removed the $ from the front of the function call. but now i get th: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /dir/Functions.php on line 10 good to go Notice that I do get the 'goof to go' echo though, but why the warning? line 10 in Functions.php is $rows = mysql_num_rows($check_link);
  21. Index.php: <? require_once("Database.php"); require_once("Functions.php"); $db = new Database(); $db->Connect(); ?> <form id="form1" name="form1" method="post" action=""> <label>RSS Feed link: <input name="txtRSS" type="text" id="txtRSS" size="70" /> </label> <label> <input name="add" type="submit" id="add" value="Insert RSS feed into database" /> </label> </form> <p> </p> <p>Current RSS links in the database:</p> <p>You currently have 0 links stored in the database! </p> <? if (isset($_POST['add'])) { $rsslink = $_POST['txtRSS']; if ($rsslink == "") echo "You didn't specify and link to add."; else { if ($rssExists($rsslink)) echo "That RSS link is already in the database."; else echo "good to go"; } } ?> Functions.php: <? $table = "rss_links"; function rssExists($link) { $check_link = mysql_query("SELECT * FROM $table where rsslink='$link'"); $rows = mysql_num_rows($check_link); if ($rows == 1) return true; else return false; } ?> When it's trying to check if the link is already in the database table it givres me this error: Fatal error: Function name must be a string in /dir/index.php on line 29 Line 29 is if ($rssExists($rsslink)) echo "That RSS link is already in the database."; Can anyone see whats wrong?
  22. Yep I mean RSS feed, is there a tutorial on how I can parse it then?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.