...

View Full Version : How to avoid redundant results



coolguyraj
08-27-2009, 06:05 PM
Hi,

I have a php script that fetches a unique record from master table and sends it to the webpage.(I have javascript on the page to perform autorefresh)

If i open multiple webpages and run the script. Instead of getting unique record each time i get the record repeated. I i go to the id siiued table i get two or more tickets with same id number.

Please tell me how can i avoide it.

Below is the code.


<?php
$db_host="localhost"; // PARAMETERS OF THE DB
$db_user="test";
$db_pass="test";
$database="test";
$rand= rand(1000000, 9999999);

mysql_pconnect($db_host,$db_user,$db_pass) or die("Unable to connect to database");
mysql_select_db($database) or die( "Unable to select database");

$row=mysql_query("SELECT * FROM t_master")or die (mysql_error());

$result=mysql_fetch_array( $row);
$id=$result['ticketid'];
mysql_query("delete from t_master where ticketid=$id");
$song1 = $result['songno1'];
$song2 = $result['songno2'];
$song3 = $result['songno3'];
$song4 = $result['songno4'];
$song5 = $result['songno5'];
$songno_1 = $result['songno_1'];


$songno_2 = $result['songno_2'];
$songno_3 = $result['songno_3'];
$songno_4 = $result['songno_4'];
$songno_5 = $result['songno_5'];

$row=mysql_query("SELECT * FROM lookup_new where songno=$song1")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$song1=$result1['songname'];
$songname1 = $song1;
$song1name = substr($songname1,0,28);
$song1movie=$result1['moviename'];
$songno1=$result1['songno'];

$row=mysql_query("SELECT * FROM songs_lookup_new where songno=$song2")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$song2=$result1['songname'];
$songname2 = $song2;
$song2name = substr($songname2,0,28);
$song2movie=$result1['moviename'];
$songno2=$result1['songno'];



$row=mysql_query("SELECT * FROM songs_lookup_new where songno=$song3")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$song3=$result1['songname'];
$songname3 = $song3;
$song3name = substr($songname3,0,28);
$song3movie=$result1['moviename'];
$songno3=$result1['songno'];
//echo $song3movie;

$row=mysql_query("SELECT * FROM songs_lookup_new where songno=$song4")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$song4=$result1['songname'];
$songname4 = $song4;
$song4name = substr($songname4,0,28);
$song4movie=$result1['moviename'];
$songno4=$result1['songno'];


$row=mysql_query("SELECT * FROM songs_lookup_new where songno=$song5")or die (mysql_error());
$result1=mysql_fetch_array( $row);
$song5=$result1['songname'];
$songname5 = $song5;
$song5name = substr($songname5,0,28);
$song5movie=$result1['moviename'];
$songno5=$result1['songno'];



//for sms test
$messageid = $_GET['MSGID'];
$mob='9999';
$mobilenumber=$mob.$rand;
$message = $_GET['MSG'];
$email = '-NA-';
$username = '-NA-';
$sex = 'not required';
$smstime = $_GET['TIME'];
$language = $_GET['DC'];

$fname='test';
$lname= 'test1';
$pno=$phone;
$sex=$sex;
$s1=addslashes($song1);
$s1name=addslashes($song1name);
$song1singer=$song1singer;
$song1movie=$song1movie;
$s2=addslashes($song2);
$s2name=addslashes($song2name);
$song2singer=$song2singer;
$song2movie=$song2movie;
$s3=addslashes($song3);
$s3name=addslashes($song3name);
$song3singer=$song3singer;
$song3movie=$song3movie;
$s4=addslashes($song4);
$s4name=addslashes($song4name);
$song4singer=$song4singer;
$song4movie=$song4movie;
$s5=addslashes($song5);
$s5name=addslashes($song5name);
$song5singer=$song5singer;
$song5movie=$song5movie;
$generatedtime=$generatedtime;
$songs=$songs;
$amount=$amount;
$payment=$payment;
$id=$id;


$query = "INSERT INTO sms_test
(
MessageID,
mobileNumber,
Message,
SMSReceivedTime,
Language

) VALUES(
'$messageid',
'$mobilenumber',
'$message',
'$smstime',
'$language'
)";

mysql_query($query) or die('Error, insert query failed:'.mysql_error());
$query = "INSERT INTO t_issued
(
ticketid,
firstname,
lastname,
phonenumber,
email,
username,
sex,
song1,
song1name,
song1singer,
song1film,
song2,
song2name,
song2singer,
song2film,
song3,
song3name,
song3singer,
song3film,
song4,
song4name,
song4singer,
song4film,
song5,
song5name,
song5singer,
song5film,
generatedtime,
nooftickets,
amount,
paymentmode,
status
) VALUES(
'$id',
'$fname',
'$lname',
'$mobilenumber',
'$email',
'$username',
'$sex',
'$s1',
'$s1name',
'$song1singer',
'$song1movie',
'$s2',
'$s2name',
'$song2singer',
'$song2movie',
'$s3',
'$s3name',
'$song3singer',
'$song3movie',
'$s4',
'$s4name',
'$song4singer',
'$song4movie',
'$s5',
'$s5name',
'$song5singer',
'$song5movie',
'$smstime',
'$songs',
'$amount',
'$payment',
'$status')";
mysql_query($query) or die('Error, insert query failed:'.mysql_error());

mysql_close();
//Return the user to the location page
echo "<HTML><head><script type=\"text/JavaScript\">function timedRefresh(timeoutPeriod){setTimeout(\"location.reload(true);\",timeoutPeriod)};</script><body onload=\"JavaScript:timedRefresh(1000);\"><STATUS></STATUS><DETAILS></DETAILS><REPLYSMS>Ticket#$id. $songno1)$song1name $songno2)$song2name $songno3)$song3name $songno4)$song4name $songno5)$song5name</REPLYSMS><LANG></LANG></body></head></HTML>";
exit;
?>

seco
08-27-2009, 06:13 PM
if you want the songs to be random, you need to add the mysql RAND() function.

coolguyraj
08-27-2009, 06:25 PM
No, I am only generating the mobile number randomly for simulation.

But the ticket ID and the song combinations are already avilable in the DB.

the php script just moves it from master table to issued table and deletes the record in the master table.

If there are multiple access at the same time two or more people will get the same record and if i check the issued table there will be duplicate ticket ids i dont want this to happen i want unique ticket from the master.At the end all the records from master table will be availabe in issued table and the number shoild match i mean to say if there are 10 records in the master table at the end of execution of the script master will have 0 records and issued sould have 10 records even if multiple users access the same page at the same time.

coolguyraj
08-29-2009, 02:00 PM
I have the records arranged in a preditermined sequence.i want to fetch it in that order itself and insert that record to issued table along with two other fields ( the moble number to whom it is sent to and the time it was sent )and finally delete that record from master after it is fetched.

It works fine.The only problem is if more than one person/webpages acesses the page at the same time there are chances that the same record/data gets issued to two mobile numbers so that should not happen every time it has to pick unique record.

Is there anyway i can tweak the code to make it happen?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum