I have a tool that checks available names in a game using cURL, and it should show available ones to the user running the check, and just dismiss the taken ones. Basically when you run a test on a list of names, it checks them all and inserts them into the database with their availability, either 0 for taken or 1 for available.
Right now, the page doesn't load until the check is done, then they're all inserted as a whole in the database. I'd like it to dynamically show the status of the check (i.e. "Checked name 405/4938") and show a loading image while the names are being checked, while also displaying available names as they're checked. Then at the end, remove the loading image, and just have the now complete list of available names.
How should I go about doing this? I don't know much about jQuery/AJAX. It's not ideal right now that they're all displayed as a mass at the end.
This is the code on the name check thread.
<?php
$query = mysql_query("SELECT * FROM `lists` WHERE id = '$id'");
while($row = mysql_fetch_assoc($query)) {
$id = $row['id'];
$list = $row['list'];
foreach(explode("\n", $list) as $listItem) {
checkname_RS(trim($listItem));
}
}
This is the function for the check.
<?php
function checkname_RS($name) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://services.runescape.com/m=hiscore/compare.ws?user1=" . $name);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
if (stristr($output,"Skill Stats")) {
mysql_query("INSERT INTO names (name, plat, status) VALUES ('$name', 'Runescape', '0')") or die(mysql_error());
}
if (stristr($output,"Member Rankings")) {
mysql_query("INSERT INTO names (name, plat, status) VALUES ('$name', 'Runescape', '1')") or die(mysql_error());
}
curl_close($ch);
}