laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
by any chance are ya encasing the 1 or 0 in quotes, like a literal string? if so that wud be a problem
-
LOL okay yer right, i think it's the leap years. anyone want to use julian calander functions instead?
-
how about echo intval(time()-strtotime("1968-12-31"))/(60*60*24*7*52)); the formula time returns amt of seconds thus (secs per min* mins per hr * hrs per day * days per week * weeks per year);
-
U are safe, the time function isn't reliant on the users timezone. but how the server was setup. usually the servers timezone so no matter who uses it, they will see the servers time
-
cudn have said it any better... BTW nice tiara
-
U tell it how to get the data, but you never tell it when to get the data. u have to use one of the several functions mysql_result mysql_fetch_array mysql_fetch_row mysql_fetch_assoc to retrieve rows after a mysql_query.
-
WHERE task_id IN (x,y,z) u put use the IN function which works like an OR operator UPDATE tasks SET status=1 WHERE task_id=x OR task_id=y OR task_id=z
-
not working? <?php if($_SERVER['REQUEST_METHOD']=='POST') echo "<PRE>". print_r($_POST,true) ."</PRE>"; ?> <html> <body> <form method="POST"> <INPUT TYPE='checkbox' name='cb[]' value='0'> <INPUT TYPE='checkbox' name='cb[]' value='1'> <INPUT TYPE='checkbox' name='cb[]' value='2'> <INPUT TYPE='checkbox' name='cb[]' value='3'> <INPUT TYPE='checkbox' name='cb[]' value='4'> <INPUT type="submit"> </FORM> </body> </html> as i said, unchecked checkboxed return nothing, while checked boxes return the value.
-
yep, as thorpe suggests mkdir returns true or false. depending if it succeeded or not. so there is no need to use other functions (is_dir) to check if it succeeeded. since it returns a numeric, ya can use it as an expression (if,while,switch). you will find a lot of functions that return simple information like this, so is of great use.
-
keep the [] in the form makes it easier to process [] will return an array, and the function u posted will handle numerics or strings so build a function function createhidden($post,$inp='') { foreach($post as $key => $val) { if(is_array($val)) createhidden($val,$key); else { $val=htmlentities(stripslashes(strip_tags($val))); echo '<INPUT TYPE=HIDDEN name="' . (!empty($inp)?"$inp\[\]":$key) . "\" VALUE=\"$val\">\n"; } } notice it calls itself on arrays so ya can call it up as createhidden($_POST);
-
nope. checkboxes return nothing, if unchecked or something if checked (as a value can be attached to the tag) so $mycheckbox=isset($_POST['mycheckbox'])?1:0;
-
echo "<PRE>" . htmlspecialchars($row) . "</PRE>";
-
Generating Links with PHP based on Specific Words
laffin replied to NeoMarine's topic in PHP Coding Help
<?php $mywordlinks = array( 'adam' => 'http://www.adam.com', 'eve' => 'http://www.eve.com', 'apples' => 'http://www.apple.com' ); function ismyword($matches) { global $mywordlinks; $word=$matches[1]; if(isset($mywordlinks[$key=strtolower($word)])) { $word="<A HREF='$mywordlinks[$key]'>$word</A>"; } return $word; } $string="Adam went to the supermarket to find apples, but there was only bananas! I feel sorry for Adam, don't you?"; $newstring=preg_replace_callback("@(?=[ ]?)([a-z\']{3,})(?=[\s\.,?!])@im",'ismyword',$string); echo "<PRE>$string\n$newstring</PRE>"; ?> -
[SOLVED] how can i count the number of rows in a DB and echo the amount?
laffin replied to frijole's topic in PHP Coding Help
one of 2 ways // U can do this $res=mysql_query('SELECT COUNT(*) FROM users'); echo mysql_result($res,0,0); echo '<BR>'; // or U can do this $$res=mysql_query('SELECT * FROM users'); echo mysql_num_rows($res); -
u can always set a cookie with the page user is on like a tracking cookie. now at beginning of some scripts, that shudn be refreshed check the cookie against the script name, if they are the same, most likely a refresh. redirect user to other page just a thought
-
until it's outputted? why cant u insert the routine before/during the output? if that can't be done, consider using ob_start/ob_get_contents/ob_clean functions. which will capture the output into a string, than ya can process and echo it out.
-
maybe sumfin like $pat='~Del Date/Time:.*<b>(\d{2}/\d{2}\d{2}~ims'
-
[SOLVED] Check to see if a date is in the future.
laffin replied to tet3828's topic in PHP Coding Help
// establish entered date variables $eYear = $_POST['eYear']; $eDay = $_POST['eDay']; $eMonth = $_POST['eMonth']; $eDate=strtotime("$eYear-$eDay-$eMonth"); // get current date turn it into variables $curDate = time(); // combine dates into a long string if ($curDate < $eDate) { // show error } converting to a numeric format simplifies the check. thus reason for using time() -
as he said, javascrpt can be bypassed. reason it shud not be relied on for validation. look at the popular firefox extension, Greasemonkey, which can remove / replace javascript from web pages. and still report that javascript is enabled. Javascript can be used to make it easier for the end user, those that behave. for the rest dun forget php validation. as to the post by haku, yep, but ya dun wanna use $_POST in yer html form either, another infraction of possible exploiting the code. use the local variables. if u have validated / santized them. if(isset($_POST['username'] && preg_match("@^\w+$@i",$username,$matches) && strlen($_POST['username']) < 30) $username=$_POST['username']; than in yer html <input type="text" name="somename" value="<?php echo $username;>"; ?>" />
-
does yer script force u to use 2 arrays for available and unavailable. seems like a waste if it does, when u can have the dates, with flags. A multi-dimensional array. which wud cut down on the code, u may also want to keep things in time() format as that makes comparisons much simpler. $today=strtotime("Y-m-D"); for($i=0;$i<5;$i++) $fdays[strtotime("+$i days",$today)]=true; than get yer unavailable days, in the array. then mark the days which are unavailble for($udays as $day) { $dt = strtotime($day); if(isset($fdays[$dt])) $fdays[$dt]=false; } now the array $fdays, have a value of true or false true = available false = unavaliabe foreach($fdays as $key => $value) { echo date("Y-m-d,$key) . " is " . ($value ? "":"un") . "available"; }
-
<?php function array_datetotoday($startdate) { $ldate=strtotime($startdate); $edate=strtotime(date("Y-m")); do { $dates[]=date("Y-m",$ldate); $ldate=strtotime("+1 Month",$ldate); }while($ldate <= $edate); return $dates; } $date_array = array_datetotoday(date("Y-m",strtotime("-1 Year"))); foreach($date_array as $dt) echo "$dt<br>"; ?>
-
[SOLVED] need help piecing this script together
laffin replied to 2DaysAway's topic in PHP Coding Help
$hk shud be $get. the query itself could be written as $query = "SELECT pimp,hoeskilled FROM `{$tab[pimp]}` WHERE `rid`=$rid ORDER BY hoeskilled DESC"; since now ya got # of hoes killed in a descending order, all u need is the first row. you can add images to the html like $tcount=1; while ($row = mysql_fetch_assoc($get)){ $image=(($tcount<=10) ? $tcount:"default") . ".png"; echo "<a href=\"\"onMouseover=\"popup('<span class=styleGreen>Hoe Killer</span><br/>')\"; onMouseout=\"\kill()\"><img src='images/$image' width='16' height='16' alt='killer award' border='0'></a>"; } now all u need are the top10 png images, and a default images. top1.gif - top10.gif -
the code wont work as well cuz the 2nd if statement, invalidated the POST fields, when $query is set, it will be set with blank values if(isset($_POST['timeout']) && (time() > $_POST['timeout'])) { will fix that extra paren issue