Jump to content

imperialized

Members
  • Posts

    100
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

imperialized's Achievements

Member

Member (2/5)

0

Reputation

  1. psycho, After rethinking it and looking at the posts provided that is exactly what I did. It wasn't important to keep the formatting for the summary.
  2. Like the guy above mentioned, I am using tinyMCE so I don't have much choice when it comes to storing the tags with the data. I used a combination of techniques to accomplish what I was trying to achieve. It seems to be working. Albeit not the #1 solution, it will suffice for the purpose of this project. Thanks for the help. The following code is what was used to accomplish the intended result: $summary = strip_tags($this->blogPost); $summary = implode(' ', array_slice(explode(' ', $summary), 0, 100)); The above code gets the first 100 words of the blog post.
  3. Alright, so I have ended myself in a predicament. Lets say, for example, I have a blog post that has 500 words (not including any HTML markup within). The post stored in the DB could be something like this: <div style='text-align: left'> post post post post post post </div> <div style='text-align: left'> post post post post post post </div> <div style='text-align: right'> post post post post post post </div> <div style='text-align: left'> post post post post post post </div> <div style='text-align: left'> post post post post post post </div> <div style='text-align: center'> post post post post post post </div> <div style='text-align: left'> post post post post post post </div> <div style='text-align: left'> post post post post post post </div> <div style='text-align: right'> post post post post post post </div> <div style='text-align: left'> post post post post post post </div> <div style='text-align: left'> post post post post post post </div> <div style='text-align: center'> post post post post post post </div> <div style='text-align: left'> post post post post post post </div> <div style='text-align: left'> post post post post post post </div> Doing a word count, or substr, or splitting in on a space could potentially leave disaster if it splits in the middle of a style, or leaves out a closing tag for html markup. I've thought about doing a substr($post, 0, 200) and pulling the first 200 characters but that leaves the possibility for the above mentioned issues. Doing a slice also leaves the issue: $postSummmary = implode(" ", array_slice(explode(" ", $post), 0, 100); Any ideas?
  4. $tagHolder = array(); $this->blogTags = array_filter(array_map('trim', explode(',', $blogTags)), 'strlen'); //Remove Empty Values, Trim Whitespace; //Insert New IDs $tagHolder = array_fill(0, count($this->blogTags), '?'); $query = "INSERT IGNORE INTO blogTags (tag) VALUES (".implode('),(',$tagHolder).")"; $stmt = $this->db_connect->prepare($query); $param = 0; foreach($this->blogTags as $tag){ $stmt->bindValue(++$param, $tag, PDO::PARAM_STR); } $stmt->execute(); //retrieve all tag ids $query = "SELECT id FROM blogTags WHERE tag IN (".implode(',',$tagHolder).")"; $stmt = $this->db_connect->prepare($query); $param = 0; foreach($this->blogTags as $tag){ $stmt->bindValue(++$param, $tag, PDO::PARAM_STR); } $stmt->execute(); $this->blogTagIds = $stmt->fetchAll(PDO::FETCH_COLUMN); // fetch just the ids as an array Final working code. Thanks Mac_Gyver and Barand
  5. I didn't test this as the other code appears to be working. Now I am just playing with the other half of it, haha. Pulling the IDs and putting them in the array.
  6. No, it works. My ftp program wasn't working properly to the changes. All I did was change some variable names (when I retyped it). Changing it to ++$param was the problem.
  7. Still returns the same error. Changing param to 1 and leaving it as is. Or leaving param at 0 and changing it to ++$param does the same thing.
  8. Thanks for the replies. I was working to try to work with the code you gave me. At first I couldn't understand how it worked, based on the idea of replacing the '?' marks, but further research showed me that they are numbered. So each ? mark was correspondent to the the order that it was. So 3 (?) = 1 2 3 as far as the binding of the parameters went. After further toying around with it, I am running into problems. This Code: $tagHolder = array(); if($this->db_connect()){ $this->blogTags = array_filter(array_map('trim', explode(',', $blogTags)), 'strlen'); //Remove Empty Values, Trim Whitespace; $tagHolder = array_fill(0, count($this->blogTags), '?'); print "holderCount: ".count($tagHolder); print "<br />tagCount ".count($this->blogTags); print "<br /><br />"; //Insert any NEW tags $query = "INSERT IGNORE INTO blogTags (tag) VALUES (".implode('),(',$tagHolder).")"; $stmt = $this->db_connect->prepare($query); $param = 0; foreach($this->blogTags as $tag){ $stmt->bindValue($param++, $tag, PDO::PARAM_STR); print "param: $param<br /> tag: $tag<br />"; } $stmt->execute(); exit; Produces this result (when 5 'tags' were inputted): holderCount: 5 tagCount 5 Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are 1-based in /home/imperialized/public_html/new_login/createBlogPost.php on line 52 param: 1 tag: abc param: 2 tag: def param: 3 tag: ghi param: 4 tag: jkl param: 5 tag: mno Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /home/imperialized/public_html/new_login/createBlogPost.php on line 56 I tried playing with it before coming back here to ask for help, but it doesn't seem to make sense. It has 5 placeholders for values, runs the bindValue loop 5 times, but still says there are too many/not enough. Thanks again
  9. Ok, I will try to clarify this as best as I can. I am creating a blog script. Basically, what I am trying to do is check the tags. The form has a tag input (comma delimited) ex: tag1, tag2, tag3 I explode the data into an array then check each one to see if it is in the database. If it is, get the ID and add it to the ID array. If it isn't, add it to the table and get the last inserted ID. This code: $this->blogTags = explode(',', $blogTags); foreach($this->blogTags as $tag){ //Check if the tag is in the database already, if so, get the ID $tag_query = $this->db_connect->prepare("SELECT * FROM blogTags WHERE tag = :tag LIMIT 1"); $tag_query->bindValue(':tag', $tag, PDO::PARAM_STR); $tag_query->execute(); if($tag_query->rowCount() > 0){ $result = $tag_query->fetch(PDO::FETCH_ASSOC); $this->blogTagIds[] = $result['id']; //Tag already exists, add the ID to our array } else { //Tag doesn't exist $add_tag_query = $this->db_connect->prepare("INSERT INTO blogTags (tag) VALUES (:tag)"); $add_tag_query->bindValue(':tag', $tag, PDO::PARAM_STR); $add_tag_query->execute(); $this->blogTagIds[] = $this->db_connect->lastInsertId(); } } This code works. I, however, am asking if that is the proper way to achieve the result. I'm sure that there is a better way. Any help would be appreciated. Thanks in advance!
  10. Hey guys!! So basically what I am doing here is pulling the directory out of a url. URL ex: http://www.xxx.com/THIS_IS_WHAT_I_WANT/ $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $arr = explode("/", $actual_link, 5); $page = $arr['3']; if($page <> ""){ $curPage = $page; }else{ //Home Page $curPage = "home"; } The code works as is. Being that I prefer to code the proper way and learn new things; is this the best way?
  11. Thanks again to all of you who helped. I marked the completed working code as the answer. You all are the best!
  12. Thank you for explaining that to me. Appreciate it. I guess if I paid a little close attention to the php date() page I probably would have noticed. Not only that, but all of their examples are quoted.
  13. Thanks to all of you guys. I must have been exhausted when I changed that code and missed the variable swap. Anyhow, the final working code is as follows: //Build the years array, we can only go forward 3 years, backwards 1 year. $startYear = date(Y) - 1; //Start Year $validYears = range($startYear, $startYear+4); //In order for us to make sure we have clean parameters for our jQuery calls later //We have to make sure that our year variable usage is consistant throughout. //If our case, we are passing the full 4 digit year as am INT = $curYear $curYear = trim($_GET['curYear']); print "Before anything: curYear = $curYear <br><br><br>"; //Check if the selected value is a valid year, if not set to current year if(!in_array($curYear, $validYears)){ $curYear = date("Y"); } //Should be a good year for our calendar by this point. print "curYear = $curYear"; exit; As far as the date() function goes, what does adding the quotes do? Specifically, if it is numeric data being passed. Thanks for the help.
×
×
  • 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.