I have a html table that contains data and i want to insert the data into an Access data. Any ideas how to do this?
[COLOR=“Blue”]Table1:
01, Rich, Mike, 23, fred lane,
02, James, milner, 45, School Lane,
03, Rob, Matthews, 89, College Road,
[COLOR=“Red”]I connect to the database using this code:
$db_conn = new COM(“ADODB.Connection”);
$connstr = “DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=”. realpath(“./Database1.mdb”).“;”;
$db_conn->open($connstr);
foreach ($rows as $row) {
$cols = $row->getElementsByTagName(‘td’);
echo $cols->item(0)->nodeValue . $cols->item(1)->nodeValue . $cols->item(2)->nodeValue . “\n”;
//here you can place the code to insert into database
}
Is there a way that i can use the code but instead of having the table in another html file, have the table in the same php file (the html table is made by using php tags)
sorry confused now, if the table is being create by php code, surely when you echo out the table contents, you can insert into the database at the same time.
i’m not sure what you mean but you can also do this
[php]
<?php
$html = "
01
Mike
fred lane
02
james
school lane
";
$dom = new DOMDocument();
$dom->loadHTML($html);
$tables = $dom->getElementsByTagName('table');
$rows = $tables->item(0)->getElementsByTagName('tr');
foreach ($rows as $row) {
$cols = $row->getElementsByTagName('td');
echo $cols->item(0)->nodeValue . $cols->item(1)->nodeValue . $cols->item(2)->nodeValue . "\n";
//here you can place the code to insert into database
}
?>[/php]
What i have is a application that uploads a “.txt” file to my server. The application will then read the information and put the data in a HTML table. The .txt file contains data e.g.
01, Richard, fred, 22,
02, Matt, mike, 55
…
The cells are separted by the comma. The code below show how this is done:
[php]
$a=1;
$b=1;
$rows=1;
$column=1;
$size1=1;
$col = 1;
while (!feof($fp)){
$char = fgetc($fp);
$array_of_line_values =explode(", ", $char);
foreach($array_of_line_values as $key => $value){
thanks for ur help, looking back on it makes sence.
A quick question for you, could i do the same but instead of putting the values into a MS access DB, could i put the values into a Multi-dimentional Array?
I have the code below which inputs data in a database, however instead of inputted the values i want, it inputs the string: Is there someting wrong with $RowName?