Please bear with me as I am still trying to learn php and mysql.
I am using ver 4.0.26 of mysql. I also have been using phpMyadmin to create tables and some minor editing.
I have learned the basics of how to create edit and delete a table in mysql. I have a simple address book called “address_book”. The tables are ” index, name, address, phone”.
I am able to display the contents:
[URL=http://www.epourania.com/SAMSphp/16/select_test_reveal_all.php]Display address_book
and the code is:
[quote]
<?php
// open the connection
$conn = mysql_connect(“localhost”, “xxxx” , “xxxx”);
// pick the database to use
mysql_select_db(“Big_File”,$conn);
// create the SQL statement
$sql = “SELECT * FROM address_book”;
// execute the SQL statement
$result = mysql_query($sql, $conn) or die(mysql_error());
//go through each row in the result set and display data
while ($newArray = mysql_fetch_array($result)) {
// give a name to the fields
// index, name, address, phone
// make $n the index number of arrays holding name address and phone
$index = $newArray[‘index’];
$name = $newArray[‘name’];
$address = $newArray[‘address’];
$phone = $newArray[‘phone’];
//echo the results onscreen
echo “The index is $index name is $name address is $address phone is $phone <br>”;
};
echo “$result”;
?>
I intended to take the contents from the fields in the table and place each one in an arrays and take those contents and put them in an HTML table.
[list][*]
Is it possible to take the contents of the fields and place them in a php array?
Is it possible to use the variables from the php array and use them in HTML?
Is it possible to make HTML type of tables in php?
The command that was used is: “.. while ($newArray = mysql_fetch_array($result)) {bla bla} ..”
I don’t fully understand the command ” mysql_fetch_array ” and when I echo the contents of ” $result ” it says “Resource id #2”
I can see this is a complex question, let me simplify:
I have a php file with an HTML table:
[quote]
<html>
<head>
<title>4×5 Table</title>
</head>
<body>
<!– Test Table –>
<!– BEGIN TABLE –>
<TABLE BORDER=”1″>
<TR>
<TD>
<!– LEFT SIDE TABLE 02 –>
<TABLE BORDER=”1″>
<TR><TD>a</TD></TR>
<TR><TD>b</TD></TR>
<TR><TD>c</TD></TR>
<TR><TD>d</TD></TR>
<TR><TD>e</TD></TR>
</TABLE>
</TD><TD>
<!– CENTER TABLE 02 –>
<TABLE BORDER=”1″>
<TR><TD>f</TD></TR>
<TR><TD>g</TD></TR>
<TR><TD>h</TD></TR>
<TR><TD>i</TD></TR>
<TR><TD>j</TD></TR>
</TABLE>
</TD><TD>
<!– Right Table –>
<TABLE BORDER=”1″>
<TR><TD>k</TD></TR>
<TR><TD>l</TD></TR>
<TR><TD>m</TD></TR>
<TR><TD>n</TD></TR>
<TR><TD>o</TD></TR>
</TABLE>
</TD><TD>
<!– RIGHT TABLE 02 –>
<TABLE BORDER=”1″>
<TR><TD>p</TD></TR>
<TR><TD>q</TD></TR>
<TR><TD>r</TD></TR>
<TR><TD>s</TD></TR>
<TR><TD>t</TD></TR>
</TABLE>
</TD>
</TR>
</TABLE>
<!– END TABLE –>
</body>
</html>
it will display as follows:
[URL=http://www.epourania.com/SAMSphp/16/aTable.php]test table
[list][*]
Is there a way I can take the values from the fields in the table of my mysql database, “address_book”, and place them in this HTML table?
or, Does php have commands similar to HTML tables?
My whole purpose of is to get familiar with php and mySql. I am currently using the SAMS Teach Yourself book. Any recommendations would be greatly appreciated.