First off, you should not be handing an untrusted input (in this case, $_GET['id']
to your database. Always SQL-escape the query and validate/sanitize the data. (In the code snippet below, it’s SQL-escaped using $wpdb->prepare()
for escaping and int
typecasting to sanitize to integer value).
Secondly, the $wpdb
object provides more than just the query()
function. In your case, it sounds like you’re trying to get a set of rows, so you can use the get_results()
function:
if ( ! empty( $_GET['msg'] ) ) {
global $wpdb;
$vuser_id = (int) $_GET['id'];
$result = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}quiz WHERE quiz_id=%d",
$vuser_id
)
);
var_dump( $result );
}
The var_dump()
is in there so you can examine exactly what $wpdb->get_results()
returned. By default it’ll be an array of objects
.
Reference
wpdb
class on the WordPress Codex