php – WordPress Custom SQL Table with UserID Filter for results
Im trying to make a Custom table with in my wordpress Database, the table is called sr3_characters, I have gone to my wordpress->wp_users and collected my login ID which is “1”. I then have added this number to my custom table which holds the headding wp_id.
Below is my code which doesnt give an error, nor does it give results. Ive tried to get samples from various websites which has made the errors disapear so I feel its working but its not ecoing the data.
Note: I know there are some formatting like “<!--?php
” and the “-->
” at the bottom near the “</td>
” but wordpress code writer is putting these in automaticly
<!--?php
global $wpdb;
$current_user = wp_get_current_user();
$uid = $current_user->ID;
$table_name = $wpdb->prefix . 'sr3_characters';
$results = $wpdb->get_results("SELECT * FROM $table_name WHERE 'wp_id' = $uid", OBJECT );
?-->
<table border="1">
<tbody>
<tr>
<th>Name</th>
<th>Race</th>
<th>Gender</th>
<th>Age</th>
</tr>
<tr>
<td><!--?php echo $results ->char_name; ?></td>
<td><!--?php echo $results ->char_race; ?></td>
<td><!--?php echo $results ->char_gender; ?></td>
<td><!--?php echo $results ->char_age; ?></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
--></td>
</tr>
</tbody>
</table>
Leave an answer