Jump to content

mrdhood

Members
  • Posts

    29
  • Joined

  • Last visited

    Never

Posts posted by mrdhood

  1. Closest you could do would be

     

    <?php
    class A
    {
    var $b;
    }
    class B extends A
    {
    function __construct()
    {
       $this->b = $this;
    }
    }
    
    

    I honestly don't see much point, as most of the time you don't need to access child classes.

     

    Another way would be

    class A
    {
    var $b;
    function __construct()
    {
       $this->b = new b;
    }
    }
    class b
    {
    function test() { echo 'test b'; }
    }
    

  2. 1. In your code, you have an echo $query; Does it output the query string you expect?

    In other words, the first question is:

    Does the regex work according to the specs you specified?

    You may have other problems (talking to the database), but first, we need to know: does the regex do what you wanted it to do?

     

    No it's outputting what I inputted: "SELECT * FROM `{settings}`"

     

    2. We prepared a query string ($query) according to your specs using regex, and I have no idea if the syntax of the query itself is correct, I only looked at your specs. But you seem to be executing a different query altogether anyhow.

    I was expecting to see something like:

     

    $result=$db->query($query);

     

    Not

    Execute(a query completely unrelated to $query)

     

    (The query method above assumes you have already created a database object, at its simplest form:

    $db= new PDO ($dsn,$dbUser,$dbPass); 

    You are probably using another database interface.)

     

    Execute($query): $query = "SELECT * FROM `{settings}`" Which is exactly what I told you it would be, I'm just trying to change {settings} to $tables['settings']

  3. How is this different from the first solution I gave you?

     

    As requested, among other things, it replaces whatever is in the braces: {settings}, {users} or whatever with

    $tables['settings'], $tables['users'] or whatever.

     

    Please be as clear as possible as it is very hard to troubleshoot regex without extremely clear communication about desired input and output.

     

    In all honesty I don't know..

     

    static function Execute($query)
    	{
    		$tables = self::$config['tables'];
    		$subject='"SELECT * FROM `{settings}`"';
    		//echo self::$config['tables']['settings'];
    		echo $tables['settings'];
    		$query = preg_replace('/"SELECT \* FROM `\{([^}]+)\}`"/', '"SELECT * FROM `".$tables[\'\1\']"', $subject);
    		echo $query . "<br />";
    }
    

     

    is what I have right now. then I call Database::Execute("SELECT * FROM `{settings}`"); and it outputs this:

    SELECT * FROM `{settings}`

    Table 'sports_sports.{settings}' doesn't exist

     

    Thank you for your help and patience thus far by the way.

  4. $tables = array(
    'settings' => $prefix . 'settings',
    'users' => $prefix . 'users'
    );
    
    $query = "SELECT * FROM `{users}` WHERE `user_id`='" . $Visitor->user_id . "'";
    // Should be $query = "SELECT * FROM `" . $tables['users'] . "` WHERE `user_id`='" . $Visitor->user_id . "'";
    

  5. I imagined it'd be something like:

    $query = preg_replace('`\{([^}]+)\}`', "self::$config['tables'][$1]", $query);
    

     

    but that errors as

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in

     

    and

     

    $query = preg_replace('`\{([^}]+)\}`', '"self::$config[\'tables\'][$1]'", $query);

    as

    Parse error: syntax error, unexpected '"' in
  6. I was trying to use $1 :/. I had almost the same thing at one point.

     

    How would I go about just changing {table} to $tables[\1\]? That way the following examples wouldn't be bothered:

    SELECT `id` FROM `{table}`

    SELECT * FROM `{table}` WHERE `id`='1'

    and so on.

  7. I know this should be simple but I am terrible with preg_replace and keep returning blank results.

    I'm attempting to make "{table}" change to the value of $tables['table'], for example: "SELECT * FROM `{settings}`" would change to "SELECT * FROM `" . $tables['settings'] ."`

  8. I don't have the information from when time() and $event['when'] weren't working.

     

    1322420400 is the int that strtotime("Next Sun, 1:00 PM") returns on my machine, is that the same on yours?

  9. Hey I'm having issues with using strtotime(), date(), and time().

     

    I have a couple problems.

    The first is: I used strtotime to get the unix of a specific date and time (worked great, even outputted the correct time using date() to return it). However when I went to post information on it (I set it up so that you can't post after the event started), it told me it already started like an hour before it was supposed to. I used

    if (time() > $event['when']) { echo "too late."; } else { do it }

    to determine.

     

    That had me very confused.

     

    Then I decided instead of manually inputting the event times I would pull them from an xml file, which I had no trouble reading.

     

    I used:

     strtotime("Next $day, $time PM")

    with $day = Sun, $time = 1:00- This outputted a unix timestamp but then date() returned it as being 7 pm on sunday instead.

     

    Any ideas what would be causing these strange things?

  10. I just opened a forum for sport discussion. I'm attempting to figure out how I want to have it, right now by going to http://www.sportsdiscussion.net you can see the two methods I'm considering.

     

    1) {Sport} (ex: Basketball), Boards are "NBA", "NCAA" - will add a board for each league, like Football would have NFL, NCAA, Arena, United Football League, with each board having child boards for "News", "Teams (each team has a grandchild board)" "Players", "General Discussion".

     

    OR

     

    2) Just hitting the main leagues as each category. Instead of Basketball just having "NBA" and then the 4 boards are on the index.

     

    Also I would like some feedback on the forum's theme and the site concept (do you think this will be successful? what do you think of the domain choice). If you are going to tell me I shouldn't have used SMF please explain why, instead of just saying "bad choice" or "should have used {other software}".

     

    Thank you,

    site: www.sportsdiscussion.net

  11. Main Object
    (
    [Visitor] = Visitor Object
    (
    	[user_info] => Array
    	(
    		[username] = user
    		[user_id] = 1
    	)
    )
    [Room] = Room Object
    (
    	[info] = Array(
    		[id] = 1
    		[name] = Lobby
    	)
    	[messages] = Messages Object
    	(
    		[messages] = Array
    		(
    			[0] = Array()
    		)
    	)
    )
    )
    

    Is there a way to get the visitor info within the Messages Object?  I'm building it such as $Main = new Main; $Main->Visitor = new Visitor; $Main->Room = new Room; $Main->Room->Messages = new Messages; so they're not static I know that I can pass the $this var through each but that duplicates the class each time and I'm 99% sure that's bad.

  12. search_array[0][1] returns

    Array ( 0 => array( 0 => '', 1 => 'THIS' ) )

    or

    search_array[0][0][1] returns

    Array (0 => array (0 => array( 0 => '', 1 => 'THIS' ) ) )

     

    Once you figure out which one of those gives you "tom" you can get cruise from changing 1 to 2

     

    you can combine the two by doing something like

     

    var name = array[0] + " " + array[1];

     

    you have to change "Array[0]" and "array[1]" to the right variables of course.

  13. I have a function that I need accessed two ways. The first way works which is with an ajax json request.

    it loads name(data) which then does alert(data['user_info']['username']);

    This works perfect.

    However I can't figure out how to set it up when a user clicks a span element it alerts their username. An exmaple code that I'm trying to use would be something like this:

     

    <span onclick="name('[\'user_info\':[\'username\':\'test\']]');">click</span>

     

    This will not work.

     

    alert(data); results in "['user_info':['username':'test']]"

     

    It won't convert it to an array.

    using new Array() did not help. (at least the way I tried).

     

    Thanks for any help. I did try to search, I'm probably doing some dumb mistake that I'm just overlooking.

  14. I've tried searching and I'm not sure if this is even possible due to the lack of (good) results.

     

    I'm trying to make it so that when you click a button the actual stylesheet changes. I want for example:

     

    <style>h1{ color: #aa000; }</style>
    <h1>Test</h1>
    

     

    would obviously make h1 have a font color of aa0000. Well I'm trying to make a button that changes that one to 00aa00 instead which is not a problem. Very easy actually especially since I use jquery. However I also create new h1 elements through ajax and those ones use the original aa0000 color because of the stylesheet. I want to know how to make new elements have the new color also.

  15. Yes.

    I'm making a chat room and instead of having 9 fields in the message table I have a couple and then user_info which consists of username=mrdhood&user_color=aa0000&message_color=aa0000 well the function I posted works great. Except now I got the idea to pass "actions" the same way except that one is gonna require arrays to be passed instead of strings.

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