zgkhoo Posted November 19, 2007 Share Posted November 19, 2007 how to list out all table name that contain in my db? i need compare with my record... eg if $gender==$tablename then...store....into $tablename how? thanks in advance Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 19, 2007 Share Posted November 19, 2007 if you are using gender as an identifier for a table then you have made you database structure to obscure to be useful... something liek gender shuld be a field in a table so you can filter out resutls based on that criteria... obviously I don't know what your tables look like BUT that is the impression I get.. the alternative is to use the setting in teh query... $qry = "INSERT INTO `" . $gender . " ....."; Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 19, 2007 Author Share Posted November 19, 2007 i know how to insert...but i know to compare the tablename .... how? eg like this if($tablename==$gender) { } Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 19, 2007 Share Posted November 19, 2007 Well, why don't you just to an IF or Switch statement? <?php if ($gender == 'male') $tablename = 'male_table'; else $tablename = 'female_table'; ?> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 19, 2007 Share Posted November 19, 2007 your question is very confusing because you structure to your database is confusing. you can get the table names it is in mysql, but you aren't making any sense as you have illogical idea that you want to solve somehow with logic. Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 19, 2007 Author Share Posted November 19, 2007 wat is meant is my table name= "Male" another table name="Female" how can i store in those tablename into $tablename and use it to compare using if else statement.. got my meant? thanks.. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 19, 2007 Share Posted November 19, 2007 Yes, you would just do this...I'm pretty sure I understand what you mean. <?php if ($gender == 'male') $tablename = 'Male'; else $tablename = 'Female'; $query = "INSERT INTO $tablename ....."; ?> Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 20, 2007 Author Share Posted November 20, 2007 no........... can u show me how to display(not insert) all table's table name inside a db? thanks... Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 20, 2007 Share Posted November 20, 2007 Try this <?php $sLocalHost="localhost"; $sLocalUser ="root"; $sLocalPassword =''; $sLocalDatabaseName ="abcdefgh"; //change here $conn = mysql_connect($sLocalHost,$sLocalUser,$sLocalPassword); $db=mysql_select_db($sLocalDatabaseName); if($conn=="") { trigger_error('Unable to connect to database: ' . mysql_error()); } // show the tables $sql = "SHOW TABLES"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_row($result)) { echo "Table: {$row[0]}\n"; } mysql_free_result($result); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.