Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Posts posted by wildteen88

  1. when you bet 1 It says you lost and you lose your point but it doesn't remove it, Same with if you win it says you gain the point but doesn't add it....

    Do you mean it is not updating your database?

     

    I have tested your function and can confirm it does add points when you win and takes points when you loose. If you create a new file and add this code in it

    <?php
    function bet ($bet, &$user){
    //sleep(2);
    
    //$user1 = mysql_query("SELECT * FROM `users` WHERE `id`='" . $_SESSION['id'] . "'");
    //$user = mysql_fetch_object($user1);
    
    $chance = rand (1, 2);
    $bet = round ($bet);
    $betPretty = number_format ($bet);
    
    if ($bet == 0) { $echo = "You did not bet anything!"; $chance = 0; }
    if ($bet < 0) { $echo = "You cannot bet a negative number."; $chance = 0; }
    if ($bet > $user->minigame_points) { $echo = "This is more minigame points than you have!"; $chance = 0; }
    if ($user->minigame_points == 0) { $echo = "You do not have any minigame points."; $chance = 0; }
    
    if ($chance == 1) {
    	//Win
    	$money = $user->minigame_points+$bet;
    	$times_bet = $user->times_bet++;
    	//mysql_query ("UPDATE `users` SET `minigame_points`='" . $money . "', `times_bet`='" . $new_bet . "' WHERE `username`='" . $user->username . "'");
    	$money = number_format($money);
    	$echo = "You won $betPretty minigame points!<br /><b>Current Minigame Points:</b> $money";
    }
    if ($chance == 2) {
    	//Lose
    	$money = $user->minigame_points-$bet;
    	$times_bet = $user->times_bet++;
    	//mysql_query ("UPDATE `users` SET `minigame_points`='" . $money . "', `times_bet`='" . $new_bet . "' WHERE `username`='" . $user->username . "'");
    	$money = number_format($money);
    	$echo = "You lost $bet minigame points.<br /><b>Current Minigame Points:</b> $money";
    }
    
        return $echo;
    }
    
    $user = new stdClass;
    $user->minigame_points = 100;
    $user->times_bet = 0;
    
    echo bet(10, $user);
    ?>

    All I did was comment your queries and hard coded in some dummy data to test the function with.

  2. Probably because you're trying to access an item from your array when defining ${$language}['succesfull login'] as global. You cannot defined an array item as global only variables can be defined as global.

     

    You should ideally pass your variables to your function rather than define them as global.

  3. As the query returns both the news and the comments. You will need to first extract the news article and then add all the comments into an array. Then where you want your comments to display you'll then use a foreach loop to output your comments.

  4. I guess when you view a news entry your url is like site.com/news.php?id=1. Which displays the news article with the id of 1 from your news table. If thats the cause you can use a JOIN which will query both your news and newscomments table at the same time. Example join query.

     

    SELECT 
        n.title, n.author, n.article,
        c.username, c.email, c.coment
    FROM news n 
    LEFT JOIN newscomments c 
        ON (c.News_ID = n.ID)
    WHERE n.ID = $news_id

  5. A function I came with.

    function halfRound($num)
    {
        // round number to nearest tenth
        $wR = round($num, 1);
        // get the difference
        $dif = $wR - $num;
    
        // check difference
        if($dif < 0)
            $num = $wR + 0.05; // add 0.05 to rounded number
        elseif($dif > 0)
            $num = $wR - 0.05; // take 0.05 to rounded number
    
        return $num;
    }
    
    $array = array(0.11, 0.28, 0.71, 10002.71);
    
    foreach($array as $item)
    {
        echo "<p>$item rounded to " . halfRound($item) . "</p>";
    }

  6. <!DOCTYPE html> has nothing to do with PHP. As you're using sessions I guess you have written your own session handler for saving your sessions to the database. When you call session_start() to create a session make sure you calling that function before any html has been sent to the web browser. If you call it after html has been sent session will no longer work.

  7. The problem is to with your regex pattern.

     

    If the url is www.test.com.net

     

    The first bit ^($label) which is expanded to

    ^([\\w][\\w\\.\\-]{0,61}[\\w])

    Is matching www.test.com.

     

    And the second part to your pattern \\.($tld_s), which is expanded to

    \\.(com|net|org|co\.uk)

    Is matching the .net part of your url.

     

    So the problem your first pattern is being too greedy. You'll need to modify it so it doesn't match your tlds. I have came up with a different pattern to try. For $label set it to the following pattern www\.?([\w-]+){0,61}.

  8. I maybe wrong but wouldn't it be easier to implode your $tld_list array into your pattern using the pipe character as a the separator. That way preg_match will only match the urls that contain the tlds within your array.

    $label = '[\\w][\\w\\.\\-]{0,61}[\\w]'; 
    
    $tld_list = array('com', 'net', 'org', 'co.uk', 'mobi');
    $tld_s = implode('|', array_map('preg_quote', $tld_list));
    
    foreach($lines as $line)
    {	
    // check that each line/domain is in the valid format, else return an error for each domain
    if(preg_match( "/^($label)\\.($tld_s)$/", $line, $match ))

     

  9. Because you have missed of the comma in str_replace

    echo "<p>" . $_SERVER['SERVER_NAME'] . "/" . strtolower(stripslashes(str_replace($row['name'])," ", "-")) .".php</p>";

    Notice the highlighted comma.

  10. Your code is not syntactically valid at all. All text/html you want to be outputted should be wrapped in quotes not curly braces as violinrocker demostrated.

    <?php
    if ($_GET=='')
    { 
        echo '<form name="input" action="http://www.xxx.uk/index.php?name=ro" method="post">
    Enter student number:<input type="text" name="sid"/>
    <input type="submit" value="Submit">"
    </form>';
    }
    elseif ($_GET=='ro')
    {
        echo "the really long content that you want in here";
    }
    ?>

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.