1

This is my code, I'm searching the table names which ends with keyword called '_countries'.

I'm getting a result also but I do not know how to get table name from that result.

This is the code the fetches the query result:

$sql="show tables like '%_countries'";
$result=$this->db->query($sql);
foreach ($result -> result() as $delete) {
    print_r( $delete);
}

The print_r()'s result is:

stdClass Object ( [Tables_in_test (%_countries)] => news_countries )

news_countries is the result which I need.

This is how I'm trying to access the property inside the loop:

$delete->table_name;
$delete->name;
$delete->Tables_in_test;

But above codes did not give result I need.

3
  • What error does it show? Commented Jan 22, 2015 at 7:27
  • 1
    Undefined property: stdClass::$table_name this error when i try with $delete->table_name; Commented Jan 22, 2015 at 7:28
  • 3
    weird property name, try $delete->{'Tables_in_test (%_countries)'} Commented Jan 22, 2015 at 7:29

1 Answer 1

1

You could also try to use reset() in this case:

foreach ($result->result_array() as $delete) {
    $name = reset($delete);
    echo $name;
}
Sign up to request clarification or add additional context in comments.

4 Comments

it works like charm , and please upvote my question ,it will be useful for some other people
@Thamaraiselvam i think another way is selecting it thru INFORMATION_SCHEMA, plus, you get to choose your own alias for that column name, i just can't test it since i don't have CI on my env, anyways, glad this helped,
Okay , Thank you for your wonderful helping . i will try with INFORMATION_SCHEMA also
something like: SELECT TABLE_NAME` AS table_name FROM information_schema.TABLES WHERE TABLE_NAME LIKE '%countries%'`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.