Hi,
I'm using a do while loop to parse data via a socket connection to a remote server, brings back an ID and puts all this info into our database.
This works spot on when there is only one instance in the loop. It connects, brings back for example ID 600 and stores it in the database.
When there is more than one instance of the loop it connects, sends the data and puts all items in the database with the same ID. Not good, they need to be unique. All IDs would be say 601 when they should be 601 602 and so on.
I've checked with the people who run the remote server and they are sending out different ID's. Why is it then that this code does not recognise each one as unique and how do I get over this problem?
do {
// TRY TO CREATE SOCKET CONNECTION
if(!($myFile=fopen("$url?$string","r")))
{
echo "SOCKET CONNECTION HAS FAILED";
// QUIT NOW THERE'S NOTHING ELSE TO BE DONE HERE
exit;
}
// SOCKET CONNECTION OKAY LET'S ROCK
// GET RESPONSE AND PROCESS
while(!feof($myFile))
{
$myLine.=fgets($myFile,255);
}
fclose($myFile);
// STRIP AWAY ALL HTML AND NON ESSENTIAL OUTPUT
$start="= ";
$end="\n\r\n";
$start_position=strpos($myLine, $start);
$end_position=strpos($myLine, $end)+strlen($end);
$length=$end_position-$start_position;
$myLine=substr($myLine, $start_position, $length);
$messageid="$myLine";
$messageid= ereg_replace("<[^>]*>","",$messageid);
$messageid= ereg_replace("\n","",$messageid);
$messageid= ereg_replace("\r","",$messageid);
$messageid= ereg_replace("=","",$messageid);
$messageid= ereg_replace(" ","",$messageid);
// OUTPUT SOMETHING TO THE BROWSER TO INDICATE MESSAGE SENT
echo "<font face=\"$font\" size=\"1\">Cell: $sender ID: $messageid</font><br>";
// SETUP DATABASE PARAMTERS
$db = mysql_connect("localhost", "$usern", "$passw");
mysql_select_db("$database",$db);
// REPLACE ' WITH \' SO WE CAN STICK THIS IN THE DATABASE OKAY
$message = ereg_replace("'","\'",$message);
// ADD THIS TO THE DATABASE
$addsql = "INSERT INTO `SMS` (`id`, `sender`, `network`, `keyword`, `message`, `time`, `transid`, `rate`, `cut`, `type`, `opt`, `status`) VALUES ('', '$sender', '$network', '$login', '$messagefordb', '$time', '$messageid', '$rate', '$cut', 'out', '$opt', 'P')";
$aresult = mysql_query($addsql);
flush();
}
while ($myrow = mysql_fetch_array($result));
I've tried using a foreach loop as well as the do while, added a sleep(1); to see if that would work and still duplicate IDs.
$messageid = $messageid + 1; is no help in there either.
Any help is most appreciated.
Thanks in advance