Jump to content

code help , view tables form a database via php. (code included.


redarrow

Recommended Posts

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;
        
        }
    }    
    ?>

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 />";
}

    ?>

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;
        
        }
    }    
    ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.