Jump to content

laffin

Members
  • Posts

    1,200
  • Joined

  • Last visited

Everything posted by laffin

  1. I think what u mean to do is pass a variable by reference, instead of it's value. so that the function can alter the variable function add(&$x,$y) { $x+=y; } $x=0; add($x,15); add($x,5); echo $x;
  2. Reason to use a cache system. depending on the information, cache updates is the question.
  3. I prefer building my own. I read a good article on building yer own Here Which is very basic, and since you can continue to build upon it, ya will get a better understanding of the engine itself
  4. u wud prolly want to use ob_start ob_get_contents and ob_end_clean than use either strpos or preg_mach to find the matching strings
  5. ya forgot an exit after header, otherwise code will continue to run
  6. Went a little further to generate a random base color, and it works most of the time, some colors just blend into each other too well. <?php function NegateColor($color) { return substr('000000'.dechex(~hexdec($color)),-6); } echo "<TABLE>\n"; for($i=0;$i<10;$i++) { $color=dechex(mt_rand(0,hexdec('FFFFFF'))); $bgc = NegateColor($color); echo "<TR><TD BGCOLOR=\"#$bgc\"><FONT color=\"#$color\">$color on $bgc</FONT></TD></TR>\n"; } echo "</TABLE>"; ?>
  7. Actually i did a test, and it did pretty well <?php function NegateColor($color) { return substr('000000'.dechex(~hexdec($color)),-6); } $colors=array('FFFFFF','000000','3300FF','660033','444444','336633'); echo "<TABLE>\n"; foreach($colors as $color) { $bgc = NegateColor($color); echo "<TR><TD BGCOLOR=\"#$bgc\"><FONT color=\"#$color\">$color on $bgc</FONT></TD></TR>\n"; } echo "</TABLE>"; ?>
  8. Yes, it will invert the numbers. function negativeColor($color) { //get red, green and blue $r = substr($color, 0, 2); $g = substr($color, 2, 2); $b = substr($color, 4, 2); //revert them, they are decimal now $r = 0xff-hexdec($r); $g = 0xff-hexdec($g); $b = 0xff-hexdec($b); //now convert them to hex and return. return dechex($r).dechex($g).dechex($b); }
  9. No, if u have teamid in user table than user can be assigned to 1 team only, unless u add more fields for more teams Let me do this in SQL syntax instead CREATE TABLE users { id integer NOT NULL AUTOINCREMENT PRIMARY KEY default '0' , username varchar(32) NOT NULL default '' } okay now for the Teams CREATE TABLE Teams { id integer NOT NULL AUTOINCREMENT PRIMARY KEY default '0' , name varchar(32) NOT NULL default '' } with a third table for the team members and which team they belong to CREATE TABLE TeamMembers { userid integer NOT NULL default '0', teamid integer NOT NULL default '0', PRIMARY KEY ('userid','teamid') } with both being a key, keeps the db from creating duplicate user/team entries
  10. They say when it comes to colors, colors on the oppsite side of the color wheel will compliment the primary color chosen. what better way than negate the color code? bgcolor= <user input> fgcolor = !<user input>
  11. Well assignment said be resourceful and if ya dunno the language, creating one on yer own is bout the last thing ya wanna do. Next step, look for a generation script (a script that generates the code for a form for u) Contact form Generator u can prolly find other automated generators
  12. this is easily avoided, by having a db entry of lastrun time, a simple check if it's been over 24 hrs (or if the date is different) than it's time to run again.
  13. dun keep the team id in the user profile. keep the team info in a seperate id. it's called a many to 1 relationship. keep the userid in the team table instead. [pre] TeamTable UserTable id +-- id userid ---+ username name [/pre]
  14. use datetime/timestamp structures in yer MySQL it's far more easiear to deal with in php CREATE TABLE `reservations` ( `startt` TIMESTAMP default NULL, `endt` TIMESTAMP default NULL, `id` int(10) NOT NULL auto_increment, `track_id` int(10) default NULL, `client_id` int(10) default NULL, PRIMARY KEY (`id`) ) to use the timestamp in php, use date to format as needed. conversion of user input into a timestamp use strtotime than testing it against a prior time is a matter of checking the result against time
  15. think outside the box Create an array of vars which are all the inputs $allfields=array('name','pass','email','vpass','first_name','last_name','title'); [code] create another array for required fields [code] $reqfields=array('name','pass','email','first_name','last_name'); [code] Note, that vpass is not added as required since a matching check is gonna be used anyhow process all fields [code] foreach($allfields as $field) $inputs[$field]=mysql_real_escape_string($_POST[$field]); than check required fieldsa are filled throw them into an error array, true false will work foreach($reqfields as $field) $reqerrors[$field]=!empty($inputs[$field]); now on yer form, ya can display errors on the field if(isset($reqfield['name']) && $reqerrors['name']) $color='BGCOLOR="RED"'; // Missing required field color else $color=''; // use default color print("<td class=\"login_border\" $color align=\"right\">Select a username:</td><td class=\"login_border\" align=\"left\"><input type=\"text\" size=\"40\" name=\"username\" /></td>"); note: color is inserted within the TD tag, u can also display an error as well [/code][/code][/code][/code]
  16. Thanks chris, Yep that's correct
  17. <?php $res=mysql_query("SELECT * FROM users where username='$user' AND pass='$pass'"); if($row = mysql_fetch_array($user_id)) if(in_array(19, $row)){ echo "ADMIN<br>"; } else { echo "NOT<br>"; } } else { echo "You have entered an invalid username/password combination"; } ?>
  18. Oh, u shud santize the string values, as mysql may choke on those as well. mysql_real_escape on these fields, $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $payer_email = $_POST['payer_email'];
  19. Actually it looks good item_number = $_POST['item_number' . $x .'']; $quantity = $_POST['quantity' . $x . '']; I wudda opted for item_number = $_POST["item_number$x"]; $quantity = $_POST["quantity$x"]; same result to save some queries, ya can move the mysql_query outside the loop, and append the query string in the loop $query .= "INSERT INTO inventory (txn_id, item_number, quantity, first_name, last_name, payer_email, order_date) VALUES ('$txn_id', '$item_number', '$quantity', '$first_name', '$last_name', '$payer_email', NOW());\n"; Nice job nonetheless
  20. Agreed Ajax is great for these type of situations. No redirction to another script, and can get results.
  21. look at this line mysql_fetch_array($user_id) mysql_fetch_array requires a mysql resource, not a string/value u obtain a mysql resource with mysql_query
  22. move mysql_query outside of the while conditional. u are getting the same row (row 1) because the query is being constantly run everytime the loop cycles.
  23. <php $id=isset($_GET['id'])?intval($_GET['pollid']):0; $vote=isset($_GET['vote'])?intval($_GET['vote']):0; $returnto=isset($_GET['returnto'])?$_GET['returnto']):'/'; @mysql_query("UPDATE polls SET hits=hits+1 WHERE pollid=$id AND vote=$vote"); $returnto=url_parse($returnto,PHP_URL_PATH); $returnto=(file_exists($returnto)?$returnto:'/'); header("Location: $returnto"); ?> very simple script, the question is how yer polls section is setup, so mysql_query shud be altered for this. so can be called from any page with votefor.php?id=xxx&vote=yyy&returnto=zzz where xxx = Poll ID yyy = Vote zzz = current page/script to return to after updating the polls
  24. than ya wudn need a form at all, just a link. with pollid and poll voted for question is, how do you plan on keeping ppl from voting more than once?
  25. Either multiple forms, or by using radio boxes / checkboxes
×
×
  • 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.