TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   Query Debugging (http://www.talkphp.com/mysql-databases/3222-query-debugging.html)

Aaron 08-09-2008 04:18 AM

Query Debugging
 
MySQL hates me.
query:
HTML Code:

SELECT * FROM `aaron_eglast`.`egle_post` WHERE `slug`=`html` AND `category`=`HTML` LIMIT 1
Error:
Code:

MySQL said:
#1054 - Unknown column 'html' in 'where clause'

Table XML:
<aaron_eglast>
<!-- Table egle_post -->
<egle_post>
<id>1</id>
<author>Aaron</author>
<last_updated>1</last_updated>
<content>*snip*</content>
<title>Html</title>
<slug>html</slug>
<meta_title>Beginner HTML Tutorial Series</meta_title>
<order>1</order>
<category>HTML</category>
<next>na</next>
<previous>na</previous>
</egle_post>
</aaron_eglast>

so... what is going on here?

delayedinsanity 08-09-2008 05:07 AM

You're using backticks. Use single quotes.

Code:

SELECT *
FROM `aaron_eglast`.`egle_post`
WHERE `slug`='html' AND `category`='HTML'
LIMIT 1


Aaron 08-09-2008 06:18 PM

Mysql Still hates me:
Code:

        $query = "
                SELECT `slug` , `title`
                FROM `aaron_eglast`.`egle_post`
                WHERE `category` = 'HTML'
                ORDER BY `order` ASC";
        $query = mysql_query($query);
        $q = mysql_fetch_array($query);
                        if (mysql_num_rows($q) == 0)
                        throw new exception('For some reason, the other tutorials in this category could not be found.
                        They will not be displayed at the side of this page.');

The query returns properly in PHPmyAdmin, yet it throws an error on the page.

Kalle 08-09-2008 06:46 PM

Its because the if conditional should be:

PHP Code:

if(!mysql_num_rows($query)) 


Aaron 08-09-2008 11:47 PM

This is why you are my idol O.o


All times are GMT. The time now is 02:33 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0