[PHP] Time and Random

Joined
May 30, 2008
Messages
558
Reaction score
64
ok heres my script
PHP:
<?php
session_start();
include'./connection/globals.php';

if($_SESSION['id']){
$sql = "SELECT * FROM timecard WHERE id='".$_SESSION['id']."'";
$res = mssql_query($sql);
$row = mssql_fetch_assoc($res);
if(time() > $row['next']){
	if(!$_POST['random']){
	echo "click to get random item<br>";
	echo "<form action=\"?act=random\" method=\"POST\">";
	echo "<br><input name=\"random\" type=\"submit\" value=\"Get Item\"><br>";
	echo "</form>";
	}else{
		$id1 = "1";
		$id2 = "2";
		$id3 = "3";
		$id4 = "4";
		$id5 = "5";
		$rand = rand($id1,$id5);
		
		$sql2 = "INSERT INTO AccountItem (AID,ItemID) VALUES ('".$_SESSION['id']."','$rand')";
		$res2 = mssql_query($sql2);
		if($res2 == TRUE){
			$itemsql = "SELECT * FROM Item WHERE ItemID ='$rand'";
			$itemres = mssql_query($itemsql);
			$item = mssql_fetch_assoc($itemres);
			$next = time() + (24000);
			$sql3 = "UPDATE timecard SET time='".time()."', next='$next' WHERE id='".$_SESSION['id']."'";
			$res3 = mssql_query($sql3);
			if($res3 == TRUE){
				echo "Successfuly got the item : ".$item['Name']."";
			}
		}
	}
}else{
	echo "Please wait the full 24 hours to use this feature again!";
}
}else{
	echo "<br><a href=\"./session.php\">Here to login</a><br>";
}

?>

I need know how to do rand($id1,$id2,$id3,$id4,$id5); and the time + 24hrs
oh yeah I want the ids to be like

520529 and like 123006, because there item id's
 
Re: [PHP][HELP]Time and Random

Time + 24 hours:
PHP:
$time = time() + 86400; //86400 seconds = 24 hours

Random item ID:
PHP:
$itemID = rand(100000, 999999);

Not sure I understood what you want to do with the item IDs, exactly. If you want to select a random item from your item database:
PHP:
$sql = "SELECT `itemid` FROM `item` ORDER BY RAND() LIMIT 1";

Edit: Just noticed you were using mssql. I think the syntax for that would be something like:
PHP:
SELECT TOP 1 column FROM table
ORDER BY NEWID()
 
tried

PHP:
		$sql4 = "SELECT ItemID FROM randItem ORDER BY RAND()";
		$res4 = mssql_query($sql4);
		while($rand = mssql_fetch_assoc($res4)){
			echo "$rand";
		}

but it only echoed Array. had this problem b4 dunno why im getting it now
 
Back