SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Extracting a variable from a class-function

    Code:
    class updating {
    	function update() {
    		$aaa = rand(0,10000000);
    		$conn = mysql_connect('localhost', 'user', 'pass');
    		mysql_select_db('database1');
    		$sqls = "UPDATE `table1` SET column1='$aaa'";
    		$results = mysql_query($sqls, $conn);
    		mysql_close($conn);
    		return $aaa;
    	}
    }
    $now = new updating;
    $now->update();
    How do you extract $sec from $now?

    I have tried:

    $aaa = $now;

    and

    $aaa = update();

    I need $aaa to continue with my programming.

  2. #2
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're returning the variable from the function, so just

    PHP Code:
    $aaa $now->update(); 
    should do it.

    But honestly this is a horrible object design. What exactly are you trying to do?
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •