Monkeymatt
Members-
Posts
35 -
Joined
-
Last visited
Never
Everything posted by Monkeymatt
-
PHP is a scripting language and does not go through and replace constants first like pre-processor directives. To do such a thing, you would have to do it this way: $CONNECT="odbc_connect"; ... $this->con=$CONNECT($this->dsn,$this->uname,$this->password) or die(odbc_errormsg());
-
Using number_format() with Text Include
Monkeymatt replied to phpBeginner06's topic in PHP Coding Help
You used include() wrong, as kenrbnsn said. You can do what I think you want to this way: [code] <?php $somenumber=file_get_contents("01-25-2007.txt"); $formatted=number_format($somenumber); echo "$formatted"; ?> [/code] Monkeymatt -
I've got this weird error: [quote] Strict standards: Non-static method Forum::load_many() cannot be called statically, assuming $this from compatible context Forum in C:\Xampp\xampp\htdocs\ekinboard\v2\class\database.class.php on line 184 [/quote] Here is line 184: [code] $this->has_many_data[$name]=call_user_func_array(array(self::$has_many[$this->class][$name]["class"], "load_many"), array(array(array(self::$has_many[$this->class][$name]["foreign_id"],'=',$this->id))+self::$has_many[$this->class][$name]["conditions"], self::$has_many[$this->class][$name]["order"], null, null, null, self::$has_many[$this->class][$name]["class"])); [/code] Here is Forum::load_many definition: [code] public static function load_many(array $where, array $order=array(), $in=null, $low_limit=null, $num=null, $class=null) { global $FINAL_CLASS; return parent::load_many($where, $order, $in, $low_limit, $num, $FINAL_CLASS[get_class()]); } [/code] parent::load_many is here: [code] public static function load_many(array $where, array $order=array(), $in=null, $low_limit=null, $num=null, $class=null) { $return=parent::load_many($where, $order, $in, $low_limit, $num, $class); if ($return === false) { return $return; } if ($class == null) { $class=get_class(); } $table=self::$tables[$class]; global $model; foreach ($return as $to_save) { $model->{$table}[$to_save->id]=&$to_save; } return $return; } [/code] last parent::load_many: [code] public static function load_many(array $where, array $order=array(), $in=null, $low_limit=null, $num=null, $class=null) { if ($class == null) { $class=get_class(); } if (in_array($class, self::$disallowed_classes)) { global $error; $error->make_error(4, "Attempted to load_many() of '".$class."' which is not allowed"); return false; } if (empty(self::$tables[$class]) || empty(self::$id_row[self::$tables[$class]])) { global $error; $error->make_error(5, "Missing information necessary for '".$class."' to initiate"); } $results=self::$database->select(self::$tables[$class], $where, $order, $low_limit, $num, array('*'), $in); $return=array(); foreach ($results as $resultnow) { $temp=new $class(); $temp->load_array($resultnow); $return[]=$temp; } return $return; } [/code] Any help would be appreciated. Monkeymatt
-
I have a [b]static[/b] function that needs to know the name of the class that was used to call it (waaaaaaay up the inheritance chain). get_class() only gives me the name of the class that the static function is in, but I need the name of the top class that was called. Is there any way to do this. Thanks, Monkeymatt
-
Does PHP have a preprocessor like C / C++?
Monkeymatt replied to roopurt18's topic in PHP Coding Help
Just use debug_backtrace() to see what the line number and such were at the function call. http://us3.php.net/manual/en/function.debug-backtrace.php Monkeymatt -
A form name with [] after it will automatically fill an array on the PHP page - this could be used with javascript to get a dynamic number of dates. [code] <input type="text" name="dates[]" /> [/code] would make an array: [code] $_POST['dates'][0], $_POST['dates'][1], ... [/code] Monkeymatt
-
It works for me: [code] mysql_connect(db_host, db_username, db_password); mysql_select_db(db_database); $result=mysql_query("OPTIMIZE TABLE `v2_settings`"); var_dump(mysql_fetch_assoc($result)); [/code] outputs: (I have xdebug enabled) [quote] array 'Table' => 'ekinboard.v2_settings' (length=21) 'Op' => 'optimize' (length=8) 'Msg_type' => 'status' (length=6) 'Msg_text' => 'OK' (length=2) [/quote] Monkeymatt
-
From http://php.net/date: [quote] I (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. [/quote] Monkeymatt
-
These lines: [code] $body2 = " Message from $_POST['fullname'] $_POST['message'] phone - $_POST['number']"; [/code] Should be changed to something more like this: [code]$body2 = " Message from ".$_POST['fullname']." ".$_POST['message']." phone - ".$_POST['number']; [/code] As you cannot have arrays where the key is a string used inside of a string or PHP complains. It would also help more if you could point out which line is line 32. Monkeymatt
-
Incrementing and decrementing URL variables
Monkeymatt replied to mjurmann's topic in PHP Coding Help
[code] $plusone=$row_Recordset1[id]+1; $minusone=$row_Recordset['id']-1; [/code] The way you are doing it changes the actual value of the variable after its value is assigned to the new variable. The better way to do it is the way I have. Monkeymatt -
when you mysql_fetch_assoc($result) of that query, you should get values that look similar to theirs - array keys are Table, Op, Msg_type, and Msg_text, and array values are the other values in the table. Monkeymatt
-
Does anyone know how to fix this problem? - Read Last Post
Monkeymatt replied to j3rmain3's topic in PHP Coding Help
You [b]can[/b] assign $variable4, $variable5, $variable5, etc inside a loop: [code] $num=5; // number of variable(num) to extract for ($i=1;$i<=$num;$i++) { $go="variable".$i; $$go=$_POST[$go]; } [/code] http://us2.php.net/manual/en/language.variables.variable.php Monkeymatt -
What existing class? There is no instance of the class until you create a variable and define it as of that class. There is only a definition of the class. Think of it this way: what we have before we defined a variable to be the class is like blueprints to a house - you know what it should look like and what it will do when it is made, but it is not made yet. After the variable is defined and set to be the class, it is like the house is built and is now there and you can now do things with it. Monkeymatt
-
Returning only a certian number of words from a row.
Monkeymatt replied to DBookatay's topic in PHP Coding Help
Here's an example for 50 words: [code] <?php $temp=explode(" ", stripslashes($row['cmnts']), 51); // 51 is 50 words +1 (extra words) array_pop($temp); // remove extra words from end $text=nl2br(implode(" ", $temp)."..."); // add spaces back in and add '...' ?> [/code] Monkeymatt -
[RESOLVED] How to skip first or last line when reading .txt file
Monkeymatt replied to Jfisher446's topic in PHP Coding Help
For the first line, you could set a variable such as this: [code] $first_line=true; // outside of loop // Inside of loop if (!$first_line) { // Do everything normally done inside of loop on every line } else { $first_line=false; // next time through will be second line } [/code] As to the last line, you could check if the line with spaces trimmed is empty: [code] // after you have $line set, and before you do anything else with the line $test=trim($line); if (!empty($test)) { // do normal stuff } else { // line is empty } [/code] Monkeymatt -
On page 2, instead of using $drname, use $_REQUEST['drname'], as $drname will only be set if register_globals is set to on, which it is not in your case due to your problem. Simply make page 2 be this: [code] setcookie("drname", $_REQUEST['drname']); [/code] Monkeymatt
-
You can actually call it like this: [code] $foo=new Foo(); $foo->Variable(); [/code] As to not using Foo::Variable(), then it does not have a $this var that is passed to the function, so it will yell at you for referencing $this because it is not defined. Foo::Variable() is for calling static functions that do not require an instance of the class, and cannot reference the current class using $this because there is not current class that it is under. Monkeymatt
-
Your quotes are wrong. This line: [code] echo '<option value="$player_id">$player</option>n'; [/code] needs to have double quotes or variables concatted for it to insert variable names and not what is literally there: [code] echo "<option value='$player_id'>$player</option>\n [/code] or [code] echo '<option value="'.$player_id.'">'.$player.'</option>\n'; [/code] Monkeymatt
-
Here is a function from a class I have that will return field names in an array. [code] function get_rows($table) { $result=mysql_query("DESCRIBE `".$table."`"); if (!$result) { echo mysql_errno().": ".mysql_error(); } $return=array(); while (($array=mysql_fetch_array($result)) !== false) { $return[]=$array['Field']; } return $return; } [/code] Monkeymatt
-
blear - He said "they don't create folders or anything themselves" This can be done with mod_rewrite to turn the url into variables for PHP - look at mod_rewrite, there's even a forum here to explore it. Monkeymatt
-
Are you attempting to put the link in the image tag by simply making a long string with all of the correct values that has the HTML and then dumping that string into somewhere? You need to do it by creating and inserting new elements using the javascript function and then add urls and such: [code] var img=document.createElement("img"); img.src=image_url; // then insertBefore or insertAfter into the main area [/code] Monkeymatt
-
Instead of calling set_size(), you need to call $this->set_size(). You need to let it know that you are calling the function from this case of the class. Also, how are you getting the filesize to $this->size, as set_size() simply calls filesize(), but does not put the value in the variable $size. I think you would need something more like this: [code] function set_size() { $this->size=filesize($this->file_name); } [/code] Monkeymatt
-
It appears that the directory walking is messing up - it should only be reading the files/directories that are not '.' or '..' (current or previous directory). This one is continously going to the same directory, most likely failing eventually because the path is too long. You need to add a check to only walk through the directory when the filename/directory name is not equal to '.' or '..' Monkeymatt
-
I have made a tutorial page with easy to remember urls, that are the categories it is under followed by the tutorial name -- see http://monkeymatt.fusionxhost.com/tutorials/ Here is the appliciable .htaccess code [code] RewriteRule ^tutorials/$ tutorials.php?cat_name=Main RewriteRule ^tutorials/((([^/]+)/)+)$ tutorials.php?cat_name=$1 RewriteRule ^tutorials/((([^/]+)/)+)([^/]+)/examples/([0-9]+)$ tutorials.php?cat_name=$1&tutorial_name=$4&example=$5 RewriteRule ^tutorials/((([^/]+)/)*)([^/]+)/([0-9]+)$ tutorials.php?cat_name=$1&tutorial_name=$4&page=$5 RewriteRule ^tutorials/((([^/]+)/)*)([^/]+)$ tutorials.php?cat_name=$1&tutorial_name=$4&page=1 [/code] The PHP code then takes the cat names, separates them, and finds the cat id (using all of the cat names allows for categories with same names, just not in the same category). Then it loads the necessary stuff using the names. Monkeymatt