Member Avatar for leadcrumb

Wordpress - I want to use a title condition for displaying info on a page, from a MySQL table "country".
The condition must compare the title with the names in the column "name" and when it match a value than display on the page the text from column "description" from the same row with the matching value. Example : title(USA)=column name (USA) get/fetch column (description) (the description from row USA).
I had tryed a code

<?php
    $page_name = $wp_query->post->post_name;
    query_posts('category_name='. $page_name);
?>
<?php global $wpdb;
$result = $wpdb->get_row ("SELECT name FROM country WHERE parent IN (SELECT parent FROM country WHERE name == '$page_name'"));
if ($result->num_rows == 0) {   
   echo '<div>No matches found</div>'; 
} else {   
    $i = 0;
    while ($row = $result->fetch_row(description)) {
        if ($row["name"] == '1') {
           echo '<div id="description' . $i . '"></div>'; 
        }
       $i++;
    }

  echo $result->description;

}
?>

I have foud hier a code to display the title

<?php echo get_the_title($ID); ?>

and a code to use the title condition

<?php
$title = the_title('', '', false);
if($title == 'conditional post title'){
// your stuff here
}
?>

There is a little typo at line 6, the closing parenthesis is after the double quote, so it is outside the query expression. Change it with this:

$wpdb->get_row("SELECT name FROM country WHERE parent IN (SELECT parent FROM country WHERE name == '$page_name')");

Also '==' does not exist in MySQL. Use '=' (unlike JS, PHP, C C++ Java...)

commented: good catch! +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.