Jump to content

Query fails: Newbie needing help ASAP


Go to solution Solved by Barand,

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.

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.