Solved

PHP Array Syntax Issue

Posted on 2010-08-16
8
401 Views
Last Modified: 2012-05-10
I have a broken search page here:

http://greenwashingindex.com/search.php?

Depending on what browser you use, you will either see the header of the page and then nothing after it, or you will see nothing at all.

I've tracked the problem down to this line:

$adsList = $ads->GetList(array(array("adId",">",0)));

I think there is something wrong with it but am not sure what Eclipse is not giving me any errors.

I've attached the code of the entire page if that will help .

Any suggestions would be greatly appreciated. I have a very tight deadline on this issue.

Thanks,
Lisa


<?php 

$pageClass = "ads"; 
$pageTitle = "Search Results";
include("header.php");

$ads = new Ad();
$adsList = $ads->GetList(array(array("adId",">",0)));

$top_results = array();
$other_results = array();
$bottom_results = array();
$used_values = array();
?>

			<div id="content">

<?php
foreach ($adsList as $theAd) {
	
	$tags_array = explode(",",$theAd->tags);
	foreach($tags_array as $theTag) {

		$tag = new Tag();
		$tag->Get($theTag);
		if (strtolower($tag->tagText) == strtolower($_GET['s']) || strtolower($theAd->companyName) == strtolower($_GET['s'])) {
			array_push($top_results,$theAd);		
			array_push($used_values,$theAd->adId);	
		}//close if
	}//close foreach tag
	
}//close if in tags or company name
	
foreach ($adsList as $theAd) {
		
		if (strpos(strtolower($theAd->Title), strtolower($_GET['s'])) || strpos(strtolower($theAd->Description), strtolower($_GET['s']))) {
			
			if (!in_array($theAd->adId,$used_values)) {
				array_push($other_results,$theAd);
				array_push($used_values,$theAd->adId);
			}//close if
	
		}//close if in title or description
}//close foreach

$search_terms = explode(" ", $_GET['s']);
foreach ($adsList as $theAd) {
	foreach($search_terms as $term) {
		
		if (strpos(strtolower($theAd->Title), strtolower($term)) || strpos(strtolower($theAd->Description), strtolower($term))) {
			
			if (!in_array($theAd->adId,$used_values)) {
				array_push($bottom_results,$theAd);
				array_push($used_values,$theAd->adId);
			}//close if
	
		}//close if in title or description
	}//close foreach search term
}//close foreach

$all_results = array_merge($top_results,$other_results);

?>	

<?php
if (count($all_results) > 0 && count($bottom_results) > 0) {
?>
<h3>Top Results for <?php echo $_GET['s'] . " (" . count($all_results); ?>)</h3>
<?php
}//close if
elseif (count($all_results) > 0) {
?>
<h3>Search Results for <?php echo $_GET['s'] . " (" . count($all_results); ?>)</h3>
<?php	
}


	foreach ($all_results as $theAd) {

		$ratings = new Rating();
		$ratingsList = $ratings->GetList(array(array("AdId","=",$theAd->adId)));
		
		$submitter = new User();
		$submitter->Get($theAd->PostedBy);
	?>			
									<dl>
										<dt><a href="ad_single.php?id=<?php echo $theAd->adId; ?>" title="<?php echo $theAd->Title; ?>"><?php echo $theAd->Title; ?></a></dt>
										
										<dd class="image"><a href="ad_single.php?id=<?php echo $theAd->adId; ?>" title="<?php echo $theAd->Title; ?>">
								<?php
								if ($theAd->Type == "0") {
									embed_video_thumbnail($theAd->URL);
								}//close if video
								if ($theAd->Type == "1") {
									embed_image_thumbnail($theAd->URL, $theAd->Title);
								}//close if image
								?>
								</a></dd>
										
										<dd class="date"><?php echo date("F j, Y", strtotime($theAd->PostedDate)); ?></dd>
										<dd class="user">Submitted by <span><?php echo $submitter->Username; ?></span></dd>
										<dd>Greenwashing Index Rating: <span><?php if ($theAd->AvgRating != 0) { echo round($theAd->AvgRating,2); } else {echo "Not yet rated"; } ?></span></dd>
	<?php if ($theAd->AvgRating != 0) {?>
										<dd><a href="ad_single.php?id=<?php echo $theAd->adId; ?>#ratings" title="Number of ratings"><?php echo count($ratingsList) + 1; ?> rating<?php if (count($ratingsList) != 0) {?>s<?php }?></a></dd>
	<?php } ?>
									</dl>
	
<?php	
   	}//close for each ad
   	if (count($bottom_results) > 0) {

if (count($all_results) <= 0) {
?>
<h3>Search Results for <?php echo $_GET['s'] . " (" . count($bottom_results); ?>)</h3>
<?php
}//close if
else {
?>
<h3><a href="#" title="Show All Results" id="show_all_results">Show All Results (<?php echo count($bottom_results); ?>)</a></h3>
<?php	
}//close else
?>
<div id="more_results" <?php if (count($all_results) > 0) { echo "class='initial_hide'"; } ?>>
	<?php	
	foreach ($bottom_results as $theAd) {

		$ratings = new Rating();
		$ratingsList = $ratings->GetList(array(array("AdId","=",$theAd->adId)));
		
		$submitter = new User();
		$submitter->Get($theAd->PostedBy);
	?>			
									<dl>
										<dt><a href="ad_single.php?id=<?php echo $theAd->adId; ?>" title="<?php echo $theAd->Title; ?>"><?php echo $theAd->Title; ?></a></dt>
										
										<dd class="image"><a href="ad_single.php?id=<?php echo $theAd->adId; ?>" title="<?php echo $theAd->Title; ?>">
								<?php
								if ($theAd->Type == "0") {
									embed_video_thumbnail($theAd->URL);
								}//close if video
								if ($theAd->Type == "1") {
									embed_image_thumbnail($theAd->URL, $theAd->Title);
								}//close if image
								?>
								</a></dd>
										
										<dd class="date"><?php echo date("F j, Y", strtotime($theAd->PostedDate)); ?></dd>
										<dd class="user">Submitted by <span><?php echo $submitter->Username; ?></span></dd>
										<!--<dd><?php echo $theAd->Description; ?></dd>-->
										<dd>Greenwashing Index Rating: <span><?php if ($theAd->AvgRating != 0) { echo round($theAd->AvgRating,2); } else {echo "Not yet rated"; } ?></span></dd>
	<?php if ($theAd->AvgRating != 0) {?>
										<dd><a href="ad_single.php?id=<?php echo $theAd->adId; ?>#ratings" title="Number of ratings"><?php echo count($ratingsList) + 1; ?> rating<?php if (count($ratingsList) != 0) {?>s<?php }?></a></dd>
	<?php } ?>
									</dl>
	
<?php	
   	}//close for each ad
?>
</div><!--close #more_results-->

<?php
   	}//close if more results
   	if (count($all_results) <= 0 && count($bottom_results) <= 0) {
   	?>
   	<h3>No search results</h3>
   	<?php
   	}//close if
?>

			</div><!--close content-->	
			
<?php include("sidebar.php"); ?>	

	<?php include("footer.php"); ?>

Open in new window

0
Comment
Question by:lisacowan
  • 4
  • 4
8 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 33449823
Having looked at your page and run it through the W3C validator, it would seem that part of your page is missing. It stops rather suddenly on line 76

http://validator.w3.org/check?uri=http%3A%2F%2Fgreenwashingindex.com%2Fsearch.php%3F&charset=%28detect+automatically%29&doctype=Inline&ss=1&group=0&verbose=1&user-agent=W3C_Validator%2F1.1

I cannot find the last DIV <div id="content_wrap"> in your source or the one that precedes it so is there other source that you have not included?
0
 

Author Comment

by:lisacowan
ID: 33449922
Test comment.
0
 

Author Comment

by:lisacowan
ID: 33449940
Hmm. Something odd just happened there.

Anyway, thanks for the speedy answer.

The page ends at line 76 when the offending line of PHP is in the file. If I removed it, the entire page renders, but I get no search results. I've attached what the HTML looks like. It doesn't validate perfectly, but there is nothing in there that should keep the page from working.

Thanks,
Lisa
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

	<head>

		<meta http-equiv="content-type" content="text/html; charset=utf-8" />

		<title>The EnviroMedia Greenwashing Index &ndash;  Search Results</title>



		



<!--Daniel's Scripts-->

<script type="text/javascript" src="js/jquery.js"></script>

<script type="text/javascript" src="js/jquery.rotator.js"></script>



<script type="text/javascript" src="js/interface.js"></script>

<script type="text/javascript" src="js/jquery.form.js"></script>

<script type="text/javascript" src="js/jquery.cluetip.js"></script>

<script type="text/javascript" src="js/jquery.dimensions.js"></script>

<script type="text/javascript" src="js/all.js"></script>



<!--swfobject to embed Flash-->

<script type="text/javascript" src="js/swfobject.js"></script>



		<link rel="stylesheet" type="text/css" href="styles/screen.css" media="screen" />



		<link rel="stylesheet" type="text/css" href="js/jquery.cluetip.css" media="screen" />

<!--[if IE]><link rel="stylesheet" type="text/css" href="styles/slider_ie.css" media="screen" /><![endif]-->



<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="styles/ie6.css" media="screen" /><![endif]-->

<!--[if lt IE 8]><link rel="stylesheet" type="text/css" href="styles/ie7.css" media="screen" /><![endif]-->





	</head>

	<body class="ads">

		<div id="wrapper">

			<div id="header">

				<h1 id="home"><a href="index.php" title="EnviroMedia Greenwashing Index, return home" class="home">EnviroMedia Greenwashing Index</a><br />



				<a href="http://www.enviromedia.com" title="EnviroMedia's website" class="esm">Promoted by EnviroMedia Social Marketing</a> <a href="http://www.uoregon.edu/" class="uo">and the University of Oregon</a></h1>



				<!-- UTILITY NAV IF USER IS SIGNED IN -->

				<div id="util_nav_yes">

					<ul>

						<li class="lefty" id="welcome_message">Welcome, lcowan</li><br />

						<li class="lefty"><a href="index.php?action=signout" title="Sign Out">Sign Out</a></li>



					</ul>

				</div>

				

				</div>

				

				<div id="google_search">

					<form action="search.php">

					    <input type="text" name="s" class="search_input" />

					    <input  type="image" src="images/btn_search.gif" class="image_submit image_submit_search" />

					</form>

<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script>



				</div>

				<ul id="global_nav">

						<li id="submit"><a href="submit.php" title="Post an Ad">Post an Ad</a></li>

						<li id="ads"><a href="ads.php" title="View the Ads">View/Rate Ads</a></li>

						<li id="about"><a href="what.php" title="About Greenwashing">About Greenwashing</a></li>

						<li id="news"><a href="news.php" title="In the News">In the News</a></li>

						<li id="commentary"><a href="commentary.php" title="Commentary">Commentary</a></li>



						

				</ul>

		<div id="content_wrap">

			<div id="content">



	



   	<h3>No search results</h3>

   	

			</div><!--close content-->	

			

			<div id="sidebar">

			<div class="rating_scale"> <a href="criteria.php"><img src="images/rating_scale2.png" alt="Greenwashing Index Rating Scale - 1 is a good ad, 3 is the midpoint and the ad is pushing it, 5 is total greenwashing" /></a><br />

				

			</div>



			<div class="about_sub">

			<h3>About Greenwashing</h3>

				<ul class="sidebar">

						<li id="what"><a href="what.php" title="What is Greenwashing?">What is Greenwashing?</a></li>

						<li id="spot"><a href="spot_gw.php" title="How Do I Spot It?">How Do I Spot It?</a></li>

						<li id="why"><a href="why.php" title="Why is Greenwashing a Problem?">Why is Greenwashing a Problem?</a></li>

						<li id="criteria"><a href="criteria.php" title="Greenwashing Index Scoring Criteria">GWI Scoring Criteria</a></li>



						<li id="purpose"><a href="purpose.php" title="Purpose of the Greenwashing Index">Purpose of the GWI</a></li>

				</ul>

			</div>

					

					

					<h3>Get Involved</h3>

					

					<p class="sidebar"><a href="contact.php" title="Sign up on the mailing list">Sign up on our mailing list</a> to stay up-to-date with the Greenwashing Index.</p>



					<h3>Useful Links</h3>



					<ul>

							<!--<li><a href="http://www.google.com/translate_t" title="Google Translate">Translate this page</a></li>-->

							<li><a href="http://www.enviromedia.com/enviroblog" title="Climate Change Starts Here blog">&ldquo;Change Starts Here&rdquo; blog</a></li>

							<li>University of Oregon School of Journalism and Communications: <br />

							<a href="http://jcomm.uoregon.edu/faculty-staff/debmor" title="Dr. Deborah Morrison">Dr. Deborah Morrison, Ph.D.</a><br />

							<a href="http://jcomm.uoregon.edu/faculty-staff/ksheehan" title="Dr. Kim Sheehan">Dr. Kim Sheehan, Ph.D.</a></li>



							<li class="img"><a href="http://www.enviromedia.com" title="EnviroMedia web site"><img src="images/emi_logo.gif" alt="EnviroMedia Social Marketing logo" /></a></li>

					</ul>

							

						

			</div>	



			

		<div id="clearfooter"></div>

		</div>

		</div>

			

			

		<div id="footer">

		

		<ul class="footer_nav">

			<li><a href="rss.php">RSS</a></li>	

			<li><a href="contact.php">Contact</a></li>	

			<li><a href="terms.php">Terms of Use</a></li>	

		</ul>



					

					<p>&copy; 2010 EnviroMedia Social Marketing<br />

					Greenwashing Index is promoted by EnviroMedia Social Marketing in partnership with  the University of Oregon School of Journalism and Communication<br />

					<span>The ads posted and evaluated here are not submitted or rated by EnviroMedia Social Marketing staff and the opinions, views and statements found on this site do not necessarily reflect those of EnviroMedia Social Marketing, its principals or employees.</span></p>

			</div>









<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">



</script>

<script type="text/javascript">

_uacct = "UA-2902130-3";

urchinTracker();

</script>

	

	</body>

</html>

Open in new window

0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 33450475
This line of code

$adsList = $ads->GetList(array(array("adId",">",0)));

might either have an EXIT() in it or be generating a fatal error which effectively kills the output. Try adding this (see below) as the first line after the opening <?php tag, put the "offending" line back in and see what error results.

ini_set('display_errors',1);    error_reporting(E_ALL & ~E_NOTICE);

It's late here, but I'll check back in a while. Post any error messages you come up with.

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 33450572
I'll check this in the morning.
0
 

Author Comment

by:lisacowan
ID: 33450852
It turned out to be a memory error in PHP. We increased the memory allocation, and that did the trick. Thank you so much for your suggestions.

Lisa
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 33452580
Glad you're sorted.
0
 

Author Closing Comment

by:lisacowan
ID: 33495487
I'm accepting this as the answer because turning on the error reporting helped me find the memory issue.

Thanks for the help.

Lisa
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mySql Syntax 7 33
Problem with SqlConnection 5 121
How can I assign SimpleXMLElements to variables? 5 31
resizeing PHP image 2 23
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now