Jump to content

deadimp

Members
  • Posts

    185
  • Joined

  • Last visited

    Never

Everything posted by deadimp

  1. Just a quick thing. On this line: $totSpent = totSpent + $row[4]; It's valid (except for the missing sigil $), but you can just use the += operator to make thing simpler: $totSpent+=$row[4]; And of course, you have other operators like this: -= *= /= .= %= &= |= ^=
  2. That whole thing I said about the example... Scratch that. Ends up, I can just make the fields entirely separate, so I did. To show you why I find this odd, I changed the code to how it originally was, how I felt it should've worked (those two lines): //FieldDate::submit() $out+=$cur; // * //FieldTime::submit() $out=strtotime($in)%DAY_LEN; // * Clip to time of day Here's the link: Example Just click on the submit button a few times, and notice how the time changes.
  3. It's not so much the date format that's the problem, but the date timestamp. These are the two lines of interest, the quick fixes: //FieldDate::submit() $out+=($cur+16*60*60)%DAY_LEN; // * Another cheap fix - I'm not sure how I can simplify this //FieldTime::submit() $out=strtotime($in)%DAY_LEN+60*60; // * Clip to time of day - Adding the extra hour is a cheap fix.... Before I added the random fixes to it, the times would change by increments / decrements every submission, thus why I added the extra one / 16 hours. I'd upload an example, but it's on a newer version of the CMS, and I'm not sure about the compatability.
  4. If you're looking to check for a valid POST submission (meaning the actually submitted data) then use key_exists() (it's actually array_key_exists(), but I like the shorthand). That way, it can tell the difference between no submission and a submission with a blank username. Also, you're first checking if some random user has that name, and then if some other user, maybe the same one, has that password, then you're checking if some random user has both the name and the password. Do you see a bit of redundancy here? You can water that down to just one query to check for a valid login. I would also suggest that you compare username / password using binary (ie. "where binary `name`='...' and binary `pass`='...'") so that it's case sensitive (though I doubt the password hashes could collide due to caseless matching). Another thing I realized as I was typing this, you're checking to see if there is only one result for those two queries, and then you use that to see if you should go on. That's bad if two or more users have the same password, because then the rows returned by the password-only match (that shouldn't be there) would be greater than one. Just use the simple statement, "if (mysql_num_rows($result))", where it means that there is a non-zero (meaning it could be negative, but not a possible return) amount of rows.
  5. How are you adding your data to the variable? Are you using output buffer control? Or are you literally concatentating it to a variable? If the latter, I would highly suggest looking into output buffers. Plus, you can also handle escaping to HTML like this: <?php echo "Stuff "; ?> and even <?php echo "more stuff. "; $var="a little more"; ?> That, and maybe <?=$var?>.
  6. Look into the PHP documentation, see if you can't find an XML parser. Just looking at the function reference, I saw SimpleXML. You can get the file using an appropriate function that can download external files.
  7. A few tips on your naming conventions: choose one (cameCase, posix_style, etc) and stick with it. You occasionally flip-flop between some of those. The "tb" prefix on your table names isn't really needed, unless your fields and table names might collide, which isn't a good design scheme in the first place. And if you're beginning on website development and all that, storing your pictures in your database might not be the easiest idea. Instead, just link to it by filename. Other than that, it seems like you have the basics of the structure nailed down.
  8. I'm working on my CMS, Thacmus, and I've run into one helluva snag (well, nothing big). I'm working on adding the time of day to my date field, since I've procrastinated on that, but I'm having trouble trying to get the time of day from the timestamp without it interfering with the day. I've managed to supress this with the two asterik'd Here's the code for the two fields, date, and time: //Date selector class FieldDate extends Field { var $fmt, //Format for column display $time; //Add time field - If it's an object, it'll add that in (but it'll overwrite the name) function FieldDate($name,$label="",$fmt="",$time=true) { $this->Field($name,$label); if (!is_object($time)) $time=new FieldTime(""); if (!$fmt) { $fmt="m/d/y"; if ($time) $fmt.=" ".$time->fmt; } $this->time=$time; $this->time->name=$this->name."[time]"; $this->fmt=$fmt; } //Add option (checkbox) for a null date? function render($value) { $date=getdate(time()); //Get current date static $info=array( "mon" => array(1 => "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"), "mday" => array(), "year" => array() ); //Init if (!count($info["mday"])) { for ($i=-2;$i<=2;$i++) $info["year"][]=$date["year"]+$i; //2 above, 2 below for ($i=1;$i<=31;$i++) $info["mday"][]=$i; } if (!$value) $value=time(); $date=getdate($value); $name=$this->name; $out=""; foreach ($info as $key => $i) { $c=new FieldCombo($name."[$key]",$i,$key=="mon"); //Only month is by key $out.=$c->render($date[$key]); } if ($this->time) $out.=' '.$this->time->render($value); return $out; } function submit($in,&$out) { $out=mktime(0,0,0,$in["mon"],$in["mday"],$in["year"]); if ($this->time) { $cur=0; $this->time->submit($in["time"],$cur); $out+=($cur+16*60*60)%DAY_LEN; // * Another cheap fix - I'm not sure how I can simplify this } } function disp($value) { return date($this->fmt,$value); } function colWidth() { return 80+($this->time ? 80 : 0); } } //Time input class FieldTime extends FieldText { var $fmt; function FieldTime($name,$label="",$fmt="h:i a") { $this->FieldText($name,$label,15); $this->fmt=$fmt; } function render($value) { $value=date($this->fmt,$value); return FieldText::render($value); } function submit($in,&$out) { $out=strtotime($in)%DAY_LEN+60*60; // * Clip to time of day - Adding the extra hour is a cheap fix.... } function disp($value) { return date($this->fmt,$value); } }
×
×
  • 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.