views:

88

answers:

2

Looking for some help with the code below. I think there may be an issue with the way I've organized the php call and function calls. I'm a beginner and am trying to allow users to display results from different tables, depending on what link they click.

I get this error:

Parse error: syntax error, unexpected '{' in /home/content/c/e/l/celebrything/html/wp-content/themes/celebrything/sidebar.php on line 16

Any help in correcting the issue here would be amazing. Here's the code:

<div id="sidebar">

<div class="post">
<h2>

<font color="#333333">Most Popular Celebrities</font><br>
<font color="#333333">in last 24 hours</font>
<br>
<br>

<a href="page.php?table=today">Today</a>
<a href="page.php?table=week">Week</a>
<a href="page.php?table=month">Month</a>

<?php
if (!in_array($table, array('today', 'week', 'month')) {
  return false;
}

global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table);
foreach($result as $row) {
echo '<a href="http://www.celebrything.com/?s=' .
    urlencode($row->name) . '&search=Search">' . $row->name .
    '</a> - ' . $row->count . ' Posts<br/>';
}
}

?>

showTable($_GET['table']);


</h2>
</div>

</div>

<div class="clear"></div>

UPDATED CODE----------------

<div id="sidebar">

<div class="post">
<h2>

<font color="#333333">Most Popular Celebrities</font><br>
<font color="#333333">in last 24 hours</font>
<br>
<br>

<a href="page.php?table=today">Today</a>
<a href="page.php?table=week">Week</a>
<a href="page.php?table=month">Month</a>

<?php
if (!in_array($table, array('today', 'week', 'month'))) {
  return false;
}

global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table);
foreach($result as $row) {
echo '<a href="http://www.celebrything.com/?s=' .
    urlencode($row->name) . '&search=Search">' . $row->name .
    '</a> - ' . $row->count . ' Posts<br/>';
}



if (!empty($_GET['table'])) {
showTable($_GET['table']);

} else { showTable('today'); }

?>




</h2>
</div>

</div>

<div class="clear"></div>
+2  A: 

1. Missing a ) on the first if block

if (!in_array($table, array('today', 'week', 'month'))) {
  return false;
}

2. There is an extra } right before the closing ?>

}
}

?>

3. You need to put the showTable function before the closing ?> like:

showTable($_GET['table']);
?>

In Summary:

Get a code editor that supports syntax highlighting. You will love it.

willoller
Thanks. Now get this error:Parse error: syntax error, unexpected '}' in /home/content/c/e/l/celebrything/html/wp-content/themes/celebrything/sidebar.php on line 27I think there must be an issue with the way I have this organized. Are the php calls, and showTable($_GET['table']); in the right place?
Mike
Thanks. No errors now, but it's not showing results. I've updated my Q above with the new code I'm using. Any ideas?
Mike
you need to change if(empty to if(!empty
Matt Ellen
Updated the code above. Still not working.. Maybe it has something to do with me calling this info from my sidebar.php file? I'm trying to get this info to display in the sidebar, not the main body.
Mike
+2  A: 

Looks to me like you're referencing a function -- showTable() -- but you haven't set up your logic inside function (unless you're leaving something out of the code sample). Should be:

<?
//----------------------
//Create the showTable() function, which won't do anything until it's called. It can
//reside anywhere on the page, really. It's here just because this is where I put it.

function showTable($table) {
   if (!in_array($table, array('today', 'week', 'month'))) {  
      return false;
   }

   global $wpdb;
   $result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table);
   foreach($result as $row) {
      echo('<a href="http://www.celebrything.com/?s='.urlencode($row-&gt;name) . '&search=Search">'.$row->name.'</a> - '.$row->count.' Posts<br/>');
   }
}

//----------------------
//Here is where you actually call the function, to display some stuff on the page

if (!empty($_GET['table'])) {
   showTable($_GET['table']);
} else { 
   showTable('today');
}
?>

The code above assumes that you're using proper/working functions built into Wordpress (I don't know Wordpress very well). But the syntax above should clear up any function syntax related issues, which I think is your main issue.

Dave