search using get_var for custom table

Hi, I have this script for which I am simply trying to display results from a custom table using custom search form.

the code:

global $wpdb;

if(isset($_GET['search-custom-table']) && $_GET['search-custom-table'] != '') {
$user_search = esc_attr($_GET['search-custom-table']);
$address_table = $wpdb->prefix . "address_table";
$myrows = $wpdb->get_var( 'SELECT city FROM ' . $address_table );
global $myrows;
}

var_dump($myrows);

?>

<form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="text" name="search-custom-table" id="search-custom-table" />

<input type="submit" class="" value="Search" />
</form>

This is giving a result of NULL.

I have searched codex, stackoverflow, and googled in general, however, those options haven’t helped to solve this.

Thanks ~

  • Paul
    • Design Lord, Child of Thor

    Thanks, I’ve been through some php/mysql books and what not, but it’s like learning something new using this in wp. In the code above, I took away the global within the if statement, and that seemed to do the trick. I see what you are saying about the where statement. I should be able to use something like: WHERE city = $user_search – yes?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.