Solved

Fixing error on page

Posted on 2014-10-26
10
125 Views
Last Modified: 2014-10-26
Hello,

We have an issue in our code where if a game is not associated with an event it should push our search box up in the space where the event would be at but its throwing an error. Here is an example of what is going on:

http://supercon2k.com/game-roster/persona-4-arena-ultimax/

Here is the code that supports that area:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
//debug($post);
if($post->ec3_schedule[0]->active==1):
$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

$timeString = str_replace('-','',$timeStamp[0]);

$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
endif;
endwhile; ksort($organizeEvents, SORT_NUMERIC); endif; wp_reset_query(); ?>

<?php if(is_array($organizeEvents)): ?>

<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

<?php if(!empty($imgLg)): ?>
<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
</div>
<?php endif; ?>
<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
$time_format=get_option('time_format');
$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
echo $thaTimeStart; ?></p>
</li>


<?php endforeach; $imgLg = array();  ?>
</ul>
</div>
<br />

<?php endif; endif; ?>

Open in new window


What do I need to change in the code to eliminate this error.
0
Comment
Question by:DancingFighterG
  • 6
  • 4
10 Comments
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40404935
it should be something like this.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
//debug($post);
if($post->ec3_schedule[0]->active==1):
$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

$timeString = str_replace('-','',$timeStamp[0]);

$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
endif;
endwhile;
//CHANGE HERE
  if(is_array($organizeEvents): 
       ksort($organizeEvents, SORT_NUMERIC); 
  endif;

// or move this lines to the if below

//END OF CHANGES 
endif; wp_reset_query(); ?>

<?php if(is_array($organizeEvents)): ?>

<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

<?php if(!empty($imgLg)): ?>
<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
</div>
<?php endif; ?>
<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
$time_format=get_option('time_format');
$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
echo $thaTimeStart; ?></p>
</li>


<?php endforeach; $imgLg = array();  ?>
</ul>
</div>
<br />

<?php endif; endif; ?>

Open in new window

0
 

Author Comment

by:DancingFighterG
ID: 40405063
What do I need to change in the code so that if the condition is not true that the header "This game is taking place at:" does not show up

<?php if(is_array($organizeEvents)): ksort($organizeEvents, SORT_NUMERIC); endif; wp_reset_query(); ?>

<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

Open in new window

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40405068
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
//debug($post);
if($post->ec3_schedule[0]->active==1):
$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

$timeString = str_replace('-','',$timeStamp[0]);

$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
endif;
endwhile;
//CHANGE HERE
  if(is_array($organizeEvents): 
       ksort($organizeEvents, SORT_NUMERIC); 
  endif;

// or move this lines to the if below

//END OF CHANGES 
endif; wp_reset_query(); ?>

<?php 
//ANOTHER CHANGE
if(is_array($organizeEvents) && count($organizeEvents) > 0): 
//END OF ANOTHER CHANGE
?>


<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

<?php if(!empty($imgLg)): ?>
<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
</div>
<?php endif; ?>
<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
$time_format=get_option('time_format');
$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
echo $thaTimeStart; ?></p>
</li>


<?php endforeach; $imgLg = array();  ?>
</ul>
</div>
<br />

<?php endif; endif; ?>

Open in new window

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40405070
or another version of the same code

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
//debug($post);
if($post->ec3_schedule[0]->active==1):
$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

$timeString = str_replace('-','',$timeStamp[0]);

$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
endif;
endwhile;

endif;  ?>

<?php 
//ANOTHER CHANGE
if(is_array($organizeEvents) && count($organizeEvents) > 0): 

 ksort($organizeEvents, SORT_NUMERIC); 
 wp_reset_query();
//END OF ANOTHER CHANGE
?>


<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

<?php if(!empty($imgLg)): ?>
<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
</div>
<?php endif; ?>
<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
$time_format=get_option('time_format');
$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
echo $thaTimeStart; ?></p>
</li>


<?php endforeach; $imgLg = array();  ?>
</ul>
</div>
<br />

<?php endif; endif; ?>

Open in new window

0
 

Author Comment

by:DancingFighterG
ID: 40405115
Fooky,

That code breaks the site website.

http://dev.supercon2k.com/game-roster/persona-4-arena/
0
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40405117
paste whole code again which u are using now.
0
 
LVL 11

Accepted Solution

by:
f_o_o_k_y earned 500 total points
ID: 40405125
I have no way to debug or test the code but try this one
<?php 
if ( have_posts() ) : 
	while ( have_posts() ) : the_post(); 
		//debug($post);
		if($post->ec3_schedule[0]->active==1):
			$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

			$timeString = str_replace('-','',$timeStamp[0]);

			$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
		endif;
	endwhile;
endif;  
wp_reset_query();
//ANOTHER CHANGE
if(is_array($organizeEvents) && count($organizeEvents) > 0): 
	ksort($organizeEvents, SORT_NUMERIC); 
//END OF ANOTHER CHANGE
?>

	<h2 class="sidebar">This Game is Taking Place at:</h2>
	<div class="content" id="related-events">
	<ul>
	<?php foreach($organizeEvents as $takingPlace): 
			$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>
			<li>
			<?php if(!empty($imgLg)): ?>
				<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
				<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
				</div>
			<?php endif; ?>
			<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
			$time_format=get_option('time_format');
			$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
			echo $thaTimeStart; ?></p>
			</li>
	<?php endforeach; 
	$imgLg = array();  ?>
	</ul>
	</div>
	<br />

<?php  
endif; 
?>

Open in new window

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40405129
And BTW in the first version of code u posted there are 4 IF statements and 5 ENDIF is this a part of bigger script?
If yes than to my last code add another endif.
0
 

Author Comment

by:DancingFighterG
ID: 40405135
Ok, it works. Thanks bud!!
0
 

Author Closing Comment

by:DancingFighterG
ID: 40405136
Good work!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL Sub-Select Query Returning Duplicate Result 7 45
IP 10.0.1.2 / 255.0.0.0 61 56
jQuery force form POST 7 46
PHP 5.6 and 7.x 4 23
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

860 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