php – WordPress Custom SQL Table with UserID Filter for results

Question

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; ?&gt;</td>
<td><!--?php echo $results ->char_race; ?&gt;</td>
<td><!--?php echo $results ->char_gender; ?&gt;</td>
<td><!--?php echo $results ->char_age; ?&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
--></td>
</tr>
</tbody>
</table>

0
Trev 4 months 2022-04-24T18:45:44-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse