Ajax RSS Reader to display feeds automatically


I want to display feeds automatically on my website as it loads without relying on users to select from the options. Thoroughly going through the site, I found the same question on AJAX RSS Reader, but not answered, I reasoned the question wasn’t detailed enough to allow members to give answers. The original source code is here https://www.w3schools.com/php/php_ajax_rss_reader.asp and I am also posting the codes to be detailed as possible HTML:

<select onchange="showRSS(this.value)">
<option value="">Select an RSS-feed:</option>
<option value="Google">Google News</option>
<option value="ZDN">ZDNet News</option>
<div id="rssOutput">RSS-feed will be listed here...</div>

//get the q parameter from URL

//find out which feed was selected
if($q=="Google") {
} elseif($q=="ZDN") {

$xmlDoc = new DOMDocument();

//get elements from "<channel>"
$channel_title = $channel->getElementsByTagName('title')
$channel_link = $channel->getElementsByTagName('link')
$channel_desc = $channel->getElementsByTagName('description')

//output elements from "<channel>"
echo("<p><a href='" . $channel_link
  . "'>" . $channel_title . "</a>");
echo($channel_desc . "</p>");

//get and output "<item>" elements
for ($i=0; $i<=2; $i++) {
  echo ("<p><a href='" . $item_link
  . "'>" . $item_title . "</a>");
  echo ("<br>");
  echo ($item_desc . "</p>");

The news feeds in this code should display automatically as the website loads.


So if you want it to load before a user selects anything, you need to choose the default channel. The if block just needs an else that will be used before any other selection is made.


I have tried to fix it by choosing “Google” as the default channel in the code, added an else to one if block at a time and run the code at each time I changed the if block I added the else to but didn’t get the solution. How do I get it done?

if(!isset($_GET['q'])) {