• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 833
  • Last Modified:

New content in box at every refresh of webpage

Hello all experts.

I have a box in one of my PHP pages that I want fresh content to show up at every re-load of the webpage.

Is there a way to do this without messing with any database...???

I have 20 different snippets of content (picture and text and a link) that needs to rotate everytime you reload the page.  

Also, the first time someone comes to the page the same snippet should not be shown but again a randomized one.

Does anyone have a bit of code that will do this lying around...???

Thanx in advance,

--d.
0
driven_13
Asked:
driven_13
  • 15
  • 14
1 Solution
 
gr8gonzoConsultantCommented:
<?php

$snippets = array();
$snippets[] = "<img src='a.jpg'><br><a href='apage.html'>Content A</a>";
$snippets[] = "<img src='b.jpg'><br><a href='bpage.html'>Content B</a>";
$snippets[] = "<img src='c.jpg'><br><a href='cpage.html'>Content C</a>";

$snippet = $snippets[rand(0,count($snippets)-1)];

echo $snippet;

?>
0
 
gr8gonzoConsultantCommented:
Bear in mind that's just a random selection, so there's a possibility that someone could see the same content twice. If you never want to see the same thing twice until you've seen everything:

<?php
session_start();

if(!isset($_SESSION["seenSnippets"]))
{
  $_SESSION["seenSnippets"] = array();
  $_SESSION["lastSeenSnippet"] = -1;
}

$snippets = array();
$snippets[] = "<a href='apage.html'>Content A</a>";
$snippets[] = "<a href='bpage.html'>Content B</a>";
$snippets[] = "<a href='cpage.html'>Content C</a>";
$snippets[] = "<a href='dpage.html'>Content D</a>";
$snippets[] = "<a href='epage.html'>Content E</a>";
$snippets[] = "<a href='fpage.html'>Content F</a>";
$snippets[] = "<a href='gpage.html'>Content G</a>";

// Exclude seen snippets, resetting when necessary
if(count($_SESSION["seenSnippets"]))
{
	if(count($_SESSION["seenSnippets"]) == count($snippets))
		$_SESSION["seenSnippets"] = array($_SESSION["lastSeenSnippet"]);

	$unseenSnippets = array_diff(array_keys($snippets),$_SESSION["seenSnippets"]);
}

// Pick a random one that hasn't been seen
$snippetIDX = array_rand($unseenSnippets);
$_SESSION["seenSnippets"][] = $snippetIDX;
$_SESSION["lastSeenSnippet"] = $snippetIDX;
$snippet = $snippets[$snippetIDX];

echo $snippet;
?>

Open in new window

0
 
driven_13Author Commented:
gr8gonzo, thanx for your responses.

I like your second solution better but I believe I already have a session running on my page.  I am using the CodeIgniter framework and as I know little to nothing about programming, I don't want to mess anything up.

Any ideas as how to implement this in another way..??

Thanx again.

--d.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
gr8gonzoConsultantCommented:
Instead of $_SESSION["seenSnippets"] just use the CodeIgniter session calls:

$seenSnippets = $this->session->userdata('seenSnippets');
if(!is_array($seenSnippets))
  $seenSnippets = array();

$lastSeenSnippet = $this->session->userdata('lastSeenSnippet');
if(!strlen($lastSeenSnippet))
  $lastSeenSnippet = -1;

$snippets = array();
$snippets[] = "<a href='apage.html'>Content A</a>";
$snippets[] = "<a href='bpage.html'>Content B</a>";
$snippets[] = "<a href='cpage.html'>Content C</a>";
$snippets[] = "<a href='dpage.html'>Content D</a>";
$snippets[] = "<a href='epage.html'>Content E</a>";
$snippets[] = "<a href='fpage.html'>Content F</a>";
$snippets[] = "<a href='gpage.html'>Content G</a>";

// Exclude seen snippets, resetting when necessary
if(count($seenSnippets))
{
	if(count($seenSnippets) == count($snippets))
		$seenSnippets = array($lastSeenSnippet);

	$unseenSnippets = array_diff(array_keys($snippets),$seenSnippets);
}

// Pick a random one that hasn't been seen
$snippetIDX = array_rand($unseenSnippets);
$seenSnippets[] = $snippetIDX;
$lastSeenSnippet = $snippetIDX;
$snippet = $snippets[$snippetIDX];

$this->session->set_userdata('seenSnippets', $seenSnippets);
$this->session->set_userdata('lastSeenSnippet', $lastSeenSnippet);

echo $snippet;
?>

Open in new window

0
 
driven_13Author Commented:
Ok.

But when I used this in my file this is the error code it gave me:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$session

Open in new window

0
 
gr8gonzoConsultantCommented:
Sounds like you aren't far enough into the page to have the session loaded yet. Try adding this before the code:

$this->CI->session = new CI_Session;

Or add "session" to your autoload libraries:

$autoload['libraries'] = array(...other libraries...,'session');
0
 
driven_13Author Commented:
OK, this time there was no error thrown but the page is a blank after this code.  Not even this code is loading and everything under it is white page.

This is the code I am using:

<?php

$this->CI->session = new CI_Session;

$seenSnippets = $this->session->userdata('seenSnippets');
if(!is_array($seenSnippets))
  $seenSnippets = array();

$lastSeenSnippet = $this->session->userdata('lastSeenSnippet');
if(!strlen($lastSeenSnippet))
  $lastSeenSnippet = -1;

$snippets = array();
$snippets[] = "<a href='apage.html'>Content A</a>";
$snippets[] = "<a href='bpage.html'>Content B</a>";
$snippets[] = "<a href='cpage.html'>Content C</a>";
$snippets[] = "<a href='dpage.html'>Content D</a>";
$snippets[] = "<a href='epage.html'>Content E</a>";
$snippets[] = "<a href='fpage.html'>Content F</a>";
$snippets[] = "<a href='gpage.html'>Content G</a>";

// Exclude seen snippets, resetting when necessary
if(count($seenSnippets))
{
	if(count($seenSnippets) == count($snippets))
		$seenSnippets = array($lastSeenSnippet);

	$unseenSnippets = array_diff(array_keys($snippets),$seenSnippets);
}

// Pick a random one that hasn't been seen
$snippetIDX = array_rand($unseenSnippets);
$seenSnippets[] = $snippetIDX;
$lastSeenSnippet = $snippetIDX;
$snippet = $snippets[$snippetIDX];

$this->session->set_userdata('seenSnippets', $seenSnippets);
$this->session->set_userdata('lastSeenSnippet', $lastSeenSnippet);

echo $snippet;
?>

Open in new window

0
 
gr8gonzoConsultantCommented:
What is around this code? Can you post the whole file that contains the above code snippet?
0
 
driven_13Author Commented:
Can I email it to you...??

I hope you understand that I do not want it in the public forum as it has my URL and other stuff.
0
 
gr8gonzoConsultantCommented:
I would suggest making a copy of it and then removing any sensitive information and then posting it, just for consistency's sake. I don't really disclose my personal email address.
0
 
driven_13Author Commented:
Sure Understood.

Below is the code for the page and look at line 436 for the place where your code will be placed.

Thanx again.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

    <!--TAGS-->

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">



    <!--TAGS-->

    <!--CSS STYLING STARTS-->

    <link rel="icon" href="favicon.png" type="image/png">

    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/<?php echo $css;?>">

	  <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/new_style.css">

      <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/voices_style.css">

      <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/footer_style.css">

      

      

      <?php /*?><link rel="stylesheet" type="text/css" href="voices_style.css"><?php */?>

      

      

      

    <!--CSS STYLING ENDS-->

    <title>Read Write Now</title>

    

    

    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery-1.4.2.min.js"></script>

	<script type="text/javascript">

        $(document).ready(function() {

			$("#___plusone_0").css("float","left");

        	$("div.article").click(function(){

                window.location = $(this).attr("url");

                return false;

            });

			loadview('d');

        });

		

		function viewarticle(url){

			window.location = url;

			return false;		

		}

		

		function loadview(viewtype){

		

			$("#mostviewed").html('<div style="margin:auto; width:50px; height:50px;">'+

							'<img src="<?php echo base_url() ?>assets/images/facebox/loading.gif" border="0"></div>');

			$.ajax({

				type:'post',

				url:'<?php echo base_url(); ?>main/articleview',

				data:[{'name':'view_type',value:viewtype}],

				dataType:'text',

				success:function(data){

					$("#mostviewed").html(data);

				},

				error:function(data){

					alert(data);

				}

				

			});

			return false;

		

		}

		

		function submitSearch(){

			var form = document.searchform;

			var search_key = form.search_key.value;

			if(search_key == 'Search'){

				alert('Enter keywords to search');

				return false;

			}

			form.submit();

		}

        </script>

 	

    <style type="text/css">

       



	

	#mostviewed div.article{

		height: auto;

		overflow: hidden;

		text-align: center;

		margin: 1px 1px 1px 5px;

		padding: 1px 1px 1px 5px;

	}	





	span.count{

		float:left;

		width:30px;

		height:18px;

	}

</style>		



</head>



<body>

	<center>

    <div id="PAGE_WRAPPER" style="margin:auto;"><!--PAGE_WRAPPER STARTS-->

        <div id="HEADER"><!--HEADER STARTS-->

            <div style="overflow:hidden; float:left;">

			<div id="LOGO">

           <img src="/assets/images/logos/<?php echo $logo;?>" alt="">

            </div>

			<div style="width:180px;float:left; padding-left: 30px; margin-right: 20px;">

				<div id="FOLLOW_US">

                

					<strong>Follow Us</strong> 

					<br> 

					<div class="follow_box">     

					

							<img src="/assets/new_style_img/fb-sm.gif" width="16" height="16" title="Click to Follow Us on Facebook"  alt="">

				

					</div>                

						

					<div class="follow_box">

		

							<img  src="/assets/new_style_img/twit-sm.gif" width="16" height="16"  title="Click to Follow Us on Twitter" alt="">

		

					</div> 



<div class="follow_box" >					

<!-- Place this tag where you want the +1 button to render -->

   <g:plusone size="small" annotation="none"><g:plusone>
   
    


</div>



<!-- Place this render call where appropriate -->

<script type="text/javascript">

  (function() {

    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;

    po.src = 'https://apis.google.com/js/plusone.js';

    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);

  })();

</script>



               		<div class="follow_box">   

						<a href="/rss">	

							<img src="/assets/new_style_img/rss-sm.gif" width="16" height="16"  title="Click for RSS feed" alt="">

						</a>

					</div>

					   

					<div class="follow_box">   		

						<a href="/">

							<img src="/assets/artimg/homep.gif" title="Click to Refresh Page" width="16" height="16" alt="">

						</a>

					</div>

					<div class="follow_box">   

						<a href="">

						 	<img src="/assets/artimg/ffimg.gif" width="16" height="16" title="Best Viewed Using FireFox 4+" alt="">

						</a> 

					</div>                     

				</div>

				<div style="clear:both"></div>

				<div style="float: left; width:200px; margin-top: 5px; margin-bottom: 5px; margin-left: 0px;">

					<form action="<?php echo base_url(); ?>search/index"  method="post" name="searchform" >

						<input type="text" name="search_key" 

						style="width:120px; margin-left: 5px; height:20px; font-style: italic; font-size: 12px; text-align: center; color: #0000cd; float:left"

						value="Search Grub Street"  onfocus="if(this.value =='Search Grub Street')this.value=''" onBlur="if(this.value =='')this.value='Search Grub Street'">

				<img src="<?php echo base_url();?>assets/images/search.jpg" alt=""

					onClick="submitSearch()" style="cursor:pointer; width:16px; height:16px;" title="Click to Search">	

					</form>

				</div>

			</div>

            

            <?php echo $toplinks; ?>  

            </div>

           

           <!--MENU_TAB STARTS-->

            <div id="MENU_TAB" style="text-align: center;">

                <ul>

                    <li class="tab_links">

                    <a href="<?php echo base_url()?>topics" style="color:#fff; font-weight: 800;">Topics</a></li>

						<?php

						$k=1;

						foreach($topics->result() as $row):

							if($k<=6){

						?>

						<li class="tab_links">

						<a href="<?php echo base_url()?>articles/topic/<?php echo $row->catid ?>/<?php echo $row->urlpart ?>">

						<?php echo $row->title ?></a></li>

						<?php

							}

						$k++;

						endforeach;

						?>

                </ul>

            </div><!--MENU_TAB ENDS-->

            

                    </div><!--HEADER ENDS-->



		<!--RECENT_POPULAR_WRAPPER STARTS-->                    

        <div id="RECENT_POPULAR_WRAPPER">

            <div id="MOST_RECENT">

                <fieldset class="mr_fieldset" style="text-align: left; float: left; width: 300px;">

                <legend class="mr_legend">Most Recent</legend>

                <?php

                    foreach($recent->result() as $row):

                    ?>

                    <li class="article" onClick="document.location.href='<?php echo base_url()?>articles/index/<?php echo $row->articleid ?>/<?php echo $row->urlpart ?>'"  

                    	style="float: left; color:#066"; URL="<?php echo base_url()?>articles/index/<?php echo $row->articleid ?>/<?php echo $row->urlpart ?>">

                        

                        <span class="red_text"><?php echo $row->deck ?>,</span>

                        

                        

                       <span class="blue_text"> <?php echo $row->name ?></span>

                     

						 </li>

                    <?php

                    endforeach;

                    ?>

					</fieldset>

               </div>

  

<div id="the_interview">       

<h2>Grub Street Feature</h2>

<div class="inner_interview" style="margin-top: 5px;">


<!---------------------------------------------------------------->
<!---------------------------------------------------------------->
<!---------------------------------------------------------------->
<!--- THIS IS WHERE THE PHP CODE FOR RANDOMIZED CONTENT WILL GO -->
<!---------------------------------------------------------------->
<!---------------------------------------------------------------->



    <img src="../../../../../assets/artimg/jAten_small.gif" alt="" style="float: left; padding-right: 4px;  margin-bottom: 2px;" height="50" width="50">

<a href="/articles/author/1//32/jennifer-flaten" style="text-decoration: none; margin-right: 0px; color: #2e5877; text-align: left; 

            margin-top: 4px; font-size: 13px; padding-top: 3px; padding-right: 5px;">Jen Aten writes about family life, its amusing or sometimes not so amusing moments. "At least it's not another article on global warming," she says. 
           Jen bakes a mean banana bread and admits to an unusual attraction to balloon animals. Busy preparing for the zombie apocalypse, 
           she still has time to write "As I See It," her witty, too often true column. "My urge to write," says Jen, "is driven by my addiction to cupcakes, with sprinkles on top."           
            [click for more]</a> 


<!---------------------------------------------------------------->
<!---------------------------------------------------------------->
<!-- STOP HERE -->
<!---------------------------------------------------------------->
<!---------------------------------------------------------------->

</div>

</div>



            

             <div id="MOST_POPULAR">

                <fieldset class="mp_fieldset" style="width: 300px;">

                <legend class="mr_legend">Popular Now</legend>

				<div id="mostviewed" style="float: left; width: 250px; overflow: visible; margin-bottom: 0px;">

						<div class="mp_fieldset" style="margin: auto; width: 90px; height: 90px;">

						  <img src="<?php echo base_url() ?>assets/images/facebox/loading.gif"></div>

					</div>

                </fieldset>

				

            </div>

            

</div>

        <!--RECENT_POPULAR_WRAPPER ENDS-->

        

       

			<div id="mainmiddle" style="padding-left: 5px; float: left; margin-bottom: 0px;">

			 

            

                <fieldset class="mid_fieldset"  style=" float:left; width: 290px; text-align: center; margin-left: 20px; margin-right: 10px; padding: 0;">

                <legend class="mid_legend">Interviews</legend>	



					<?php

					$i=0;

                    foreach($interviews->result() as $row):

					$i++;

                    ?>
                    <!--Next line has error at the word style -->

                   <div class="article" style""; url="<?php echo base_url()?>articles/index/<?php echo $row->articleid ?>/<?php echo $row->urlpart ?>">

                        

                        <h1><?php echo $row->deck ?></h1>

                        <h2><?php echo $row->name ?></h2>

                    </div>

                    <?php

                    endforeach;

					if($i==0){

						echo '<div class="no_results">No Results found.</div>';

					}

                    ?>

                   

                  </fieldset>

                  



                <fieldset class="mid_fieldset" style=" float:left; width: 280px; text-align: center; 
                	padding: 0px; margin-left: 17px; margin-right: 27px;">

                <legend class="mid_legend">Reviews</legend>	



					<?php

					$i=0;

                    foreach($reviews->result() as $row):

					$i++;

                    ?>

				   <div class="article" style""; url="<?php echo base_url()?>articles/index/<?php echo $row->articleid ?>/<?php echo $row->urlpart ?>">

                        

                  <h1 class = "red_text"><?php echo $row->deck ?></h1>

                        <h2 class = "blue_text"><?php echo $row->name ?></h2>

                    </div>

                    <?php

                    endforeach;

					if($i==0){

						echo '<div class="no_results">No Results found.</div>';

					}

                    ?>

                  

                  </fieldset>

                 

                  

      

				<fieldset class="mid_fieldset" style=" float:left; width: 290px; text-align: center; padding: 0; margin-left: -10px;">

				<legend class="mid_legend">Profiles</legend>



					<?php

					$i=0;

                    foreach($profiles->result() as $row):

					$i++;

                    ?>

                    <div class="article" url="<?php echo base_url()?>articles/index/<?php echo $row->articleid ?>/<?php echo $row->urlpart ?>">

                        

                        <h1 class = "red_text"><?php echo $row->deck ?></h1>

                        <h2 class = "blue_text"><?php echo $row->name ?></h2>

                    </div>

                    <?php

                    endforeach;

					if($i==0){

						echo '<div class="no_results">No Results found.</div>';

					}

                    ?>

	  </fieldset>

      <div style="clear:both;"></div>

</div>



<!-- XXX --->

<style type="text/css">

<!--

	.teraBoxes h3{background: #006666; color: #FFFFFF; font-size: 16px; margin: 5px 0 5px 15px; 
	padding-left: 3px; text-align: left;}

-->

</style>

<div class="teraBoxes" >

	<div style="float:left;width: 290px; margin:20px 0 20px 20px; padding:4px;">

    	<h3>Voices</h3>

       <div class="inner_profile" style="margin-top: 4px; padding-top: 4px;">

			<div class="inner_profile_text" >

            	<h4 style="color: #228B22;">Jennifer Flaten</h4>

                <?php 

				$result = $this->marticle->get_random_by_author(32,3);

				foreach($result as $row):

					echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

				endforeach;

				?>

            </div>

            <span class="inner_profile_img">

            	<img height="48" width="48" src="../../../../../assets/artimg/jaten_small.gif" alt="">

            </span>

        </div> 

        <div class="inner_profile">

	        <div class="inner_profile_text">

    		    <h4 style="color: #228B22;">David Simmonds</h4>

		        <?php 

				$result = $this->marticle->get_random_by_author(35,3);

				foreach($result as $row):

					echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

				endforeach;

				?>

	        </div>

    	    <span class="inner_profile_img">

        		<img height="48" width="48" src="../../../../../assets/artimg/davids60x70.gif" alt="">

	        </span>

        </div>

		<div class="inner_profile">

			<div class="inner_profile_text">

				<h4 style="color: #228B22;">Jennifer Ramirez</h4>

				<?php 

                $result = $this->marticle->get_random_by_author(120,3);

                foreach($result as $row):

               		echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

                endforeach;

                ?>

            </div>

			<span class="inner_profile_img">

				<img height="48" width="48" src="../../../../../assets/artimg/janedoe-car2.gif" alt="">

			</span>

		</div>                

        <div class="inner_profile">       

            <div class="inner_profile_text" style="margin-top: 10px;">

                <h4 style="color: #228B22; padding: 2px 2px 2px 5px;">M Alan Roberts</h4>

                <?php 

                $result = $this->marticle->get_random_by_author(2,3);

                foreach($result as $row):

               		echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

                endforeach;

                ?>

            </div>

            <span class="inner_profile_img">

           		<img height="48" width="48" src="../../../../../assets/artimg/mar50x50.gif" alt="">

            </span>

        </div>

    </div>

    <div style="float:left;width: 290px; margin: 20px 0 20px 20px; padding:4px;">

    	<h3>Voices</h3>

        

        <div class="inner_profile">

        

        <div class="inner_profile_text">

        <h4 style="color: #228B22;">Matt Seinberg</h4>

        <?php 

        $result = $this->marticle->get_random_by_author(50,3);

        foreach($result as $row):

        echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

        endforeach;

        ?>

        </div>

        <span class="inner_profile_img">

        <img height="48" width="48" src="../../../../../assets/artimg/ms-60x70.gif" alt="">

        </span>

        </div>

        

        <div class="inner_profile">

        

        <div class="inner_profile_text">

        <h4 style="color: #228B22;">Sjef Frenken</h4>

        <?php 

        $result = $this->marticle->get_random_by_author(72,3);

        foreach($result as $row):

        echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

        endforeach;

        ?>

        </div>

        <span class="inner_profile_img">

        <img height="48" width="48" src="../../../../../assets/artimg/sjef09.gif" alt="">

        </span>

        </div>

        

        

        

        <div class="inner_profile">

        

        <div class="inner_profile_text">

        <h4 style="color: #228B22;">Bob Stark</h4>

        <?php 

        $result = $this->marticle->get_random_by_author(91,3);

        foreach($result as $row):

        echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

        endforeach;

        ?>

        </div>

        <span class="inner_profile_img">

        <img height="48" width="48" src="../../../../../assets/artimg/sjef60x70.gif" alt="">

        </span>

        </div>

        

        <div class="inner_profile" style="padding-top: 0px;">

        

        <div class="inner_profile_text" style="padding-top: 2px; padding-bottom: 2px;">

        <h4 style="color: #228B22;">Jane Doe</h4>

        <?php 

        $result = $this->marticle->get_random_by_author(118,3);

        foreach($result as $row):

        echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

        endforeach;

        ?>

        </div>

        <span class="inner_profile_img">

        <img height="48" width="48" src="../../../../../assets/artimg/katcuncar.gif" alt="">

        </span>

        </div>

    </div>

    <div style="float:left;width: 290px; margin:20px 0 20px 20px; padding:4px;">

    	<h3>Voices</h3>

       

		<div class="inner_profile" style="margin-top: 4px; padding-top: 4px;">

		

		<div class="inner_profile_text">

		<h4 style="color: #228B22;">AJ Robinson</h4>

		<?php 

		$result = $this->marticle->get_random_by_author(1,3);

		foreach($result as $row):

		echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

		endforeach;

		?>

		</div>

		<span class="inner_profile_img">

		<img height="48" width="48" src="../../../../../assets/artimg/drew60x70.gif" alt="">

		</span>

		</div>

		

		<div class="inner_profile">

		

		<div class="inner_profile_text" >

		<h4 style="color: #228B22;">M Adam Roberts</h4>

		<?php 

		$result = $this->marticle->get_random_by_author(48,3);

		foreach($result as $row):

		echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

		endforeach;

		?>

		</div>

		<span class="inner_profile_img">

		<img height="48" width="48" src="../../../../../assets/artimg/madam.gif" alt="Grub Street">

		</span>

		</div>

		

		

		<div class="inner_profile" >

		

		<div class="inner_profile_text"   style="margin-bottom: 0px;">

		<h4 style="color: #228B22;">JR Hafer</h4>

		<?php 

		$result = $this->marticle->get_random_by_author(14,3);

		foreach($result as $row):

		echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

		endforeach;

		?>

		</div>

		<span class="inner_profile_img">

		<img height="48" width="48" src="../../../../../assets/artimg//jr-3.gif" alt="">

		</span>

		</div>

		

		

		<div class="inner_profile">

		

		<div class="inner_profile_text" style="padding-top: 2px; padding-bottom: 2px;">

		<h4 style="color: #228B22;">Ricardo Teixeira</h4>

		<?php 

		$result = $this->marticle->get_random_by_author(86,3);

		foreach($result as $row):

		echo '<a href="articles/index/'.$row['articleid'].'/'.$row['urlpart'].'">'.$row['deck'].'</a><br>';

		endforeach;

		?>

		</div>

		<span class="inner_profile_img">

		<img height="48" width="48" src="../../../../../assets/artimg/rt-car.gif" alt="Grub Street">

		</span>

		</div>

    </div>

</div>

<div style="clear:both;"></div>

       

<div style="width:960px; position: relative; text-align: left;">

<!-- START: Habitat for Humanity International - Habitat Supporters Web Banner -->
<a href="https://www.habitat.org" title="Habitat for Humanity International">
<img src="http://www.habitat.org/images/banners/webbanners/728x90_INT_GI1.jpg" alt="Habitat for Humanity Web banners: Get Involved (International)" width="728" height="90" border="0" /></a>
<!-- END: Habitat for Humanity Web banners: Get Involved (International)-->

<!-- Medicine Sans Frontiers -->
<a href="http://www.doctorswithoutborders.org?source=AZD100001D01">
   <img src="http://www.doctorswithoutborders.org/images/share/button_cutout_185x70.png" width="185" height="70" border="none" alt="Support Doctors Without Borders" /></a>





        

        

        

<!--FOOTER STARTS -->

<div id="FOOTER2" style="padding-bottom: 0px;">

<?php echo $footerlinks; ?>  

</div>



<?php /*?><!--

<a href="#" style="text-decoration: none;">Readership</a> &bull;

<a href="#" style="text-decoration: none;">Stats</a> --!><?php */?>

					

        </div><!--FOOTER ENDS-->

    </div><!--PAGE_WRAPPER ENDS-->

  </center>

</body>


</html>

Open in new window

0
 
gr8gonzoConsultantCommented:
Hmmm... could be one of two things.

First try replacing my first line of code with:
$this->session = new CI_Session;
instead of
$this->CI->session....

If that doesn't work, then remove that line altogether and do the autoload approach I suggested.

If that STILL doesn't work, then you might not be in the context of an object instance, so PHP is failing on the variable "$this". You'd have to change all references in my code from $this->session to just $session and use this line at the top:
$session = new CI_Session;
0
 
driven_13Author Commented:
I tried your first and third things.  Both of them gave me the same white page for all the content below this code.

The second thing, the autoload approach, I have no idea what to do and where to go to get this done.

Any help??

Thanx gr8gonzo.

--d.
0
 
gr8gonzoConsultantCommented:
It's in the application/config/autoload.php file.
0
 
driven_13Author Commented:
This is my autoload.php file:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| AUTO-LOADER
| -------------------------------------------------------------------
| This file specifies which systems should be loaded by default.
|
| In order to keep the framework as light-weight as possible only the
| absolute minimal resources are loaded by default. For example,
| the database is not connected to automatically since no assumption
| is made regarding whether you intend to use it.  This file lets
| you globally define which systems you would like loaded with every
| request.
|
| -------------------------------------------------------------------
| Instructions
| -------------------------------------------------------------------
|
| These are the things you can load automatically:
|
| 1. Libraries
| 2. Helper files
| 3. Plugins
| 4. Custom config files
| 5. Language files
| 6. Models
|
*/

/*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your system/application/libraries folder.
|
| Prototype:
|
|	$autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/

$autoload['libraries'] = array('database');


/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
|	$autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Plugins
| -------------------------------------------------------------------
| Prototype:
|
|	$autoload['plugin'] = array('captcha', 'js_calendar');
*/

$autoload['plugin'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Config files
| -------------------------------------------------------------------
| Prototype:
|
|	$autoload['config'] = array('config1', 'config2');
|
| NOTE: This item is intended for use ONLY if you have created custom
| config files.  Otherwise, leave it blank.
|
*/

$autoload['config'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Language files
| -------------------------------------------------------------------
| Prototype:
|
|	$autoload['language'] = array('lang1', 'lang2');
|
| NOTE: Do not include the "_lang" part of your file.  For example 
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
*/

$autoload['language'] = array();


/*
| -------------------------------------------------------------------
|  Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
|	$autoload['model'] = array('model1', 'model2');
|
*/

$autoload['model'] = array();



/* End of file autoload.php */
/* Location: ./system/application/config/autoload.php */

Open in new window

0
 
gr8gonzoConsultantCommented:
Look on line 42.
Change that to:

$autoload['libraries'] = array('database','session');
0
 
driven_13Author Commented:
Ok, after that which set of code do you want me to use on the actual page..??  There has been so  many different versions that I am a little confused...[:0)
0
 
gr8gonzoConsultantCommented:
Just use the code I posted in # 38329853
0
 
driven_13Author Commented:
OK, the whole page is now loading fine but the spot where this code is supposed to display the revolving content, this is the error it is displaying:

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: unseenSnippets
Filename: views/vmain.php
Line Number: 511

A PHP Error was encountered
Severity: Warning
Message: array_rand() [function.array-rand]: First argument has to be an array
Filename: views/vmain.php
Line Number: 511

A PHP Error was encountered
Severity: Notice
Message: Undefined index: 
Filename: views/vmain.php
Line Number: 514

Open in new window


error
0
 
gr8gonzoConsultantCommented:
54th time's the charm.

$seenSnippets = $this->session->userdata('seenSnippets');
if(!is_array($seenSnippets))
  $seenSnippets = array();

$lastSeenSnippet = $this->session->userdata('lastSeenSnippet');
if(!strlen($lastSeenSnippet))
  $lastSeenSnippet = -1;

$snippets = array();
$snippets[] = "<a href='apage.html'>Content A</a>";
$snippets[] = "<a href='bpage.html'>Content B</a>";
$snippets[] = "<a href='cpage.html'>Content C</a>";
$snippets[] = "<a href='dpage.html'>Content D</a>";
$snippets[] = "<a href='epage.html'>Content E</a>";
$snippets[] = "<a href='fpage.html'>Content F</a>";
$snippets[] = "<a href='gpage.html'>Content G</a>";

// Exclude seen snippets, resetting when necessary
$unseenSnippets = array_keys($snippets);
if(count($seenSnippets))
{
	if(count($seenSnippets) == count($snippets))
		$seenSnippets = array($lastSeenSnippet);

	$unseenSnippets = array_diff($unseenSnippets,$seenSnippets);
}

// Pick a random one that hasn't been seen
$snippetIDX = array_rand($unseenSnippets);
$seenSnippets[] = $snippetIDX;
$lastSeenSnippet = $snippetIDX;
$snippet = $snippets[$snippetIDX];

$this->session->set_userdata('seenSnippets', $seenSnippets);
$this->session->set_userdata('lastSeenSnippet', $lastSeenSnippet);

echo $snippet;
?>

Open in new window

0
 
driven_13Author Commented:
Hahaha...I hear you.

Thank you for sticking with it.  I would be lost otherwise.

Ok, I think we are almost there.  

All the page is loading with no errors.  Just the actual revolving content is not showing up.

I have attached a pic below.

blank
0
 
gr8gonzoConsultantCommented:
Hmm.... try changing:

echo $snippet;

to:

echo "<pre>";
echo $snippetIDX;
print_r($snippets);
echo "</pre>";

See what the output is there. I'm going to guess that something in $snippets is messing up.
0
 
driven_13Author Commented:
Home stretch....[:0)

It is displaying more than it should.

Pic attached.

array
0
 
gr8gonzoConsultantCommented:
Actually, I think it was working before. :) Do you happen to have any CSS styling applied to links that might make them nearly-white in that section? (Use Firebug's CSS inspector to help find the rule if you need to)

Try changing the snippets to something else besides an HTML link, and see what shows up.

At this point, you should be able to just change $snippets to contain whatever content you want, and it should rotate properly. You can put the bottom part of the code back to just echo $snippet
0
 
driven_13Author Commented:
You are indeed correct sir.

Thank you SO much for all your patience and help.  You deserve the 500 points and more...[:0)

The change you made to the autoload.php file will not break anything elsewhere, will it..??? A bit paranoid about such things.

Indebted to you.

--d.
0
 
driven_13Author Commented:
Unbelieveable patience.  Knows his stuff front and back.  Lucky to have him help me out.
0
 
gr8gonzoConsultantCommented:
Nope, that's what is preventing that first error from showing up. :) All it does is automatically load the session if it's not already loaded whenever it's requested.
0
 
driven_13Author Commented:
Aarrggg...I have one more follow-up question:

The snippets are actually a paragraph of text and a picture.

What would I need to do so that it is easier to maintain them if there are say TEN of them....???

Is there even an easier way to maintain it...???

Thanx gr8gonzo.

--d.
0
 
gr8gonzoConsultantCommented:
Hmm. You could put each HTML snippet into its own HTML file and name them something like snippet_1.html and snippet_2.html and so on. Then replace the chunk that defines the snippets:

$snippets = array();
$snippets[] = ... bla bla bla ...
...etc...

With something like this:

$snippets = array();
$allSnippetFiles = glob("snippet_*.html");
foreach($allSnippetFiles as $snippetFile)
{
  $snippets[] = file_get_contents($snippetFile);
}
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 15
  • 14
Tackle projects and never again get stuck behind a technical roadblock.
Join Now