Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. you know, it's not really that great of a stretch of the imagination to apply the same concept to tables: [code] $i = 0; echo "<table><tr>"; while ($i < $num) {   $i++;   echo "<td>stuff</td>";   if ($i == 5) {       echo "</tr><tr>";   } } echo "</tr></table>"; [/code]
  2. remove the * from your query
  3. okay I thought I'd make a new post instead of editing the last one, since it's on a new page. Okay, It's all about.. Bride of Franky! <?php $relatives = array('mother', 'father', 'sister', 'brother','uncle', 'auntie'); $verbs = array('dislikes', 'sits on', 'licks', 'sucks', 'looks like', 'does', 'discusses the pros and cons of Web 2.0', 'loves', 'caresses', 'slides onto', 'hates', 'kisses', 'learns PHP with', 'has an AJAX interface with'); $animals = array('dogs', 'cats', 'horses', 'birds', 'giraffes', 'elephants', 'hippos', 'hamsters', 'gerbils', 'monkeys'); $adjectives = array('abhorrent','abject','abnormal','abrasive','absorbed','absurd', 'abusive','acrid','agonizing','ambiguous','ancient','apathetic', 'average','bad','barbarous','bawdy','belligerent','berserk', 'bizarre','black','boorish','brash','brawny','burly', 'callous','cold','colossal','combative','crabby','craven', 'crazy','creepy','crooked','cynical','demonic','deranged', 'devilish','direful','dirty','disagreeable','draconian','drunk', 'dysfunctional','erratic','evasive','evil','filthy','flippant', 'gaudy','giant','gigantic','greedy','grotesque','grouchy', 'gruesome','grumpy','guiltless','hellish','horrible','huge', 'hulking','icky','immense','irate','jaded','jittery', 'macho','maddening','malicious','mammoth','maniacal','massive', 'mighty','mindless','moaning','moldy','murky','mysterious', 'nasty','nauseating','noxious','oafish','obscene','psychotic', 'rabid','ruthless','sassy','scary','smelly','snobbish', 'snotty','spooky','threatening','tightfisted','tough','towering', 'trashy','ugly','unbecoming','unsightly','vagabond','vengeful', 'venomous','vulgar','wicked','wrathful','wretched'); function insult($secondary_person) { global $relatives; global $verbs; global $animals; $r_size = sizeof($relatives) - 1; $v_size = sizeof($verbs) - 1; $a_size = sizeof($animals) - 1; $r_rand = rand(0, $r_size); $v_rand1 = rand(0, $v_size); $v_rand2 = rand(0, $v_size); $a_rand = rand(0, $a_size); $insult = "Your {$relatives[$r_rand]} {$verbs[$v_rand1]} $secondary_person and {$verbs[$v_rand1]} {$animals[$a_rand]}"; return $insult; } class Greeting { function Greeting() { echo "Hello World!"; } } interface Singleton { public static function getInstance(); } interface Actor { public function speak(); public function meet($person); public function eat($animalArr); } abstract class Intestant_Abstract { abstract public function input($input); abstract public function output(); } class Stomach extends Intestant_Abstract implements Singleton { private static $instance; public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new self; } return self::$instance; } private function __construct(){ } public $kilosOfFood; public function input($input){ $this->kilosOfFood += strlen($input); echo 'Franky liky to eats '.$input.'..<br />'; if($this->kilosOfFood > (strlen(implode('',$GLOBALS['animals']))/1.5)){ $this->output(); } } public function output(){ echo '<br />Bhaarf..<br />'; } } class Guts implements ArrayAccess, Singleton { private static $instance; public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new self; } return self::$instance; } private function __construct(){ } private $intestants; public function add($name){ $this->intestants[$name] = call_user_func(array($name, 'getInstance')); } public function remove($key) { unset($this->intestants[$key]); } public function offsetExists($offset) { return isset($this->intestants[$offset]); } public function offsetGet($offset) { return $this->intestants[$offset]; } public function offsetSet($name, $value) { $this->add($name); } public function offsetUnset($offset) { unset($this->intestants[$offset]); } } class Franky implements Actor { private $person; public function meet($person){ $this->person = $person; } function eat($animals){ shuffle($animals); $guts = Guts::getInstance(); $guts->add('Stomach'); $guts['Stomach']->input(next($animals)); } public function speak($insult_them = false){ if($this->person == null){ $greet = new Greeting(); echo '<br />'; } else { echo 'Hello '.$this->person.'!<br />'; if ($insult_them) { echo insult($this->person) . '<br />'; } } } } if (isset($_POST['relativeName'])) { $relativeName = $_POST['relativeName']; $relativeType = $_POST['relativeType']; $h = new Franky; $h->speak(); $h->meet($relativeName); $h->speak(true); $h->eat($animals); $h->eat($animals); $h->eat($animals); $h->eat($animals); $h->eat($animals); $h->eat($animals); $h->eat($animals); $h->eat($animals); $monstername = $adjectives[array_rand($adjectives)]; echo "<br/>Franky wants to marry your $relativeType.<br/>"; echo "$relativeName will join the monster family and<br/>"; echo "$relativeName's monster name will be $relativeName the $monstername.<br/>"; } else { $person = $relatives[array_rand($relatives)]; echo <<<FORMINT What's your $person's name?<br/> <form action = '{$_SERVER['PHP_SELF']}' method = 'post'> <input type = 'text' name = 'relativeName' size = '10'> <input type = 'hidden' name = 'relativeType' value = '$person'> <input type = 'submit' value = 'submit'> </form> FORMINT; } ?>
  4. Yeah I meant no php5 on account of some people maybe people unable to test it if they don't have it installed, yes. But who cares. Cheating? Bah! I don't consider that cheating. In fact, I'm surprised the original "hello world" is still there. Why? Because I can put "Jesus" into the input field and it will in essence be do the same thing as before. p.s. - rewriting code to run more efficiently or "better" is okay too. I'm certainly not the most php saavy person here; for instance you guys' OOP skills are much better than mine. So if you feel like "Franky" is somehow being crippled because of his internals, rewriting/reorganizing is okay - to an extent. We don't want complete rewrites every single post, I guess. But, well..well for instance, exactly how redbull turned the simple "hello world" into a method inside a class. LoL, I ran the code and this is what I got:
  5. [code] <?php     if ( $img_dir = @opendir('../images/') ) {         while ( false !== ($img_file = readdir($img_dir)) ) {             // add checks for other image file types here, if you like if ( preg_match("/(\.jpg)$/", $img_file) ) {               echo "<img src = '$img_file'>";             }         }         closedir($img_dir);     } else {         echo "wrong path";     } ?> [/code]
  6. [code] $sql = "SELECT * FROM articles ORDER BY id DESC LIMIT $from, $max_results"; $getlist = mysql_query($sql, $db_handle) or die(mysql_error()); . . while($row = mysql_fetch_array($getlist)){ [/code]
  7. how did you connect to the database? my code assumes the following: $conn = mysql_connect('localhost','username','password') or die(mysql_error()); and then the $getlist query uses the optional 2nd argument to specify the connection.  Either change $conn to your connection var or if you did assign the connection to a var, simply remove the $conn argument from the mysql_query: $getlist = mysql_query($sql) or die(mysql_error()); edit: also, you need to re-look at my code.  I have the query seperated from the function call. The way you listed it, you have the query string combined with the function call, which returns and assigns the result source to $sql.  Then you turn around and try to use that result source in your $getlist query function call, instead of a query string.
  8. [code] $sql = "select * from table order by $sortby limit $from, $max_results"; $getlist = mysql_query($sql, $conn) or die(mysql_error()); $sql = "select count(*) as num from table"; $getcount = mysql_query($sql, $conn) or die(mysql_error()); $total_results = mysql_result($getcount, 0) or die(mysql_error()); $fr = $from + 1; $to = $from + mysql_num_rows($getlist); echo "showing $fr - $to of $total_results results"; [/code]
  9. you mean the "Showing 1 - 12 of 11784 Results" part?
  10. someone or other posted this link a while back, and I loved it so much I bookmarked it. It's great for helping you come up with a color scheme: http://www.behr.com/behrx/workbook/index.jsp
  11. No offense meant (by me), no offense taken (from you).  Perhaps if you could provide a link to your work-in-progress then people might offer some opinions/critique the situation.  If you provide a link then I will move this to the website critiques forum.
  12. <mr. burns>   :: drums fingers :: [i]excellent...[/i] </mr. burns>
  13. We can't tell you what "looks best." That's up to you.  Everybody has their own personal tastes.  I'm not trying to be difficult; we're just not mind readers, nor do we have the same tastes.  Just sit down and consider what you "need" your script to do, and get that done, and then build to make it do what you "want" it to do.
  14. I try to start at "appearance," assuming you mean layout and what you are wanting the site to be able to "do."
  15. I think I'm one of the only people on the planet that doesn't go to wikipedia. 
  16. crap. i meant to say no php5 as well. oh well. i can do that. i guess if someone can't do php5 then tough titties. okay do you guys' posts ^ mean to serve as placeholders or what? nevermind, i will decide for you. unless your thread specificially states "placeholder/whatever" then it doesn't count as a placeholder. okay i just added something quick cuz i have to go soon: <?php $relatives = array('mother', 'father', 'sister', 'brother','uncle', 'auntie'); $verbs = array('dislikes', 'sits on', 'licks', 'sucks', 'looks like', 'does', 'discusses the pros and cons of Web 2.0', 'loves', 'caresses', 'slides onto', 'hates', 'kisses', 'learns PHP with', 'has an AJAX interface with'); $animals = array('dogs', 'cats', 'horses', 'birds', 'giraffes', 'elephants', 'hippos', 'hamsters', 'gerbils', 'monkeys'); function insult($secondary_person) { global $relatives; global $verbs; global $animals; $r_size = sizeof($relatives) - 1; $v_size = sizeof($verbs) - 1; $a_size = sizeof($animals) - 1; $r_rand = rand(0, $r_size); $v_rand1 = rand(0, $v_size); $v_rand2 = rand(0, $v_size); $a_rand = rand(0, $a_size); $insult = "Your {$relatives[$r_rand]} {$verbs[$v_rand1]} $secondary_person and {$verbs[$v_rand1]} {$animals[$a_rand]}"; return $insult; } class Greeting { function Greeting() { echo "Hello World!"; } } interface Actor { public function speak(); public function meet($person); } class Franky implements Actor { private $person; public function meet($person){ $this->person = $person; } public function speak($insult_them = false){ if($this->person == null){ $greet = new Greeting(); echo '<br />'; } else { echo 'Hello '.$this->person.'!<br />'; if ($insult_them) { echo insult($this->person) . '<br />'; } } } } if ($_POST['name']) { $h = new Franky; $h->speak(); $h->meet($_POST['name']); $h->speak(true); } else { echo <<<FORMINT What's your best friend's name?<br/> <form action = '{$_SERVER['PHP_SELF']}' method = 'post'> <input type = 'text' name = 'name' size = '10'> <input type = 'submit' value = 'submit'> </form> FORMINT; } ?>
  17. lol. unfortunately i think it's kinda catchy. i'm at 19 minutes 30 seconds right now...
  18. http://www.leekspin.com/
  19. Okay I have been inspired by one of steelman's (though it pains me to admit it ) posts to make a game. P.s. - Don't be jealous of the awesomeness of my game name! Okay here's how it works: It's just like those threads on other message boards where everybody contributes to making a story by posting the next sentence/few sentences/paragraph or whatever, except for we are gonna take the script and the next poster adds his/her little piece to it. The code you add doesn't have to really 'conform' to any particular theme or situation or goal or whatever, but it does have to be somehow useable or relavent to the script as a whole. In other words, if you wish to create a new arm for Frankenstein-Code, that's fine and dandy, but it has to be attached to his body, not just some random arm laying there. Also, the script has to be "self-contained." No database stuff. No flatfile stuff. I don't want people to have to go setting up and altering databases all the time, or having to mess with dir structures/permissions/whatever. Also no cookies. And keep it strictly PHP, as in, no adding in javascript or some other such thing. These rules may or may not be relaxed, depending on how this game progresses and what comes of it. Also, it should go without saying, but I'm gonna say it anyways, so that one cannot argue they "didn't know" : No malicious code, no vulgar or pornographic content, etc.. Now, in order to keep the code consistent and not have like 3 different people posting 'at the same time' or something, here's what we're gonna do: If you wanna be the next person to add to the script, make a 'placeholder' post, saying "placeholder" or "I'm next" or "get off my koolaid yo" or something. Then copy the code from the previous post, add your piece to it, and then edit your placeholder post. p.s. - Please use code tags when posting. Also, even though coding styles differ, things like indenting in some way are standard, so do it. Okay so I guess I'll start with the cheezy but fitting: <?php echo "Hello World!"; ?>
  20. yes you can do that with php. it's a content management system (cms).  Have fun googling.
  21. so tell them to start paying your time or stop wasting it.  you don't work for free. if they can't grasp that, then walk away.
  22. well..here is another way of alternating row colors, non-dependant of your sql rows.. [code] <?php   // pretend this array is your results array from a query   $blah = array('a','b','c','d','e','f','g','h','i','j');   // example colors   $color1 = '#777777';   $color2 = '#FFFFFF';   // example loop. would normally use a while with fetch_array or whatever   echo "<table border='1'>";   for($x = 0; $x<10; $x++) {       // is color == to color1? set to color2. otherwise, set to color1       $color = ($color == $color1) ? $color2 : $color1;       echo "<tr><td bgcolor = '$color'>{$blah[$x]}</td></tr>";   }   echo "</table>"; ?> [/code]
  23. yeah i can kinda sorta see how that would be useful..if you were working with a database and under certain circumstances..anyways, I wasn't saying you stole it. I was saying it looked like a piece of code that was part of a larger piece of code, doing something specific, as opposed to being a general purpose piece of code that could be used, well, generically. also, am i mistaken, or it vaguely seems like your using your code to do something like alternate row colors or something?
  24. That piece of code looks like it's specifically designed for whatever larger script its from. I fail to see how it works as a generic 'odd or even' checker. Can you please explain your code in more detail, ignace?
×
×
  • 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.