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

Link to comment
Share on other sites

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

    ?>

Link to comment
Share on other sites

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

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.