Jump to content


Photo

just need a little help finding whats inside mysql


  • Please log in to reply
4 replies to this topic

#1 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 12 June 2006 - 11:52 PM

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

$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);

The best way to learn
is to ask you lot........

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 13 June 2006 - 12:36 AM

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]
~ D Kuang

#3 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 13 June 2006 - 01:19 AM

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

$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);

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
The best way to learn
is to ask you lot........

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 13 June 2006 - 01:47 AM

[!--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!
Legend has it that reading the manual never killed anyone.
My site

#5 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 13 June 2006 - 02:15 AM

[!--quoteo(post=383064:date=Jun 12 2006, 08:47 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 12 2006, 08:47 PM) View Post[/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 :)
mysql_field_name() 

The best way to learn
is to ask you lot........




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users