Jump to content

Query fails: Newbie needing help ASAP


LDMartin1959

Recommended Posts

Working on a WordPress site. I've been again thrown into the deep end of the pool on this. I am trying to add some code to the HEADER.PHP file which will display content under certian conditions. Here's the code in question:
 

$q1=mysql_query("SELECT * FROM 'wp_sean_sponsors' WHERE 'type' LIKE 1 AND 'cat'='.$post->ID.' ");

$row_diamond=mysql_fetch_object($q1);

if ($q1){
          
?>

The problem is that there doesn't seem to be anything coming back from the database. When I do a var_dump of $q1 it comes back as boolen(false), which I am taking to mean it has no value. But I know that a record which matches the criteria exists. I tried replacing '.$post->ID.' with a hard value with no change.

 

I've got no clue where to go next but they're beating me until I come up with a solution.

Link to comment
https://forums.phpfreaks.com/topic/284864-query-fails-newbie-needing-help-asap/
Share on other sites

Consider

CREATE TABLE search_example (category INT PRIMARY KEY,text VARCHAR(20));
INSERT INTO search_example VALUES (1, 'category'),(2, 'description'),(3, 'text');

This next query searches for column category = column text (as expected none found)

mysql> SELECT category FROM search_example WHERE text = category;
Empty set (0.00 sec)

Now we put category string in quotes to tell SQL "this is a string value"

mysql> SELECT category FROM search_example WHERE text = 'category';
+----------+
| category |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

SQL can't know what you intended. It's up to you to be smart enough.

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.