Jump to content

just need a little help finding whats inside mysql


thehigherentity

Recommended Posts

basicaly I have only just got my head round making and removing tables in mysql I have been using the following code to see if the tables were there or not, now im onto writing information into the table i dont seem to have any way of checking the info is actualy there.

So my question is, can this code be changed to read the information within the tables too ?

if so can somone point me in the right direction of how to go about this
what i could realy do with is it showing the rows and the values or information within them so i can actualy tell i am doing things right

this would be a great help to me if somone could help with this

[code]
$link = mysql_connect($host, $user, $pass);

$result = mysql_list_dbs($link);
$row_numb = mysql_num_rows($result);

while ($db_data = mysql_fetch_row($result )){
    echo $db_data[0]."<br>";
    $result2 = mysql_list_tables($db_data[0]);
    $num_rows2 = mysql_num_rows($result2);
    while($table_data = mysql_fetch_row($result2)) {
        echo "--".$table_data[0]."<br>";
    }
    echo "==> $num_rows2 table(s) in ".$db_data[0]."<p>";
}

mysql_close($link);
[/code]
Link to comment
Share on other sites

Maybe I am misunderstanding you, but you are looking for MySQL data retrieval, right?

[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95441\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95441[/a]
[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95443\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95443[/a]
Link to comment
Share on other sites

I can view the data in a table if i know what the rows are called, eg im using this at the moment

[code]
$link = mysql_connect($host, $user, $pass); // conect to the mysql databases

if (!mysql_select_db ($dbname)) die ("WE have a big problem, <br>I cant connect to the database $dbname"); // select the database to work with

$query = "SELECT * from $tablename";

$result = mysql_db_query($dbname, $query, $link);

// create a table
print ("<TABLE BORDER=1 WIDTH=\"75%\" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>\n");

print ("<TR ALIGN=CENTER VALIGN=TOP>\n");

print ("<TD ALIGN=CENTER VALIGN=TOP>I.D</TD>\n");

print ("<TD ALIGN=CENTER VALIGN=TOP>Username</TD>\n");

print ("<TD ALIGN=CENTER VALIGN=TOP>Comments</TD>\n");

print ("<TR>\n");

while($row = mysql_fetch_array($result)){
    print("<TR ALIGN=CENTER VALIGN=TOP>\n");
    print("<TD ALIGN=CENTER VALIGN=TOP>$row[id]</TD>\n");
    print("<TD ALIGN=CENTER VALIGN=TOP>$row[user_name]</TD>\n");
    print("<TD ALIGN=CENTER VALIGN=TOP>$row[information]</TD>\n");
    print("</TR>");
}
mysql_close($link);
[/code]

however, lets say i dont know the names of the rows "$row[user_name]"
how can i find that out?
and how can i find out how many of them there are?

my problem is i like flat files becouse i can look inside and see for myself, but im working on somthing
thats far too big for flat files so i realy need to learn mysql now, i have worked out its a lot easyer to work with then i thought but its just knowing how to do it in the first place

thanks for any help you can give and i hope thats explained things a little better
Link to comment
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]however, lets say i dont know the names of the rows "$row[user_name]"
how can i find that out?
and how can i find out how many of them there are?[/quote]
I don't really understand your problem. How did you create the table in the first place. How did you create and define the fields that make up each row? How could you not actually know the structure of a database you created?

Doing a little reading will help you learn faster than just asking questions. At worst, you'll get the terminology right :)

[a href=\"http://www.htmlite.com/MYSQLintro.php\" target=\"_blank\"]http://www.htmlite.com/MYSQLintro.php[/a]

[a href=\"http://aspn.activestate.com/ASPN/docs/PHP/function.mysql-list-fields.html\" target=\"_blank\"]http://aspn.activestate.com/ASPN/docs/PHP/...ist-fields.html[/a] - but it won't tell you the definitions of each field!
Link to comment
Share on other sites

[!--quoteo(post=383064:date=Jun 12 2006, 08:47 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 12 2006, 08:47 PM) [snapback]383064[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I don't really understand your problem. How did you create the table in the first place. How did you create and define the fields that make up each row? How could you not actually know the structure of a database you created?

Doing a little reading will help you learn faster than just asking questions. At worst, you'll get the terminology right :)
[/quote]

the database I have created isnt a problem right now, even though... I will come back to them in a few month and wont have a clue what i called the fields with the tables.

I have created a small database with only 3 fields at the moment and there id, user and comment all i am doing in playing arround with these making sure i know how to delete move and change the information befor i even attempt to make anything with the connection.

I have a guest book installed on my server and i have been trying to access the information within there too and this is were i have had some problems, I know how to find the table names but im lost on how to find the field names and I have read a number of sites and looked through my referance books but non of these seem to consider the fact that you could be working on somthing that somone else has created.

I would of thought there would be a simple command to do this, it seems very logical to me?

anyway thanks for the links, I will go check them out now see if i can find anything there

Just so you know i found what i wanted thanks for the help :)
[code]
mysql_field_name()
[/code]
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.