-
Posts
2,965 -
Joined
-
Last visited
Everything posted by mikesta707
-
[SOLVED] LSB (PHP 5.3) problem with static value!
mikesta707 replied to keevitaja's topic in PHP Coding Help
Ahh missed the 5.3 part sorry. Here is the problem, you are using a parent method, and expecting it to use a static variable from a child class. This will not work simply because of scope. The parent has no access to the childs attributes, even its static ones. However, you may want to take this into consideration: As of PHP 5.3.0, it's possible to reference the class using a variable. The variable's value can not be a keyword (e.g. self, parent and static). I'm pretty sure you can't qualify the scope with the static key word. In fact, that doesn't even really make sense it all. by the way, when I change your code to A:: i get the following output first: first second: second, static text: here shoult be some static text: here shoult be some static text: here shoult be some static text: -
use url_encode on the variable
-
oh my bad. My brain exploded for a minute and I thought that was javascript for some reason... yeah ignore me
-
Haha, yeah the way that HTML arrays are formatted in the PHP Post array are kind of strange, so the first time I encountered this it took some getting used to.
-
um... this is the PHP forum
-
[SOLVED] LSB (PHP 5.3) problem with static value!
mikesta707 replied to keevitaja's topic in PHP Coding Help
when you use the scope resolution operator you have to use the class name of the scope you are resolving. so echo 'here shoult be some static text: ' . static::$text; should probably be echo 'here shoult be some static text: ' . A::$text; -
By the way, using mime-types is not the best way. Mime types can be easily spoofed, and some browsers don't even send them. Some even send different ones for specific types. I usually restrict file type like so $allowed = array("jpg", "jpeg", "gif");//make an array for allowed file types $ext = end(explode('.', $_FILES['minfile']['name']));//get the extension of the file //check it if (!in_array($ext, $allowed)){//its not an allowed file type echo "File type not accepted."; exit(); } //continue with upload
-
yeah, this very example is a reason why its bad to rely on scripts to have variables in certain scopes being in others. You have two options. One route would be do declare sql_inect_ext as global in the DivisionManagers function (which a lot of people would suggest you don't. Im not going to get into it, or voice my opinion one way or the other) function DivisionManagers($branchid, $directoryid) // FIRST LEVEL OF EMPLOYEES BASED ON BRANCH AND BOSS { global $sql_inject_ext; or you could simply pass $sql_inject_ext in. I personally reccomend this way function DivisionManagers($branchid, $directoryid, $sql_inject_ext) // FIRST LEVEL OF EMPLOYEES BASED ON BRANCH AND BOSS { DivisionManagers($bID[$key],$row['DIRECTORYID'], $sql_inject_ext); ?>
-
can I see more of your code. If sql_inject_ext is in a function, than it's scope will only be local to that function. In any case its always good to pass variables to functions that you may use in the function, instead of relying on global variables (which may collide with other variables down the line.)
-
you could just use a for loop. im assuming you want to do some image upload kind of thing for ($i = 0; $i < count($_POST['new_image']['name']); $i++){ //access each individual element like so $name = $_POST['new_image']['name'][$i]; $size = $_POST['new_image']['size'][$i]; //do rest of stuff }
-
foreach($array as $key => $value){ echo "The " . $value . " won the World Series " . ($key + 1) . "<br />"; } [/code] ?
-
You could use array sort to put them in alphabetical order. As for faster or not, either one would only be slightly faster than the other. Unless you are processing GIGANTIC arrays, then you won't really see a difference. You could time it though, if you are curious. just do both 100 times, like $time = time(); for($i = 0; $i < 100; $i++){ yourMethod(); } echo "Us: ". (time() - $time) ."<br />"; $time = time(); for($i = 0; $i < 100; $i++){ myMethod(); } echo "and Them: ". (time() - $time) ."<br />"; edit: if you are processing huge arrays, I would just use databases. it would definitely be faster
-
I would do it like so function combine($array1, $array2){//array1 has precedence $combined=array_merge($array2, $array1); //merge them all with array1 having precedence. //array merge will overwrite any default values, even if //the value is empty (ie "") //now go through, and replace any empty values with //their default values $keys = array_keys($array2); foreach($keys as $key){ if ($combined[$key] == "" || empty($combined[$key])){ //if we find a key in combined thats empty //replace it with default value $combined[$key] = $array2[$key]; }//end if }//end foreach }//end func
-
just display the $average variable
-
.. well thats because you copy pasted my code instead of applying it to your situation. take out the echo getGrade(75)."<br />"; echo getGrade(66)."<br />"; echo getGrade(82)."<br />"; echo getGrade(89.6)."<br />"; echo getGrade(99)."<br />"; echo getGrade(50)."<br />"; part, and add echo getGrades($average); at the bottom after you define average
-
[SOLVED] Can I please get help on my store finder? Two small issues.
mikesta707 replied to damion's topic in PHP Coding Help
<?php for($i=0;$i<count($resultArray);$i++){?> <div style="width:200px;float:left;margin-bottom:10px"> <span class="feedname"><? echo $resultArray[$i]['name']; ?></span><br /> <span class="small"><?php echo $resultArray[$i]['address']; ?></span><br /> <span class="small"><?php echo $resultArray[$i]['city']; ?>,<?php=$resultArray[$i]['state']; ?>,<?php=$resultArray[$i]['zip']; ?></span><br /> <span class="small" style="font-weight:bold"><?php echo $resultArray[$i]['phone']?></span><br /> </div> <?php }?> <br style="clear:both" /> </div> </div> </body> </html> you really should just do a find/replace all in your favorite text editor -
ooops simple syntax error function getGrade($grade){ if ($grade > 89.5){//is A return 'A'; }//fixed here. elseif(... etc)//etc
-
pageination not working right... coping images over 4 pages
mikesta707 replied to runnerjp's topic in PHP Coding Help
im thinking here //Now we can issue the database qery and process the result. $sql="SELECT * FROM `photos` WHERE `thumb_id` = '3'"; $res = mysql_query($sql) or die(mysql_error()); you want to add the limit clause, to the end of the query. $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; //Now we can issue the database qery and process the result. $sql="SELECT * FROM `photos` WHERE `thumb_id` = 3 " . $limit; $res = mysql_query($sql) or die(mysql_error()); -
i took the liberty of writing a median grade function because I'm bored at work. tested and test code output is below function getMedian($scores){ sort($scores, SORT_NUMERIC); print_r($scores);//you can comment this out $count = count($scores); if ($count % 2 != 0){ $key = ceil($count/2) - 1; return $scores[$key]; } else { $key1 = $count/2 - 1; $key2 = $key1 + 1; return (($scores[$key1] + $scores[$key2])/2); } } $scores = array(12, 43, 65, 23, 84); $scores2 = array(44, 55, 23, 67, 88, 90); echo getMedian($scores)."<br />"; echo getMedian($scores2)."<br />"; output Array ( [0] => 12 [1] => 23 [2] => 43 [3] => 65 [4] => 84 ) ans: 43 Array ( [0] => 23 [1] => 44 [2] => 55 [3] => 67 [4] => 88 [5] => 90 ) ans: 61
-
Then you aren't calculating the average. You are just calculating the total. you can calulate the average like so $total = 0; foreach($_POST['grades'] as $grade){ $total += $grade; } $average = $total/count($_POST['grades]);
-
if you want 10 grades in stead of two than just add 10 input text fields instead of two. just add 10 of these <input name="grades[]" type="text" /> as far as an letter grade, you could do function getGrade($grade){ if ($grade > 89.5){//is A return 'A'; { elseif ($grade < 89.5 && $grade > 79.5){ return 'B'; } elseif($grade < 79.5 && $grade > 69.5){ return 'C'; } elseif ($grade < 69.5 && $grade > 59.5){ return 'D'; } return 'F'; } test code echo getGrade(75)."<br />"; echo getGrade(66)."<br />"; echo getGrade(82)."<br />"; echo getGrade(89.6)."<br />"; echo getGrade(99)."<br />"; echo getGrade(50)."<br />"; output: C D B A A F I don't consider + or - grades tho (like A-, B+)
-
[SOLVED] PHP arrays into arrays need help
mikesta707 replied to ashton321's topic in PHP Coding Help
with an ltrim it won't take any zeros on the right of the string, so they would both work the same -
The problem is your else ifs. It will only do one of the three elseif statements (even thought they could all be true) you should change them to if's so that even if $htel isset, it will check all the others too. BTW when you assign a variable the value of another variable, you can just do $var1 = $var2; even if they are strongs. you definitely want to do this with numbers. btw instead of checking if something is a null or empty string like you do if ($string = "") just use empty if (empty($string1) || empty($string2)){
-
missing a closing parenthesis for ($i = 0; $i < count($_FILES['image']['name']); $i++){
-
oh sorry missed a semi colon function getScoreAndCity($string){ $tokens = explode(" ", $string); //$tokens is defined $name = array();//missed it here foreach($tokens as $token){ //$token is not here is where the error is if (is_numeric($token)){ $score = $token; } else { $name[] = $token; } } $name = implode(' ', $name); return array($name, $score); }