Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 377575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:42:36+00:00 2026-05-12T14:42:36+00:00

I have written a page that will scan a site and then extract certain

  • 0

I have written a page that will scan a site and then extract certain code from the source. That part is working successfully, however I want to run this over multiple pages and dump the details into a database. I am stuggling to get the loop working, this is what I currently have:

date_default_timezone_set("australia/sydney");

$host = 'http://www.tabonline.com.au/';
$day = date(d);
$month = date(m);
$year = date(Y);
$slash = '/';
$mtgraces = '/mtgraces.html';

//Gallops Meetings on Todays racing page
$content = file_get_contents($host . $year . "/". $month . "/" . $day . $mtgraces);
preg_match_all('#<a[^<>]+href\s*=\s*[\'"](.R[0-9]+.html*)[\'"]#i', $content, $matches);
foreach ($matches[1] as $url) $links[] =  "$host$year$slash$month$slash$day$slash$url";

//get the runners from each page

for($c=0; $c<count($links); $c++)

$racepage = file_get_contents($links[$i]);
preg_match_all('#<td align="right" height="18"><font color="\#ffffff">[0-9]{1,2}</font></td>#', $racepage, $number);
preg_match_all('#<font color="\#00ffff">[0-9]{1,3}</font>#', $racepage, $rating);
preg_match_all('#<B>[\w]+([\s][A-Z]+)?</B>#', $racepage, $location);
preg_match_all('#<B>[\w]+\s[0-9]+</B>#', $racepage, $locationcode);

//strip tags for storage in DB

$number_data = implode(",", $number[0]);
$dbnumber = strip_tags($number_data);
$final_number = explode(",", $dbnumber);

$rating_data = implode(",", $rating[0]);
$dbrating = strip_tags($rating_data);
$final_rating = explode(",", $dbrating);

$location_data = implode(",", $location[0]);
$dblocation = strip_tags($location_data);
$final_location = explode(",", $dblocation);

$locationcode_data = implode(",", $locationcode[0]);
$dblocationcode = strip_tags($locationcode_data);
$final_locationcode = explode(",", $dblocationcode);

//Insert into database

 $data = array(); 
for($i=0; $i<count($final_number); $i++)
{
    $data[] = "('" . $final_location[0] . "', '" . $final_locationcode[0] . "', '" . $final_number[$i] . "', '" . $final_rating[$i] . "')";
}

if(count($queries) == 0)
{
    # Nothing passed
    # exit
}


$query = "insert into ratings(location, location_code, tab_no, rating) values " . implode(", ", $data); 


$hostname = "%hostname%";   // eg. mysql.yourdomain.com (unique)
$username = "%username%";   // the username specified when setting-up the database
$password = "%password";   // the password specified when setting-up the database
$database = "%database";   // the database name chosen when setting-up the database (unique)
mysql_connect($hostname,$username,$password);
mysql_select_db($database) or die("Unable to select database");

mysql_query($query) OR die(mysql_error())

At the moment the output for this is giving me the correct contents of the last page in the list of sites (the $links variable). Ultimately I want it to loop through the whole $links variable and then import that data, using the $query variable, into a database so I can do further analysis on it.

I hope this makes sense and you can see the error in my ways.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:42:36+00:00Added an answer on May 12, 2026 at 2:42 pm

    I have managed to figure it out!

    I needed to put the whole lot in the for loop, so it looks like this:

    for($c=0; $c<count($links); $c++)
        {
    $racepage = file_get_contents($links[$c]);
    preg_match_all('#<td align="right" height="18"><font color="\#ffffff">[0-9]{1,2}</font></td>#', $racepage, $number);
    preg_match_all('#<font color="\#00ffff">[0-9]{1,3}</font>#', $racepage, $rating);
    preg_match_all('#<B>[\w]+([\s][A-Z]+)?</B>#', $racepage, $location);
    preg_match_all('#<B>[\w]+\s[0-9]+</B>#', $racepage, $locationcode);
    
    //strip tags for storage in DB
    
    $number_data = implode(",", $number[0]);
    $dbnumber = strip_tags($number_data);
    $final_number = explode(",", $dbnumber);
    
    $rating_data = implode(",", $rating[0]);
    $dbrating = strip_tags($rating_data);
    $final_rating = explode(",", $dbrating);
    
    $location_data = implode(",", $location[0]);
    $dblocation = strip_tags($location_data);
    $final_location = explode(",", $dblocation);
    
    $locationcode_data = implode(",", $locationcode[0]);
    $dblocationcode = strip_tags($locationcode_data);
    $final_locationcode = explode(",", $dblocationcode);
    
    //Insert into database
    
     $data = array(); 
    for($i=0; $i<count($final_number); $i++)
    {
        $data[] = "('" . $final_location[0] . "', '" . $final_locationcode[0] . "', '" . $final_number[$i] . "', '" . $final_rating[$i] . "')";
    }
    
    if(count($queries) == 0)
    {
        # Nothing passed
        # exit
    }
    
    
    $query = "insert into ratings(location, location_code, tab_no, rating) values " . implode(", ", $data);
    
    
    $hostname = "%HOSTNAME";   // eg. mysql.yourdomain.com (unique)
    $username = "%username%";   // the username specified when setting-up the database
    $password = "%password%";   // the password specified when setting-up the database
    $database = "%database%";   // the database name chosen when setting-up the database (unique)
    mysql_connect($hostname,$username,$password);
    mysql_select_db($database) or die("Unable to select database");
    
    mysql_query($query) OR die(mysql_error());
    
    
    }
    

    Thank you all for your help, it seems like a great community that is here. I am sure to keep an eye on it for more fixes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In jQuery, I have written a piece of code that appears on every page
I have written some code in java that will guess a number based on
Working on making an inventory page for work. I have written a page that
I have written a php code which will get one id from database and
I have written a django page that requires only super users to login. So
I have written an GWT app and a static Intro page that introduces the
I have a page written in PHP that has a playlist of songs. When
I have written a simple code in page test_cookie.php to work with cookies. if(isset($_GET['data']))
I have written some code to display a YouTube video on my page but
I have a website that returns search results from Twitter, written in C# ASP.NET.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.