Forums

messed up again - working thru tutorials!

nancyh 22 Jul, 2011
I started working my way through the "dynamic filters" tutorial and boy, have I messed everything up again!

In the tutorial, you are using "title" and "post". I am trying to order by "company_name" and filter by "County."

I worked through the tutorial, adding code (mostly blindly I admit). Then I went through the complete code at the end and cleaned it up. I never could get County to filter and now my tables are gone.

PLEASE PLEASE PLEASE help. I can see light at the end of the tunnel..just not sure if it's a train or not.

Here's what I have:

WHERE SQL:
<?php
$County = JRequest::getString('County', '', 'post');
if ( $County ) {
echo " WHERE `County` LIKE '%$County%' ";
}
?>


ORDER:
`company_name` ASC


HEADER:
<?php
// get the number of records returned
$db =& JFactory::getDBO();
global $count;
$count = $db->loadResult();

// add style & script snippets
$style = $script = "";
$style .= "

table.cf_listing {
  margin-bottom: 12px;
}
";

$script .= "
$('clear').addEvent('click', function() {
  $('title').value = '';
});
";
$doc =& JFactory::getDocument();
if ( $script ) {
  $script = "window.addEvent('domready', function() { $script });";
  $doc->addScriptDeclaration($script);
}
if ( $style) {
  $doc->addStyleDeclaration($style);
}

<!-- I AM NOT USING TITLE and POST...but want to order by company_name and be able to filter by County -->

// get the previous filter string
$title = JRequest::getString('title', '', 'post');
?>
<!-- display the filter box and buttons -->
<input type='text' name='County' id='County' value='<?php echo $title; ?>' /> <input type='submit' name='filter' id='filter' value='Filter' />
 <input type='button' name='clear' id='clear' value='Clear' />

<!-- start the listing table -->
<table class='cf_listing'>
<?php

// check if there are any records returned
if ( !$count ) {
  // no records - show the message
  echo "<div>Sorry, no results were found.</div>";
} else {
  // some records, show the header & footer rows
?>
<thead>
  <tr>
    <th style='width:250px;'>Company</th>
    <th style='width:5px;'>Website</th>
    <th style='width:20px; margin-left:12px;'>Phone</th>
    <th style='width:100px;'>Address</th>
    <th style='width:100px;'>City</th>
    <th style='width:10px;'>State</th>
    <th style='width:20px;'>Zip</th>
    <th style='width:25px;'>County</th>
  </tr>
</thead>
<tfoot>
  <tr>
    <td colspan='8' style='background:silver; height:4px;'></td>
  </tr>
</tfoot>
<?php
}
?>
<tbody>


BODY:
<tr>
  <td>{company_name}</td>
  <td>{URL}</td>
  <td>{Phone}</td>
  <td>{Street_Address_and_Suite}</td>
  <td>{City},</td>
  <td>{State}</td>
  <td>{Zip_Code}</td>
  <td>{County}</td>
</tr>


FOOTER:
</body>
</table>
<?php
// get the row count and show the pagination if needed
global $count;
if ( $count ) {
?>
{pagination}
<?php
}
?>
</body>
</table>
GreyHead 23 Jul, 2011
Hi Nancy,

There's a little problem with big consequences in the Footer block. You have this code twice
</body>
</table>
It should only be there once and that should be </tbody> (not </body> which ends the whole page). Please change the Footer code to
</tbody>
</table>
<?php
// get the row count and show the pagination if needed
global $count;
if ( $count ) {
?>
{pagination}
<?php
}
?>

Once that is fixed you should get your table back.

Looking at the code I think that the filter by County should work OK. Please post a link to the form so I can take a quick look.

Bob
nancyh 23 Jul, 2011
wow - I don't know what the heck happened. I put that footer code in and that menu item for chrono-connections would only show up grey - not the teal blue I'd selected. (Plus the table was messed up as before.) I ended up deleting the menu item and creating a new one, going back to some older chrono-code without most of the php just the html and I still can't set the color on that menu item. deleted cache, too...am at a loss.

Oh, and I had 4 entries of data and now only 2 show in the table...four in the edit data show up still, but I can't edit.

I've given up on worrying about sorting ... I'll be happy just to get the table showing again with the pagination and my template color back and the ability to edit my data.


hope you can help straighten it out. I'll pm you.

thanks, N
GreyHead 24 Jul, 2011
Hi Nancy,

The CSS problems were the result of a stray 'a' in the Header box CSS snippet
table.cf_listing {
  margin-bottom: 12px;
} a


There are four records showing up for me OK - I don't know what that problem was.

I've added in the code from the Sortable Columns tutorial too.

Bob
nancyh 24 Jul, 2011
THANK YOU! THANK YOU! THANK YOU!

I am seriously close now...going to get pagination working and figure out how to edit my data (blank page shows up)...I think I can search the forums for those solutions hopefully.

MANY MANY MANY thanks to you from this uber-novice.
GreyHead 24 Jul, 2011
Hi Nancy,

Pagination should be working OK. I just hid the paginator if there are less than 25 records showing. Change the Limit to 3 and it should show up again.

Bob
nancyh 24 Jul, 2011
Thanks. Now I just need to solve the 'how to edit records' mystery and I'm good to go! Thanks.

From what I've found, it appears I can't edit from the back; I need to create a form and link to it in admin to edit from the front...sounds easier than it will be for me, I'm sure....
This topic is locked and no more replies can be posted.