Jump to content

premiso

Members
  • Posts

    6,951
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by premiso

  1. A great place to learn/test regex using preg functions can be found below. http://www.perlfect.com/articles/regextutor.shtml It may help you out when trying to create a regex for something.
  2. I store my timestamps as int(11) but some people do not like to do that. So first modify your tables column to be int(11) (or timestamp whichever). Then when you insert a time into the db, you insert the actual time stamp. $sql = "INSERT into tbl_name (`timest`) VALUES ('" . time() . "')"; That will insert it as a timestamp.
  3. No, there is no API for google groups. http://www.google.com/search?hl=en&q=google+groups+api&btnG=Google+Search A few different topics on the idea. As for deleteing/managing. I am not sure. I bet you would need curl to maintain the session and the admin account login info etc. I would suggest looking up information on cURL and use that.
  4. Basically it would require changing the table type to INT or datetime and using time to update the database. If you want it stored in the DB as MM/DD/YYYY, which I do not know why you would, you would probably need a varchar of 10, but note that does limit your options, where as the timestamp can be pulled out and manipulated using the date function to show seconds, the month, the year, all of the above or some. I would highly suggest changing that table deal. But yea, my 2 cents on that part. To store it as MM/DD/YYYY simply put the timestamp into date like so: $dateFormat = date("m/d/Y"); $sql = "UPDATE tblname SET colDate = '" . $dateFormat . "' WHERE bob=1"; Should format the time correctly. I am not sure how to do it in mysql, so if that is your goal I would suggest reading up more on MySQL and Dates. As for the rude comment back to gevans, I would agree with him, reading is your #1 key to finding a solution. He was basically suggesting different ways to manipulate dates in MySQL. I would suggest reading through that page as it will help you out in the long run.
  5. I think he means, if their last name is in the DB, they get to register for free for that event and not have to pay....but I could be wrong.
  6. Most likely it realizes you are hotlinking to that image and the does not allow hotlinking.
  7. To save you the hassel of trying to use php for this, you want to use Javascript. I would suggest looking there. Since PHP is a server-side script it cannot be changed after it has been processed, that is where the javascript comes into play.
  8. Yep, except if you have $this->error setup, I would just use that and skip passing the parameter.
  9. Yea, like I said it was more of psuedo code (layout/design) instead of a working example. At least you now have the idea to go off of. I know where the blanks are coming form anyhow =) <?php // takes in multi dimm array function combineArrays($arrays) { $newarray = array(); $cnt = count($arrays); for ($i=0; $i < $cnt; $i++) { $array = $arrays[$i]; foreach ($arrays as $nextArray) { $compared = compareArray($array, $nextArray); if (is_array($compared)) $newarray[] = $compared; } unset($arrays[$i]); // unset cause we know this one does not compare; } return $newarray; } That should narrow your results =)
  10. imo, I have a function in the class called error(). When this is called it sends an email with the error information to me, if that is setup and then redirects the user to the page (session helps me keep track of pages the user was at), so nothing is returned. If I am doing it in development, I simply print the error to the screen, then die the script. Cause if you get that error chances are the rest of the script is prone to errors etc due to that one single error, so why run it if you know the next errors to post cede it are potentially false errors? At least that is my philosphy. Anytime I am using classes and I get an error, I always send it to the error function and depending what it is kill the script or do something else. Th email sent ensures that you know there is a problem, where it is and allows you to fix it without the user every seeing stuff they should not see in a production environment.
  11. Using your FTP client, it should tell you who the owner is.
  12. Why not store it as a timestamp, then when it comes out of the db, use date and format it how you want to?
  13. As a side note, you can use <div>'s and set the style.display to none and have a link "show part 2" when clicked on it hides part one and shows part 2. Which is better, I dunno. Just figured I would throw that option out there.
  14. Not exactly clear on the question, but this might help you get rolling. Also note that this gets insanely long depending on how many arrays you have. <?php // takes in multi dimm array function combineArrays($arrays) { $newarray = array(); $cnt = count($arrays); for ($i=0; $i < $cnt; $i++) { $array = $arrays[$i]; foreach ($arrays as $nextArray) { $newarray[] = compareArray($array, $nextArray); } unset($arrays[$i]); // unset cause we know this one does not compare; } return $newarray; } function compareArray($array1, $array2) { if ($array1['sessionid'] == $array2['session_id'] && $array1['type'] == $array2['type']) { $array1['ftp_url2'] = $array2['ftp_url']; // etc return $array1; } return false; // not compatible } ?> That code could easily be fine tuned but my mind is not into now, hopefully that gets you going on what you need. The ultimate result is a returned array of the combined values...I think.
  15. Why not just look up the functions it uses via php.net and see which is compatible with php 4 and or 5 and the proper usage for each? mysql_fetch_object You either need to create a class, and put the results in the class or I would suggest just using mysql_fetch_assoc instead. $detectedlang = mysql_fetch_assoc($result); $detectedlang = $detectedlang['name'];
  16. I use my DB class to handle the errors. In production I check mysql_error after every query, if there is an error I send an email to myself with the error and where it occured etc. Then display a nice page to the user "We are sorry an error was encountered, the admin has been notified." If I am developing, I have it simply print the error to the page public function query($sql) { if ($sql) { $resource = mysql_query($sql); if (mysql_error()) { return $this->error(); }else { return $resource; } }else { $this->error = mysql_error(); return FALSE; } } Sorry bout the formating, copying from the [ php ] tags tends to do that. A side note I was taught when I first started programming, handle the errors where they are thrown. So instead of handling them somewhere else in the code, handle them at the source and save yourself alot of extra coding.
  17. It helps giving us the error message, but thankfully your code has soo many errors it was not hard: case 'Caipirinha': // Should be Colon ( not semi-colon ( $recipe = '1 lime juice<br /> 3 sugar<br /> 2 Cachaca'; // need a semi-colon here. Rinse and repeat for each case you have.
  18. Are you sure you are passing in a get variable? $myid = isset($_GET['myid'])?$_GET['myid']:0; // if $_GET is not present assign the value default of 0 $xmlFileData = file_get_contents("xml/myxml.xml"); $xmlData = new SimpleXMLElement($xmlFileData); $xmlName = $xmlData->color[$myid]->name; Just an fyi, it is possible to access elements of the array using an array identifier, so the previous should work as long as "myid" was set using the get such as: http://www.mysite.com/xml.php?myid=1 Chances are the above will not work if you have not been calling the page like that.
  19. Heres an idea. Create a new table "entries" that has a userid column and an entry column. Instead of adding to that row, just create a new row each time. Then this way you can pull out each entry for that user and display it how you want without using delimeters. This will not take up any more room, but may be slower in that every 4 minutes that is alot of rows. What is being entered every 4 minutes? and why every 4 minutes? As stated above if you want to do it your orginal way a delemiter is the way to go, just choose something that wont be part of the entry text, like |. Then append it to the end of the string. The real question I have is why add something every 4 minutes. Just think about it, there are 1,440 minutes in a day which means 360 updates per day adding 32 characters or more. So 32 * 360 is 11,520 characters a day with an average word being 5 characters, that is 2,000 words (try writing a 2,000 word essay, it is quite a bit). Times that by a week. Thats around 16,000 words in a week. That is just for one user. The DB is going to grow insanely fast when you multiply that by 100 users, which is why I ask that question, why do you need to append data and what type of data is being appened every 4 minutes?
  20. Do you have some code?
  21. $xmlFileData = file_get_contents("xml/myxml.xml"); $xmlData = new SimpleXMLElement($xmlFileData); $xmlName = $xmlData->color[$_GET['myid']]->name; I think you were just using the $_GET call wrong, you do not have to print it if you are using it internally to PHP.
  22. Just a shot in the dark, I am not sure if this is possible, but does your host deny your .htaccess file for the AddType? I would think they would be able to but yea, I am not sure. Are you also sure that .htaccess file is at least in the same directory, or one directory above the directory where the files are kept? That code should work just fine, so yea. That is why I am throwing that out there.
  23. Different topic it should be. But you are not setting those as a class. <?php //Finding web root $dr=($_SERVER['DOCUMENT_ROOT']); //Loading system config require ($dr . 'config.php'); $config = array('db_host' => 'bob', 'db_user' => 'bob2'); // etc $db = new dbClass($connectionSettings); class dbClass() { //constructor public function __construct($config) { $this->db_host = $config['db_host']; // etc. // however I would just pass the parameters to connect and not store them as class variables. $this->connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); // this is assuming you passed in an array for $config. $config = null; // no need for the connection info to stay valid. } //System connection public function connect($db_host, $db_user, $db_pass, $db_name) { if(!$this->con) { $sys_connect = @mysql_connect($db_host,$db_user,$db_pass); if($sys_connect) { $select_db = @mysql_select_db($db_name,$sys_connect); if($select_db) { $this->con = true; return true; } else { return false; } } else { return false; } } else { return true; } } //System disconnect public function disconnect() { if($this->con) { if(@mysql_close()) { $this->con = false; return true; } else { return false; } } } //System tables load private $result = array(); private function tableExists($table) { $system_tables = @mysql_query('SHOW TABLES FROM '.$this->$db_name.' LIKE "'.$table.'"'); if($system_tables) { if(mysql_num_rows($system_tables)==1) { return true; } else { return false; } } } //System select public function select($table, $rows = '*', $where = null, $order = null) { $q = 'SELECT '.$rows.' FROM '.$table; if($where != null) $q .= ' WHERE '.$where; if($order != null) $q .= ' ORDER BY '.$order; if($this->tableExists($table)) { $query = @mysql_query($q); if($query) { $this->numResults = mysql_num_rows($query); for($i = 0; $i < $this->numResults; $i++) { $r = mysql_fetch_array($query); $key = array_keys($r); for($x = 0; $x < count($key); $x++) { // Sanitizes keys so only alphavalues are allowed if(!is_int($key[$x])) { if(mysql_num_rows($query) > 1) $this->result[$i][$key[$x]] = $r[$key[$x]]; else if(mysql_num_rows($query) < 1) $this->result = null; else $this->result[$key[$x]] = $r[$key[$x]]; } } } return true; } else { return false; } } else return false; } //System insert public function insert($table,$values,$rows = null) { if($this->tableExists($table)) { $insert = 'INSERT INTO '.$table; if($rows != null) { $insert .= ' ('.$rows.')'; } for($i = 0; $i < count($values); $i++) { if(is_string($values[$i])) $values[$i] = '"'.$values[$i].'"'; } $values = implode(',',$values); $insert .= ' VALUES ('.$values.')'; $ins = @mysql_query($insert); if($ins) { return true; } else { return false; } } } //System delete public function delete($table,$where = null) { if($this->tableExists($table)) { if($where == null) { $delete = 'DELETE '.$table; } else { $delete = 'DELETE FROM '.$table.' WHERE '.$where; } $del = @mysql_query($delete); if($del) { return true; } else { return false; } } else { return false; } } //System update logic for($i = 0; $i < count($where); $i++) { if($i%2 != 0) { if(is_string($where[$i])) { if(($i+1) != null) $where[$i] = '"'.$where[$i].'" AND '; else $where[$i] = '"'.$where[$i].'"'; } else { if(($i+1) != null) $where[$i] = $where[$i]. ' AND '; else $where[$i] = $where[$i]; } } } $keys = array_keys($rows); for($i = 0; $i < count($rows); $i++) { if(is_string($rows[$keys[$i]])) { $update .= $keys[$i].'="'.$rows[$keys[$i]].'"'; } else { $update .= $keys[$i].'='.$rows[$keys[$i]]; } // Parse to add commas if($i != count($rows)-1) { $update .= ','; } } //system update public function update($table,$rows,$where) { if($this->tableExists($table)) { // Parse the where values // even values (including 0) contain the where rows // odd values contain the clauses for the row for($i = 0; $i < count($where); $i++) { if($i%2 != 0) { if(is_string($where[$i])) { if(($i+1) != null) $where[$i] = '"'.$where[$i].'" AND '; else $where[$i] = '"'.$where[$i].'"'; } } } $where = implode('=',$where); $update = 'UPDATE '.$table.' SET '; $keys = array_keys($rows); for($i = 0; $i < count($rows); $i++) { if(is_string($rows[$keys[$i]])) { $update .= $keys[$i].'="'.$rows[$keys[$i]].'"'; } else { $update .= $keys[$i].'='.$rows[$keys[$i]]; } // Parse to add commas if($i != count($rows)-1) { $update .= ','; } } $update .= ' WHERE '.$where; $query = @mysql_query($update); if($query) { return true; } else { return false; } } else { return false; } } } ?> It also looks like you have some issues in that class. I would highly recommend reading more on OOP in PHP and finding better examples of how to use it, cause that just shows you are just guessing at it all without having the proper form. I would actually recommend looking at an already built mysql class and see how that is constructed. Anyhow hope that helps ya.
  24. There are a few different alternative options to it: http://www.google.com/search?hl=en&q=mysql_real_Escape_string+alternative&btnG=Google+Search&aq=f&oq= The best example that I used to use is: function my_real_escape_string($value) { $search = array("\x00", "\n", "\r", "\\", "'", "\"", "\x1a"); $replace = array("\\x00", "\\n", "\\r", "\\\\" ,"\'", "\\\"", "\\\x1a"); return str_replace($search, $replace, $value); }
  25. premiso

    Explode Help

    You are using regex in the explode function, when explode does not understand regex. Try preg_match if you want to use regex.
×
×
  • 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.