Hey guys fairly new to PHP as is, I need to run a PHP function call through an onClick which through my research I have found that I need to use AJAX.

Let me explain better what I am trying to do. I am currently using Simplepie PHP to pull various RSS feeds, I have an HTML DIV tag that loads the titles of the feeds and I want to get to the point where each title is clickable (im assuming this is through onClick) to run a simplepie PHP function to pull the content into a seperate DIV (on the same page).

Im really lost here, I would really appreciate any insight...

Here's a snippet of the code I am currently running:

function printFeed($feedUrl, $imgNumber)
	$feed = new SimplePie();
	$feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/NEW/cache');
	$item = $feed->get_item(0);
	$titleName = $item->get_title();
	$feedDescription = $item->get_content();
	$image = returnImage($feedDescription, $imgNumber);
	$titleImage = scrapeImage($image);
	$Description = Shorten ($item->get_description(), 450);
		echo '<div class="content">';
			echo '<div id="contenthead"><img src="images/contenthead.png"></div>';
			echo '<div id="feedwrap">';
			echo '<div class="fleft"><img src="images/l_border.png"></div>';
			echo '<div class="fright"><img src="images/r_border.png"></div>';
			echo '<div class="fmain">';
				echo '<div class="contentimg">';
				echo '<div id="titlenamewrap">';
				echo $titleName;
				echo '</div>';
                                //In this DIV is where I want the images to change when onClick event gets triggered.
                                //basically I want the value of $titleImage to change when an onClick in the DT DIV gets triggered
				echo '<img src="' .$titleImage. '" width="316" />';
				echo '</div>';
				echo '<div id="desc">';
				echo $Description; 
				echo '</div>';
				echo '<div id="divider"><img src="images/contentdivider.png"></div>';
					echo '<div class="scroll" overflow: auto;>';
					echo '<dl>';
					for($i=0; $i < $feed->get_item_quantity() && $i<10; $i++)
 							$item = $feed->get_item($i);
									echo '<dt>';
									//Currently I am having it echo out, I want to have this as an onClick 
                                                                        //to trigger a simplepie PHP function which will update the contentimg DIV 
                                                                        //Is this possible?	
                                                                        echo $item->get_title();
					echo '</dl>';
					echo '</div>';
			echo '</div>';
		echo '</div>';
		echo '<div id="contentfoot"><img src="images/contentfoot.png"></div>';
		echo '</div>';

I am going to be brutally honest, I didn't read your whole code and I'm not familiar with simplepie php but if I understood your question correctly, you need to use javascript obviously for the onclick function. Either you use ajax or not. With ajax you don't have to refresh the site, without you do. If you have some variables that you need to pass to a function you can have each title's href or location.href have that same site as a link and just pass the variables through a _GET in other words; you are on sample.php and you need to send the value. The href would look something like this: ../sample.php?var=<?php echo $var ?>. So the site will refresh and you just pull the var with the _GET.

Hope this was helpful. If not, follow up and I'll try to help you find another solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.