We help IT Professionals succeed at work.

Joomla - creating extension, why sql statement doesn't work

373 Views
Last Modified: 2009-09-19
I'm learning to create Joomla module. I'm following example in a book and after entering the codes, the sql statement just doesn't work. Any sql statement doesn't work. Does anyone has create any module or component and encounter the same problem?

Here is an easy example...this is the file...don't worry, it's easy to understand. I just want to know why any sql statement whether in this file or other files doesn't work. Perhaps please tell me why the below file sql statement doesn't work...thanks

<?php

//no direct access
defined('_JEXEC') or die('Restricted access');

$db =& JFactory::getDBO();
//Find all empty strings in metakey and metadesc and
//make sure the article is published (state=1)
$where = "(metakey = '' or metadesc = '') and state = 1 ";
$query = "SELECT id, title, metakey, metadesc"
      . " FROM #_content WHERE "
      . $where . " ORDER BY title ASC";
$db->setQuery( $query, 0);
?>

<table class="adminlist">
<tr>
      <td class="title">
            <strong><?php echo JText::_( 'Article' ); ?></strong>
      </td>
      <td class="title">
            <strong><?php echo JText::_( 'Empty Description'); ?></strong>
      </td>
      <td class="title">
            <strong><?php echo JText::_('Empty Keys'); ?></strong>
      </td>
</tr>

<?php
      //Make sure some rows match query
      if ($rows = $db->loadObjectList()) {
            foreach ($rows as $row) {
                  //Create url to allow user to click & jump to edit article
                  $url = "index.php?option=com_content&task=edit&".
                        "&id=" . $row->id;
                  //Check meta fields for record and set Yes/No value
                  if ($row->metadesc == "") $metad = JText::_("Yes");
                        else $metad = JText::_("No");
                  if ($row->metakey =="") $metak = JText::_("Yes");
                        else $metak = JText::_("No");
                  
                  echo "<tr>";
                  //Place article title inside link
                  echo "<td><a href='". $url. "'>".
                        $row->title . "</a></td>";
                  //Display status of empty meta column
                  echo "<td>" . $metad . "</td>";
                  echo "<td>" . $metak . "</td>";
                  echo "</tr>";
            }
      } else {
            //No articles with missing metadata found
            echo '<tr><td>None</td>';
            echo '<td>n/a</td>';
            echo '<td>n/a</td></tr>';

      }

?>
</table>
Comment
Watch Question

Commented:
What Joomla version are you using ? 1.0 or 1.5 ?

Author

Commented:
I'm using 1.5

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
let me check:)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.