AndrewFerrara
AndrewFerrara

Reputation: 2403

Sending GET data to a url from a database

EDIT: I want to load the page for each gamertag, so that it creates the images.

EDIT 2: Here is new script I have, if it were working correctly the the page would have more than 2 images on it

<?php
require_once('sql.php');

$result = mysql_query("SELECT * FROM gamertags");

while($row = mysql_fetch_array($result)){
    // Prepare gamertag for url
    $gamertag = strtolower($row['gamertag']);
    //echo $gamertag.'<br />';
    $url = "http://halogamertags.com/tags/index.php?player_name=".urlencode($gamertag);
    $get_result = file_get_contents($url);
}
?>

Upvotes: 0

Views: 412

Answers (3)

Jimmy Sawczuk
Jimmy Sawczuk

Reputation: 13614

Checked the URL you provided, it's a link to a page that has a bunch of image templates you can use. I chose one and went with it:

<?php
require_once('sql.php');

$result = mysql_query("SELECT * FROM gamertags");

$images = array();

while ($row = mysql_fetch_array($result))
{

    $gamertag = $row['gamertag'];

    // assuming this URL is just an image
    $url = "http://halogamertags.com/tags/sig2.php?player=".urlencode($gamertag);

    $images []= $url;
}

foreach ($images as $img)
{
    echo '<img src="'.$img.'"><br />';
}

Upvotes: 0

alex
alex

Reputation: 490481

In case it wasn't obvious, this code should be placed at the end of your foreach block.

You should also skip the str_replace() and just use urlencode() as per the example below.

file_get_contents(
 'http://halogamertags.com/tags/index.php?player_name=' . urlencode($gamertag)
);

Assuming allow_url_fopen is on in your php.ini.

Otherwise, use a library such as cURL.

Update

Here is new script I have, if it were working correctly the the page would have more than 2 images on it

You only have two img elements there. You need to provide much more information and code.

Upvotes: 0

Raisen
Raisen

Reputation: 4495

$tag_encoded = urlencode($gamertag);

$url = "http://halogamertags.com/tags/index.php?player_name=$tag_encoded";

// To request the page's content
$html = file_get_contents($url);

Upvotes: 2

Related Questions