Jump to content

select * question


aniket_dj

Recommended Posts

Hi all,

 

I have a db called "core_set" which has a bunch of tables in it.

 

Basically I want to search for a table named "x" or "xx" or "xxx" inside db "core_set". I am scripting using PHP, but I guess this is purely a (My)SQL question.

 

I was hoping for something like

 

select *from db(core_set) where tables_in_core_set like '%x%';

 

right now 'show tables' returns me the names of tables, but I cant have select *from show tables  as such.

 

Any ideas of how I can get around this?

 

Thanks!

Link to comment
Share on other sites

first you should select a table and store it as a variable. say you have a form, you submit the form, you retrieve the table you selected in the form.

 

$table = $_GET['tablename'];

 

now you can get the results from the table

 

$sql = "SELECT * FROM `$table`";

 

you would use show tables first to show a list of the tables then you would select the table to get the results.

 

lets say you want to list the tables and when you click on a table name it shows the data

<?php
$sql = "SHOW TABLES FROM $dbname";
$res = mysql_query($sql) or die(mysql_error());
while($r = mysql_fetch_row($res)){
echo "<a href=\"".$_SERVER['PHP_SELF']."?tablename=".$r[0]."\">".$r[0]."</a><br />\n";
}
if(isset($_GET['tablename'])){
$table = $_GET['tablename'];
$sql = "SELECT * FROM `$table`";
$res = mysql_query($sql) or die(mysql_error());
$fields = mysql_num_fields($res);
  while($r = mysql_fetch_array($res)){
    for($i=0; $i<$fields; $i++){
    echo $r[$i]." ";
    }
  }
}
?>

 

Ray

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.