Hi Pals,
Howz the day? Im a newbie to PHP but wants to learn quickly the baseline of the PHP-MYSQL
programming because of time-frame.So if anyone who have better knowledge in PHP-MYSQL can
change the following script from ASP to PHP-MYSQL.
---------------------------------------------------------
ASP CODE
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "sample"
set rsprod = server.CreateObject("ADODB.Recordset")
rsprod.Open "select prd_nam from tbl_prod_details where psta =1 order by pdat desc",objConn,1,2
rsprod.MoveLast
cnt = rsprod.RecordCount
cnt1 = cnt
rndMax = cnt
If 6 < cnt Then
cnt1 = 6
End If
str = ","
str1 = ","
Do Until cnt1 = 0
Randomize
RndNumber = Int(Rnd * rndMax)
If (InStr(1, str1, "," & RndNumber & "," ) = 0) Then
str1 = str1 & RndNumber & ","
cnt1 = cnt1 - 1
rsprod.MoveFirst
rsprod.Move RndNumber
str = str & rsprod("prd_nam") & ","
End If
Loop
rsprod.Close
Set rsprod = Nothing
----------------------------------------------------------
Scenario is to get the random 6 names from the set of values in the database.Where <str> is
the variable to store the random numbers with delimiter of , (eg., Pepsi,Coke,Cake)
(Where Pepsi Coke Cake are stored in the database as a product name)
Any help would be greatly appreciated in this issue.
Cheers
SATHISH
Howz the day? Im a newbie to PHP but wants to learn quickly the baseline of the PHP-MYSQL
programming because of time-frame.So if anyone who have better knowledge in PHP-MYSQL can
change the following script from ASP to PHP-MYSQL.
---------------------------------------------------------
ASP CODE
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "sample"
set rsprod = server.CreateObject("ADODB.Recordset")
rsprod.Open "select prd_nam from tbl_prod_details where psta =1 order by pdat desc",objConn,1,2
rsprod.MoveLast
cnt = rsprod.RecordCount
cnt1 = cnt
rndMax = cnt
If 6 < cnt Then
cnt1 = 6
End If
str = ","
str1 = ","
Do Until cnt1 = 0
Randomize
RndNumber = Int(Rnd * rndMax)
If (InStr(1, str1, "," & RndNumber & "," ) = 0) Then
str1 = str1 & RndNumber & ","
cnt1 = cnt1 - 1
rsprod.MoveFirst
rsprod.Move RndNumber
str = str & rsprod("prd_nam") & ","
End If
Loop
rsprod.Close
Set rsprod = Nothing
----------------------------------------------------------
Scenario is to get the random 6 names from the set of values in the database.Where <str> is
the variable to store the random numbers with delimiter of , (eg., Pepsi,Coke,Cake)
(Where Pepsi Coke Cake are stored in the database as a product name)
Any help would be greatly appreciated in this issue.
Cheers
SATHISH
Comment