Jump to content

joel24

Members
  • Posts

    760
  • Joined

  • Last visited

Posts posted by joel24

  1. in the array

     

    [1] => Admin

    [2] => User

     

    is 1 the admin user_type_id?

     

    if so..

    you'd have somthing like this

     

    $sql = @mysql_query("SELECT * FROM user_types");
    
    while ($r = mysql_fetch_array($sql))
    {
    $userTypes[$r['user_type_id']] = $r['user_types'];
    }
    

    then you'd have an array with

    $userTypes[1] = "Admin"

    $userTypes[2] = "User" etc

  2. you'd have to have a function in that class like

    function returnUserName()
    { 
    return $this->username;
    }
    

     

    then call that objects function.. i.e. if the object was $user1

    
    class MyApp
    {
    
    function __construct()
    
    {
    
    global $dbHost;
    
    global $dbUser;
    
    global $dbPass;
    
    global $dbName;
    
    $this->DB = new Database;
    
    $this->DB->connect($dbHost, $dbUser, $dbPass, $dbName);
    
    
    $user = new User;
    $username = $user->returnUserName();
    
    
    echo $User->login;
    echo $this->User->login;
    }
    }
    

  3. with prepend it would just add the last entry when it was being sent to the database, you can also do it another way... which might be easier...

     

    you can create a PHP page which calls that create_output function and displays it on an otherwise blank page.

    like

    updateGuestBook.php

     

    then on the page the guestbook entries would be listed in a div with id guestBookEntries

     

    $("#guestbook_submit").click(function(){
       //get the id
       //the_id = $(this).attr('id');
       $(".postmsg").fadeOut(50);
    
       // show the spinner
       $('.postmsg').append('<img src="images/loader.gif" alt="Loading" />');
       
       //the main ajax request
    
       var dataString = $("#guestbook_form").serialize();
    
       $.ajax({
          type: "POST",
          data: dataString,
          url: "add_post.php",
          timeout: 2000,
          cache: false,
          success: function(msg)
          {
             $("#loading").remove();
             $(".postmsg").fadeIn(400);
             $(".postmsg").html(msg);
             setTimeout("$('.postmsg').fadeOut();",2000);
     $.post("updateGuestBook.php", 
    					   function(data) {
    						   if (data.length > 0) {
    							   $('#guestBookEntries').html(data);
    						   } else {
    							   $('#guestBookEntries').html("<div align='center'>Error retrieving item details</div>");
    						   }
    					   });
          }
       });
    return false;
    });
    

     

    that code will call the updateGuestBook.php file and get the HTML of the page and put it into the #guestBookEntries div

    also the line

            setTimeout("$('.postmsg').fadeOut();",2000);

    should make the .postmsg div fade out after 2seconds... before it was set to 60000 (60secs)

     

     

  4. there's a bit of scripting involved, have you played around with jquery?

     

    it'd depend on how you have your guestbook layed out.

     

    but

    pretty much you write the html and insert it at the top of the div containing the guest book entries...

    but pull the values using jquery... then put them in there..

     

    i.e. the jquery would be like

    $("#guestbook_submit").click(function(){
       //get the id
       //the_id = $(this).attr('id');
       $(".postmsg").fadeOut(50);
    
       // show the spinner
       $('.postmsg').append('<img src="images/loader.gif" alt="Loading" />');
       
       //the main ajax request
    
       var dataString = $("#guestbook_form").serialize();
    
       $.ajax({
          type: "POST",
          data: dataString,
          url: "add_post.php",
          timeout: 2000,
          cache: false,
          success: function(msg)
          {
             $("#loading").remove();
             $(".postmsg").fadeIn(400);
             $(".postmsg").html(msg);
             setTimeout("$('.postmsg').fadeOut();",2000);
    $("#guestbookEntries").prepend("<b>Entry Number: whatever, etc etc</b><div>rarara</div>");
          }
       });
    return false;
    });
    

     

    <div id="guestbookEntries">

     

    <!-- other entries -->

    </div>

     

     

    check out

    http://docs.jquery.com/Manipulation/prepend#content

  5. i think its because of the scope of a function.

    i.e.

    function get_name(){
          $name = "Jimmy Goe"
          echo $this->name;
       }
    

     

    $name within the function and $name in the class are two separate variables, because the scope of a variable within a function is local..

     

     

    try

     

    function get_name(){
          $this->name = "Jimmy Goe"
          echo $this->name;
       }
    

  6. you've got a problem with your jquery/ajax.

    the data isn't being sent properly...

    use the serialize() function to put the form element into a readable state for the php...

     

    you have the give the guestbook form an id.

    i.e.

    <form class="guestbook_form" action="add_post.php" method="post">
    <label>Nickname:</label>
    <?php
    db_connect();
    if(!$_SESSION['user']['username'])
       {
       $username = "Anonymous";
       echo '<input type="text" readonly="readonly" name="guestbook_name" class="guestbook_name" value="'.$username.'" />';
       }
    else
       {
       $username = $_SESSION['user']['username'];
       echo '<select name="guestbook_name" class="guestbook_name" id="guestbook_name">
                <option value="'. $username .'">'. $username .'</option>
                <option value="Anonymous">Anonymous</option>
             </select>';
       }
    
    $query = "SELECT * FROM `categories`";
    $results = mysql_query($query);
    echo '<select name="category" class="category" id="guestbook_category">';
    while ($row = mysql_fetch_array($results))
       {
       $catid = $row['cat_id'];
       $catname = $row['category'];
       echo '<option value="'.$catid.'">'.$catname.'</option>';
       }
    echo "</select>";
    
    ?>
    
    <p class="label">
    <label>Message:</label><textarea cols="50" rows="10" name="guestbook_message" id="guestbook_message"></textarea>
    </p>
    <p class="label">
    <label></label>
    <span class="postmsg">
    </span>
    </p>
    <p class="submit">
    <button type="submit" class="submit" value="Submit" id="guestbook_submit" name="guestbook_submit">Submit</button>
    <button type="submit" class="close">Cancel</button>
    </p>
    </form>
    

     

    then change the jquery to the following

    $("#guestbook_submit").click(function(){
       //get the id
       //the_id = $(this).attr('id');
       $(".postmsg").fadeOut(50);
    
       // show the spinner
       $('.postmsg').append('<img src="images/loader.gif" alt="Loading" />');
       
       //the main ajax request
    
       var dataString = $("#guestbook_form").serialize();
    
       $.ajax({
          type: "POST",
          data: dataString,
          url: "add_post.php",
          timeout: 2000,
          cache: false,
          success: function(msg)
          {
             $("#loading").remove();
             $(".postmsg").fadeIn(400);
             $(".postmsg").html(msg);
             setTimeout("$('.postmsg').fadeOut();",60000);
          }
       });
    return false;
    });
    

  7. for the price use BETWEEN

    i.e.

    you'd have priceMin and priceMax on the form.

    $priceMin = isset($_GET['priceMin']) ? $_GET['priceMin'] : 0;
    
    if (isset($_GET['priceMax'])) {
          $types[] = isset($_GET['price'])?"`price` BETWEEN $priceMin AND $priceMax":'';
    } else {
          $types[] = isset($_GET['price'])?"`price` >= $priceMin":'';
    }
    

     

    is the script working at present?!

    I don't get exactly what you want us to do...?

  8. you'd have a database with columns song_id, day_start, day_hits, week_start, week_hits, total_hits

     

    then run a script like the following for each time the song page is viewed...

    $song_id = 'the song id';
    
    $sql = @mysql_query("SELECT * FROM song_hits WHERE song_id = $song_id");
    $song_hits = mysql_fetch_row($sql);
    
    if ($song_hits['day_start'] == date('z')) {
    $sql_day = ' day_hits = ' . $song_hits['day_hits']++ . ', ';
    } else {
    $sql_day = ' day_start = ' . date('z') . ', day_hits = ' . $song_hits['day_hits']++ . ', ';
    }
    
    if ($song_hits['week_start'] == date('W')) {
    $sql_week = ' week_hits = ' . $song_hits['week_hits']++ . ', ';
    } else {
    $sql_week = ' week_start = ' . date('W') . ', week_hits = ' . $song_hits['week_hits']++ . ', ';
    }
    
    $sql_total = ' total_hits = ' $song_hits['total_hits']++;
    
    $sql = @mysql_query("UPDATE song_hits SET $sql_day $sql_week $sql_total WHERE song_id = $song_id");
    
    

  9. noo i meant so the automatically added gold was never stored in the database...

    instead only acquired gold was stored in there... and then each time the user interacted with someone or someone viewed their gold it would add the amount in teh database + (current unix timestamp - account creation timestamp) / 60

     

    i.e. if they might have -400 gold in the database however since they've been a member so long they actually have 10000 gold.

     

    i guess then there's issues if you want to select the person with the most gold from the database etc etc...

     

    other way is to write a script which runs each time the user is interacted with... and after it puts in gold it adds the current unix timestamp to the database, so next time someone interacts with the user it adds the amount of gold accumulated since the previous interaction...?

  10. andy is on the right path,

    you could have someones gold stores what is in the database plus the amount automatically given to them since their account creation

    i.e. have a unix timestamp of their creation, then each time someone interacts with that user they work out the amount of gold that user has

    which would be

    (current unix timestamp - account creation timestamp) / 60 (for minutes).

    then add that to the amount in the database, which is not inclusive of any automatically given gold... and could be a negative or positive number...

    so when someone stole gold or wanted to see how much gold a person had

    $sql = @mysql_query("SELECT accountCreation, gold FROM users WHERE userid = xx");
    $results = mysql_fetch_row($sql);
    
    //amount of gold in users account
    $gold = (time() - $results['accountCreation']) / 60 + $results['gold'];
    

     

    either that or you can have it so each time a user logs on or a user interacts with another user, a script runs which updates the amount of gold in their account...

     

×
×
  • 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.