Example #1
0
/**
 * Echo the value of $_GET[$var], else $val
 */
function echoValueOrDefault($var, $val)
{
    if (!empty($_GET[$var]) && maxValue($var)) {
        echo $_GET[$var];
    } else {
        echo $val;
    }
}
Example #2
0
		<meta charset="utf-8">
		<title>Upload - Step 1</title>
		
		</head>
		<body>
		<?php 
$mysqli = new mysqli("localhost", "root", "nelinecka", "test");
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit;
}
// Calculating lookup values
calcLookup();
// Getting maximum value for random generation
$Max = maxValue();
$rand = mt_rand(0, $Max);
$sql = "SELECT * FROM test_rand WHERE Lookup>=" . $rand . " LIMIT 1";
if ($result = $mysqli->query($sql)) {
    $Row = $result->fetch_object();
    var_dump($Row);
    $result->close();
}
$mysqli->close();
function calcLookup()
{
    global $mysqli;
    $Weights = array();
    $sql = "SELECT ID, Weight FROM test_rand";
    if ($result = $mysqli->query($sql)) {
        while ($Row = $result->fetch_object()) {