I am trying something here, I want to make a condition that allows me to fetch an info from a row in a Mysql if the page title is the same with a value from table “names”/column “lastname”. Here I had made a table “names”
The “firstname” column would be unique in this table.
+---------+-----------+----------+
| id | firstname | lastname |
+---------+-----------+----------+
| 1 | John | Smith |
| 2 | Jane | Smith |
| 3 | Jimbo | Jones |
| 4 | Andy | Smith |
| 7 | Chris | Jones |
| 45 | Anna | Bell |
| 44 | Jimmy | Carr |
| 43 | Albert | Smith |
| 47 | Johnna | Doe |
+---------+-----------+----------+
If the page name is equal to “Jimbo” than display “Jones” else error text (but still showing) or so. I don’t know if this way good is while I don’t have any ideeas anymore.
The code that i am using so far:
<?php echo get_the_title($ID); ?>
– for fetching the title –
<?php
$result = mysql_query("SELECT lastname FROM names WHERE id = '2'");
if (!$result) {
echo 'error:bla ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
echo $row[0]; // 2
echo $row[1]; //
?>
- For fetching the row –
In WordPress I am using PHP code for posts and pages (I can make a shortcode).
http://codex.wordpress.org/Class_Reference/wpdb