Jump to content

What's wrong with this statement?


jo.nova

Recommended Posts

Hi,

 

Can anyone find something wrong with this statement?

 

//store the current section id
$secNum = $secResult[$i]->id;

//check value
echo "Section: " . $secNum . "<br /><br />";

//set query
$sql = "SELECT * FROM #__categories WHERE section = $secNum GROUP BY id ORDER BY ordering";

//get results
$database->setQuery($sql) or die ('Could not set category query');
$catResult = $database->loadObjectList()  or die ('Could not load category object list');

 

It fails every time. Here's the output:

 

Section: 1

 

Could not set category query

 

The statement runs fine when run through phpMyAdmin, except I have tweak the table prefixes because of the DB object abstraction.

 

Any ideas?

 

 

Link to comment
Share on other sites

why not error check the query

 

<?php
//store the current section id
$secNum = $secResult[$i]->id;

//check value
echo "Section: " . $secNum . "<br /><br />";

//set query
$sql = "SELECT * FROM #__categories WHERE section = $secNum GROUP BY id ORDER BY ordering";

//get results
$database->setQuery($sql) or die (mysql_error()."<br /><br />".$sql);
$catResult = $database->loadObjectList()  or die ('Could not load category object list');

 

It fails every time. Here's the output:

 

Section: 1

 

Could not set category query

 

The statement runs fine when run through phpMyAdmin, except I have tweak the table prefixes because of the DB object abstraction.

 

Any ideas?

 

 

Link to comment
Share on other sites

Well, first of all, I'm not an expert, so some more specific error checking advice would be appreciated.  How would I use mysql_error() if I'm building queries and feeding them to a database object, instead of talking directly to the database?

Link to comment
Share on other sites

Well, first of all, I'm not an expert, so some more specific error checking advice would be appreciated.  How would I use mysql_error() if I'm building queries and feeding them to a database object, instead of talking directly to the database?

I'm not sure what you mean... but can we see the error?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.