Hi,
I think the foreach statement is correct but not to sure how to fix:
[PHP]<?php
for($i=1;$i<3000;$i++) {
$data = file_get_contents('http://www.website.com?id='.$i);
$data = strip_tags($data,"<tr>");
$data = explode("<tr>",$data);
foreach($data as $index => $value) {
mysql_query("INSERT INTO `table` (entry, entry2, entry3, entry4, entry5) VALUES ('" . $data[12] . "', '" . $data[13] . "', '" . $data[14] . "', '" . $data[15] . "', '" . $data[16] . "')");
}
}
?>[/PHP]
Table structure that i am extracting data from is:
[HTML]<table width="385" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><h1>Company Name</h1>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<th width="30%"><strong>Contact:</strong></th>
<td width="70%"><strong>Persons Name
</strong> </td>
</tr>
<tr>
<th><strong>Tel:</strong></th>
<td><strong>000 000 000</strong></td>
</tr>
<tr>
<td> </td>
<td><span class="small">Information Here</span>.</td>
</tr>
<tr>
<th><strong>E-mail:</strong></th>
<td><strong><a href="info@website.com">info@website.com</a></strong></td>
</tr>
<tr>
<th><strong>Web site:</strong></th>
<td><strong><a href="http://www.website.com" target="_blank" id="451" onClick="return trackclick(this.id);" title="Visit Site">www.website.com</a></strong></td>
</tr>
</table>[/HTML]
Any ideas?
Cheers,
Adam
17 1269
Please can you post exactly what the problem is (errors, display, etc) so we know what to look for. We are not public syntax correctors!
Please can you post exactly what the problem is (errors, display, etc) so we know what to look for. We are not public syntax correctors!
Furthermore, show us what gets inserted into your db and what it is that you want inserting. We are not public syntax correctors!
Hi,
Sorry i was not that clear.
What i have done first is:
[PHP]<?php
$file = "http://www.web.co.uk/page.asp?id=22";
$data = file_get_contents($file);
$data = strip_tags($data,"<tr>");
$data =explode("<tr",$data);
print_r($data);
?>[/PHP]
This is produces: - Array ( [0] => name [1] => > [2] => > description [3] => > [4] => > [5] => > [6] => > [7] => > [8] => > [9] => > --> [10] => > [11] => > [12] => > Company Name [13] => > Contact: John [14] => > Tel:0000 [15] => > Text [16] => > E-mail: gstarmobilediscos@yahoo.co.uk [17] => > Web site: www.site.com
Then i want to run the first script on what is produced but it does not return anything.
Cheers,
Adam
What exactly you want script to return?
Single call of mysql_query won't return anything.
I want to return the '" . $data[12] . "', '" . $data[13] . "', '" . $data[14] . "', '" . $data[15] . "', '" . $data[16] . "' and put them into my table.
mysql_query("INSERT INTO `table` (entry, entry2, entry3, entry4, entry5) VALUES ('" . $data[12] . "', '" . $data[13] . "', '" . $data[14] . "', '" . $data[15] . "', '" . $data[16] . "')");
I want to return the '" . $data[12] . "', '" . $data[13] . "', '" . $data[14] . "', '" . $data[15] . "', '" . $data[16] . "' and put them into my table.
mysql_query("INSERT INTO `table` (entry, entry2, entry3, entry4, entry5) VALUES ('" . $data[12] . "', '" . $data[13] . "', '" . $data[14] . "', '" . $data[15] . "', '" . $data[16] . "')");
So $data array is empty while you expect it to be with some data?
Try to turn on debugging by including in your script this lines:
[PHP]ini_set('display_errors',1);
error_reporting(E_ALL);[/PHP]
And check are there any errors.
You're logic on the foreach is flawed ;)
Simple to fix though!
You should no longer assume $data[] is an array - you have now (through the foreach) passed it into new variables ($value / $index) so use these variables to work with it:
[php]
foreach($data as $index => $value) {
/**
* THIS WONT WORK BECAUSE YOU ARE CHANGING $DATA!
* mysql_query("
* INSERT INTO
* `table`
* (entry, entry2, entry3, entry4, entry5)
* VALUES
* ('" . $data[12] . "', '" . $data[13] . "', '" . $data[14] . "', '" . $data[15] . "', '" . $data[16] . "')");
*/
echo "$index is $value<br />";
}
[/php]
Any questions?
Thanks for that but how do i go about only extracting certain fields as this displays all the data but i only need 13,14,15 and 16
Something like this?
[php]
for($_i = 13; $_i < 17; ++$_i)
{
echo $data[$_i] . "<br />";
}
[/php]
Hi,
I tried this:
[PHP]<?php
for($i=1;$i<10;$i++) {
$data = file_get_contents('http://www.website.com/details.asp?ID='.$i);
$data = strip_tags($data,"<tr>");
$data = explode("<tr>",$data);
foreach($data as $index => $value) {
for($_i = 13; $_i < 17; ++$_i) {
echo $data[$_i] . "<br />";
}
}
}
?>[/PHP]
But just returns the same value.. Am i doing something wrong?
Let's have a look at this:
[PHP]<?php
// nine times we'll do the same things
for($i=1;$i<10;$i++) {
// get HTML-code into string
$data = file_get_contents('http://www.website.com/details.asp?ID='.$i);
$data = strip_tags($data,"<tr>");
// now string becomes an array
$data = explode("<tr>",$data);
// loop with as much iterations as items in array $data
foreach($data as $index => $value) {
// display items $data[14], $data[15], $data[16]
for($_i = 13; $_i < 17; ++$_i) {
echo $data[$_i] . "<br />";
}
}
}
?>[/PHP]
Say, $data looks like this :
[PHP]$data = array (
1 => 'first string',
...
16 => 'sixteenth string',
);[/PHP]
Finally, we'll see this in the browser for nine times:
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
forthteenth string
fifteenth string
sixteenth string
There seems to be something wrong as it is not printing out 14, 15, 16 it is just printing 14 but the same data over and over about 50 times.
Just remove foreach statement.
No idea why do you need it.
How about instead of for loop having conditon:
[PHP]
foreach($data as $index => $value) {
// display items $data[14], $data[15], $data[16]
/* for($_i = 13; $_i < 17; ++$_i) {
echo $data[$_i] . "<br />";
} */
if (($index == 14) || ($index == 15) || ($index == 16)){
echo $value. "<br />";
}
}
[/PHP]
Yeh, you were supposed to remove the foreach statement as it serves no purpose.
[php]
<?php
$data = file_get_contents('http://thescripts.com');
$data = strip_tags($data,"<tr>");
// now string becomes an array
$data = explode("<tr>",$data);
for($_i = 13; $_i < 17; ++$_i)
{
echo $_i. " " . $data[$_i] . "<br />";
}
?>
[/php]
Hi,
Still does not work:
[PHP]
<?php
// nine times we'll do the same things
for($i=1;$i<10;$i++) {
$data = file_get_contents('http://www.website.co.uk/details.asp?OrgID='.$i);
$data = strip_tags($data,"<tr>");
// now string becomes an array
$data = explode("<tr>",$data);
for($_i = 14; $_i < 17; ++$_i)
{
echo $_i. " " . $data[$_i] . "<br />";
}
}
?>
[/PHP]
Any ideas?
It worked for me..
Do you get any output, and errors?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dpackwood |
last post by:
Hello,
I have two different scripts that do pretty much the same thing. The main
perl script is on Windows. It runs and in the middle of it, it then calls
out another perl script that then...
|
by: mike |
last post by:
Hello,
After trying to validate this page for a couple of days now I was
wondering if someone might be able to help me out. Below is a list of
snippets where I am having the errors.
1. Line 334,...
|
by: Derek |
last post by:
I have the following script in a page and it gets an error in IE 6. Says
something about an invalid
argument but the line number doesn't help since I can't see the javascript
code when viewing...
|
by: mike |
last post by:
Hello,
I am kind of new to this javascript stuff and I am constantly having
problems trying to get my webpage validated. I have the following
<script>printdate();</script> and when I validate it...
|
by: Craig Keightley |
last post by:
Please help, i have attached my page which worksin IE but i cannnot get the
drop down menu to fucntion in firefox. Any one have any ideas why?
Many Thanks
Craig
...
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
...
|
by: Rahul |
last post by:
Hi Everybody
I have some problem in my script. please help me. This is script file.
I have one *.inq file. I want run this script in XML files. But this
script errors shows . If u want i am...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: althafexcel |
last post by:
hi everyone
Im trying to include an external js in my aspx page under the head
tag, it doesn't load or it displays an object expected error whenver
the function from the .js is called. Actually...
|
by: mattehz |
last post by:
Hey there,
I am trying to upload old source files and came across these errors:
Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |