Page 1 of 1

How to insert data into database...

Posted: Fri May 09, 2008 7:47 am
by Swathimaddipatla
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


hi folks....

i have retrieved information from remote server and displays the same in browser..
the information was in table format..
based on the search parametrs the information will change...

Now the thing i need to do is i have identify only data from that..which is in tables format..each row will contain some data..that data i need to display and the same has to insert into the database...

the code is as follows...

Code: Select all

<?php
$remote_server = "WWW.TYRKIAREISER.NO";
 
$req = "adminuser=&adminwho=&bookingtype=1&Submit2=S%F8k+ reise&ReturnPageOrder1=WWW.TYRKIAREISER.NO%2Forder 1.asp&sendrequestACC=&sendrequestTRP=&pax=2&infant =0&destination=Alanya&bookingTypeDepcity=Bod%F8&du ration=1&earlydate=09.05.2008&numberpp=10&includef ull=no&Submit2=S%F8k+reise";
 
$data = "POST /order1B.asp HTTP/1.0\n".
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*\n".
"Accept-Language: en-us\n".
"Accept-Encoding: gzip, deflate\n".
"User-Agent: Mozilla/4.0\n".
"Host: http://WWW.TYRKIAREISER.NO\n".
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length:$conlen\n\n".
"$req\n";
$fp = fsockopen($remote_server, 80);
 
if ($fp)
{
fputs($fp, $data);
$response="";
while (!feof($fp))
$response .= fgets($fp,1024);
 
fclose($fp);
echo $response;
}
?>
Upto this no problem..sucessfully i have retrive data from remote server....
Issue arises here....

In the response variable i have the information which is represented in the form of
tables....



$response contains data like this..

Code: Select all

<table width="100%" border="0" cellspacing="0" cellpadding="5">
 
<tr><td bgcolor='#E5ECF9' valign='top'>28.05.2008<BR>Bodø</td>
<td bgcolor='#E5ECF9' valign='top'>
<a href='#' onClick='OpenHotel(124);'>Sunway Apart 2 uker</a></td>
<td bgcolor='#E5ECF9' valign='top'><div align='right'>NOK 3 790</div></td>
<td bgcolor='#E5ECF9' valign='top'><div align='right'>7<td bgcolor='#E5ECF9' valign='top' nowrap><div align='right'><a href='#' onClick="PostPageT('booayt28.05.2008swa2u','false' );"><b><font color=#ff9900>Bestill nå</font></b> »</a><tr><td colspan='5' height='3'></td></tr><tr><td bgcolor='#E5ECF9' valign='top'>28.05.2008<BR>Bodø</td><td bgcolor='#E5ECF9' valign='top'><a href='#' onClick='OpenHotel(32);'>Uzel Hotel 2 uker med frokost </a></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>NOK 3 890</div></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>7<td bgcolor='#E5ECF9' valign='top' nowrap><div align='right'><a href='#' onClick="PostPageT('booayt28.05.2008uze2u','false' );"><b><font color=#ff9900>Bestill nå</font></b> »</a><tr><td colspan='5' height='3'></td></tr><tr><td bgcolor='#E5ECF9' valign='top'>28.05.2008<BR>Bodø</td><td bgcolor='#E5ECF9' valign='top'><a href='#' onClick='OpenHotel(13);'>Delfino Hotel & Apart 2 uker</a></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>NOK 3 990</div></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>7<td bgcolor='#E5ECF9' valign='top' nowrap><div align='right'><a href='#' onClick="PostPageT('booayt28.05.2008del2u','false' );"><b><font color=#ff9900>Bestill nå</font></b> »</a><tr><td colspan='5' height='3'></td></tr><tr><td bgcolor='#E5ECF9' valign='top'>28.05.2008<BR>Bodø</td><td bgcolor='#E5ECF9' valign='top'><a href='#' onClick='OpenHotel(123);'>Kaptan Hotel 2 uker med frokost</a></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>NOK 4 590</div></td><td bgcolor='#E5ECF9' valign='top'><div align='right'>7<td bgcolor='#E5ECF9' valign='top' nowrap><div align='right'><a href='#' onClick="PostPageT('booayt28.05.2008kap2u','false' );"><b><font color=#ff9900>Bestill nå</font></b> »</a><tr><td colspan='5' height='3'></td></tr>......
...........</table>";

i need to figure out each row data and need to insert into data base...

pls..help me out in this issue...

Thanks in advance....


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: How to insert data into database...

Posted: Fri May 09, 2008 9:09 am
by lornajane
It seems like you need to screen-scrape the data in to a format you can actually work with. If you are confident with XML then you might try parsing everything in the <table></table> tags and working with that.

I'm sure there will be other suggestions however.

Re: How to insert data into database...

Posted: Fri May 09, 2008 9:33 am
by pickle
If the datum will always be in the same order, you could try running the response through strip_tags() & parsing the result.

Other than that - parsing it as XML is the only other option I can think of.