redarrow Posted November 14, 2010 Share Posted November 14, 2010 Advance thank you. Can you help please. The error..... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\wamp\www\test_dabase.php on line 24 code. <?php //database connection. $DB = mysql_connect("localhost","root") or die(mysql_error()); if($DB){ //database name. $DB_NAME="mysql"; //select database and name. $CON=mysql_select_db($DB_NAME,$DB)or die(mysql_error()."\nPlease change database name"); // if connection. }if($CON){ //show tables. $mysql_show="SHOW TABLES"; //select show and show. $mysql_select2="mysql_query(".$mysql_show.") or die(mysql_error())"; } //if allowed to show. if($mysql_select2){ //while it and while($data=mysql_fetch_assoc($mysql_select2)){ //show it. echo $data; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/218618-code-help-view-tables-form-a-database-via-php-code-included/ Share on other sites More sharing options...
redarrow Posted November 14, 2010 Author Share Posted November 14, 2010 Had to be done this way, with a array. <?php $DB = mysql_connect("localhost","root") or die(mysql_error()); //database name. $DB_NAME="mysql"; //selEct database and name. $CON=mysql_select_db($DB_NAME,$DB)or die(mysql_error()."\nPlease chage database name"); $showtablequery = "SHOW TABLES FROM mysql"; $showtablequery_result = mysql_query($showtablequery); while($showtablerow = mysql_fetch_array($showtablequery_result)) { echo $showtablerow[0]."<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/218618-code-help-view-tables-form-a-database-via-php-code-included/#findComment-1134000 Share on other sites More sharing options...
redarrow Posted November 14, 2010 Author Share Posted November 14, 2010 Code corrected and understood why.... from the previous attempt, I didn't use a array, i used a assoc, so it went wrong, also I wrote the select statement wrong. also i didn't select the database name (from mysql) working <?php //database connection. $DB = mysql_connect("localhost","root") or die(mysql_error()); if($DB){ //database name. $DB_NAME="mysql"; //select database and name. $CON=mysql_select_db($DB_NAME,$DB)or die(mysql_error()."\nPlease change database name"); // if connection. }if($CON){ //show tables. $mysql_show="SHOW TABLES FROM $DB_NAME"; //select show and show. $mysql_select2=mysql_query($mysql_show) or die(mysql_error()); } //if allowed to show. if($mysql_select2){ //while it and while($data=mysql_fetch_array($mysql_select2)){ //show it. echo " $data[0] <BR>"; } } ?> not working.(with my mistakes)))) <?php //database connection. $DB = mysql_connect("localhost","root") or die(mysql_error()); if($DB){ //database name. $DB_NAME="mysql"; //select database and name. $CON=mysql_select_db($DB_NAME,$DB)or die(mysql_error()."\nPlease change database name"); // if connection. }if($CON){ //show tables. $mysql_show="SHOW TABLES"; //select show and show. $mysql_select2="mysql_query(".$mysql_show.") or die(mysql_error())"; } //if allowed to show. if($mysql_select2){ //while it and while($data=mysql_fetch_assoc($mysql_select2)){ //show it. echo $data; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/218618-code-help-view-tables-form-a-database-via-php-code-included/#findComment-1134004 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.