php - html data to array for mySQL insertion

992

I have got a list of HTML data which i would like to have inserted into a mySQL database.

I'm sort of a beginner on this one so I need some help in how to convert the HTML data toward an array, and insert that data into a mySQL database.

The html data looks like this:

<tr><td></td>
<td align="right">09:00</td>
<td><a href="./draw.aspx?id=406FB89A-DCD9-409B-AB32-033677CFAEC8&amp;draw=111">groep 1 - boys U19 - finale 17-24 A</a></td><td align="right"><a href="team.aspx?id=406FB89A-DCD9-409B-AB32-033677CFAEC8&amp;team=3">Home Team</a><img src="//static.tournamentsoftware.com/images/flags/16/NED.png" alt="Nederland" title="Nederland" height="14" width="16"><span >[NED] </span></td>
<td align="center">-</td>
<td ><img src="//static.tournamentsoftware.com/images/flags/16/NED.png" alt="Nederland" title="Nederland" height="14" width="16"><span >[NED] </span><strong><a href="team.aspx?id=406FB89A-DCD9-409B-AB32-033677CFAEC8&amp;team=15">Away Team</a></strong></td>
<td><span ><span>0-4</span></span></td>
<td><a href="./court.aspx?id=406FB89A-DCD9-409B-AB32-033677CFAEC8&amp;crtid=65">Pitch 3a</a>
</td></tr>

I think i should extraxt the data with a for loop and put it into an array.

this is the data i need from the html above:

Time - schedule - home - away - homegoals - awaygoals -pitch

Who can help me on building an array, and help me on how to inset this into a database with colums like below:

Time - schedule - home - away - homegoals - awaygoals -pitch

//////////////////////////////////////////////////////////////////////////////// I have used the stripttags functionality to end up with a complete list of information like this:

strip_tags($table);

Wedstrijdoverzicht van zondag 20 april 2014 TijdstipSchemaUitslagVeld 09:00groep 1 - boys U19 - finale 17-24 AFC Lisse[NED] -[NED] Hapse Boys0-4Cuijk - veld 3a 09:00groep 1 - boys U19 - finale 17-24 BVV Gesta[NED] -[NED] RKSV Odiliapeel/Braks0-4Cuijk - veld 1a 09:00groep 1 - boys U19 - finale 17-24 BWVV Constantia[NED] -[ENG] The Cardinal Vaughan 21-3Cuijk - veld 2a 09:00groep 2 - boys U17 - finale 1 09-12KFC Werchter[BEL] -[GER] Salamanda Kornwestheim1-0Wanroij - veld 1a 09:00groep 2 - boys U17 - finale 1 09-12Broomhill[SCO] -[NED] Hapse Boys1-1Wanroij - veld 2a 09:00groep 2 - boys U17 - finale 1 13-16WVV Constantia[NED] -[NED] Voorschoten '972-3Wanroij - veld 3a 09:00groep 2 - boys U17 - finale 1 13-16Advanced Soccer Acedemy[LIB] -[NED] Neerlandia '310-0Wanroij - veld 4a 09:00groep 5.2 - boys U15 B - finale 17-24 AToxandria[NED] -[NED] Montagnards1-5Rijkevoort - veld 3a 09:00groep 5.2 - boys U15 B - finale 17-24 BBryrup IF[DEN] -[USA] Stuttgart Select7-0Rijkevoort - veld 1a 09:00groep 5.2 - boys U15 B - finale 17-24 BSv Zulte Waregem[BEL] -[ENG] Essex Royals WFC6-0Rijkevoort - veld 2a 09:00groep 3 - boys U16 - finale 13-16VV De Zwaluw[NED] -[NED] Sv Houten1-3Gennep - veld 1a 09:00groep 3 - boys U16 - finale 13-16Dosko '32[NED] -[NED] Blauw Wit '812-1Gennep - veld 2a 09:00groep 4 - boys U15 A - finale 13-16RKSV Mulo[NED] -[DEN] Snekkersten IF1-1Landhorst - veld 1a 09:00groep 4 - boys U15 A - finale 13-16FC Akilles[FIN] -[NED] Berghem Sport0-0Landhorst - veld 2a 09:00groep 5.1 - boys U15 B - finale 13-16Excellent[NED] -[ENG] St Edmundton Campain0-3Oploo - veld 1a 09:00groep 5.1 - boys U15 B - finale 13-16Bournemouth Collegiate[ENG] -[NED] Nooit Gedacht7-0Oploo - veld 2a 09:00groep 6 - boys U14 A - finale 13-16WVV Constantia[NED] -[DEN] Stautrup IF0-3Beugen - veld 1a 09:00groep 6 - boys U14 A - finale 13-16MK Dons SET FC[ENG] -[ENG] Welling FC1-1Beugen - veld 2a 09:00groep 7.1 - boys U14 B - finale 13-16VV De Willy's[NED] -[WAL] Penrhyn Bay FC1-1Wilbertoord - veld 1a 09:00groep 7.1 - boys U14 B - finale 13-16Slagelse B&I[DEN] -[NED] RKSV Volkel2-0Wilbertoord - veld 2a 09:00groep 7.2 - boys U14 B - fina

But I'm not sure how to extract the information I need from the $table variable above.

////////////////////////////////////////////////////////////////////////////////

So, just left the striptags aside.Now i've got the following result:

object(DOMElement)#1 (18) { ["tagName"]=> string(5) "table" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(5) "table" ["nodeValue"]=> string(78208) " Wedstrijdoverzicht van zondag 20 april 2014 TijdstipSchemaUitslagVeld 09:00groep 1 - boys U19 - finale 17-24 AFC Lisse[NED] -[NED] Hapse Boys0-4Cuijk - veld 3a 09:00groep 1 - boys U19 - finale 17-24 BVV Gesta[NED] -[NED] RKSV Odiliapeel/Braks0-4Cuijk - veld 1a 09:00groep 1 - boys U19 - finale 17-24 BWVV Constantia[NED] -[ENG] The Cardinal Vaughan 21-3Cuijk - veld 2a 09:00groep 2 - boys U17 - finale 1 09-12KFC Werchter[BEL] -[GER] Salamanda Kornwestheim1-0Wanroij - veld 1a 09:00groep 2 - boys U17 - finale 1 09-12Broomhill[SCO] -[NED] Hapse Boys1-1Wanroij - veld 2a 09:00groep 2 - boys U17 - finale 1 13-16WVV Constantia[NED] -[NED] Voorschoten '972-3Wanroij - veld 3a 09:00groep 2 - boys U17 - finale 1 13-16Advanced Soccer Acedemy[LIB] -[NED] Neerlandia '310-0Wanroij - veld 4a 09:00groep 5.2 - boys U15 B - finale 17-24 AToxandria[NED] -[NED] Montagnards1-5Rijkevoort - veld 3a 09:00groep 5.2 - boys U15 B - finale 17-24 BBryrup IF[DEN] -[USA] Stuttgart Select7-0Rijkevoort - veld 1a 09:00groep 5.2 - boys U15 B - finale 17-24 BSv Zulte Waregem[BEL] -[ENG] Essex Royals WFC6-0Rijkevoort - veld 2a 09:00groep 3 - boys U16 - finale 13-16VV De Zwaluw[NED] -[NED] Sv Houten1-3Gennep - veld 1a 09:00groep 3 - boys U16 - finale 13-16Dosko '32[NED] -[NED] Blauw Wit '812-1Gennep - veld 2a 09:00groep 4 - boys U15 A - finale 13-16RKSV Mulo[NED] -[DEN] Snekkersten IF1-1Landhorst - veld 1a 09:00groep 4 - boys U15 A - finale 13-16FC Akilles[FIN] -[NED] Berghem Sport0-0Landhorst - veld 2a 09:00groep 5.1 - boys U15 B - finale 13-16Excellent[NED] -[ENG] St Edmundton Campain0-3Oploo - veld 1a 09:00groep 5.1 - boys U15 B - finale 13-16Bournemouth Collegiate[ENG] -[NED] Nooit Gedacht7-0Oploo - veld 2a 09:00groep 6 - boys U14 A - finale 13-16WVV Constantia[NED] -[DEN] Stautrup IF0-3Beugen - veld 1a 09:00groep 6 - boys U14 A - finale 13-16MK Dons SET FC[ENG] -[ENG] 

Now i Should know how to convert this to an array for mysql insertion

37

Answer

Solution:

What you need to do (if I've understood you correctly) is create a link to your database

<?php
link = mysqli_connect("localhost","root","","table");

mysqli_query($link,"INSERT INTO YOUR_TABLE(Time, schedule, 
      home, away, homegoals, awaygoals, pitch)

VALUES ($emp_time, $emp_schedule, $emp_home, $emp_away, 
        $emp_homegoals, $emp_awaygoals, $emp_pitch)") 
or die(mysqli_error($link));
?>

Where$emp_time is the table dataname attribute and addname to all othertd row to match the code.

Reference

People are also looking for solutions to the problem: php - GridView row as link, except action column items in Yii2

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.