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
https://forums.phpfreaks.com/topic/118324-whats-wrong-with-this-statement/
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?

 

 

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.