Jump to content

imperialized

Members
  • Posts

    100
  • Joined

  • Last visited

Everything posted by imperialized

  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.
  14. Ok, I have read the responses above. Thank you all again for replying. The code has been modified as such: //Build the years array, we can only go forward 3 years, backwards 1 year. $startYear = date(Y) - 1; //Start Year $years = range($startYear, $startYear+4); $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; This, however, still does not work. The $years array contains all of the right numbers (Thanks for that, much more efficient and clean) When the if statement runs: The reason I chose to use $curYear is because that is the current year I am working with, and noot because it is necessarily the actual year. Thanks for your opinion, however.
  15. The reason I used true for that condition is because if that is true, it changes it to that value. all other conditions, false, set to the current dates value. I believe you are are correct about not converting it to a number and I am trying to match a string. I will test when I get home.
  16. Hey everyone!!! It has been years since I have had to opportunity to post on here. I am, however, getting back into development. I am running into an issue and I was looking for some help. Here is the code: $years = array(); //Build the years array, we can only go forward 3 years, backwards 1 year. $sYear = date(Y, strtotime('-1 years')); //Start Year $eYear = date(Y, strtotime('+3 years')); //End Year while($sYear < $eYear){ array_push($years, $sYear); //Add each year that fits to the array $sYear++; } //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 = clean($_GET['curYear']); print "Before anything: curYear = $curYear <br><br><br>"; if($curYear == "" || $curYear == null){ //No Year set, use current print "empty or null<br>"; exit; $curYear = date(Y); }elseif(!is_numeric($curYear)){ //Not even a number lol print "not number<br>"; $curYear = date(Y); }elseif($aSearch = in_array($curYear, $years, true)){ print "valid year<br>" . $years[$aSearch]; //It isn't in our array of valid years //$curYear = date(Y); }else{ //all else failed $curYear = date(Y); print "Failed all tests.<br>"; } //Should be a good year for our calendar by this point. exit; I am passing the variable curYear in the url: index.php?curMonth=July&curYear=2013 For some reason, it outputs: Before anything: curYear = 2013 Failed all tests. printing the $years array gets: Array ( [0] => 2013 [1] => 2014 [2] => 2015 [3] => 2016 ) I think you get the just of what I am looking for here. Thanks for the help!!
  17. Thank you, I did just realize however that I need to grab the following number if it is available as well. Not quite as important, but can come in handy for me. If I had any clue how regex worked I could figure it out by looking at the code you provided. Unfortunately, I don't have the slightest clue! If anyone here could point me in the right direction, http://domain.com/xxx-c-39_107.html I am referring to pulling the 107 from the URL. Again, this number could be more or less than 3 characters. Thanks!
  18. That looks like it should accomplish EXACTLY what I need. Thank you for the exceptionally quick response!!
  19. This sounds much more simple than it really is.. to me anyhow! I really don't have a true understanding off all this Regex stuff so I really hope someone here can give me a hand! I'm working with a Zen Cart installation with SEO URLs installed so all of the pages are cached .html files. The URLS have the following (patterns?) http://domain.com/xxx-c-39.html http://domain.com/xxx-c-39_107.html The number that I need from that URL would be "39" Is there a way to just parse the URL and pull that number? it always immediately follows the last - but the length of the category ID changes. Any help is appreciated!!! Thanks in advance.
  20. This is just a suggestion but I do believe it may point you in the right direction. After you download the file from your FTP: $lines = file('your_text_file.txt'); // Loop through our array foreach ($lines as $line_num => $line) { //use a ereg to search for a certain user/setting -- replace if necessary } I am not really familiar with ereg or I would try to help more.. maybe someone else can build on this if it will get you going to the right place.
  21. I hope someone can help! I'm truly stuck here. ** I am using the latest version of jQuery and jQueryUI ** Im working on writing a script to edit user information. Basically what happens is this: A user clicks on a link > using jQuery, I pull information from a second page to populate a DIV on my current page. function editaccount(id){ jQuery.ajax({ type: "POST", url: "include/ajax/accountActions.php", data: 'id=' + id + '&mode=editAccountView', cache: false, success: function(response){ var responseCode = response.substring(0,2); var responseString = response.substring(2); if(responseCode == "ok"){ $("#editAccountDiv").hide().html(responseString).fadeIn("slow").draggable(); } else { alert("Response is: " + responseString) //Error } } }); } Once this page has loaded it has a form to update user information. What I want to do is use another AJAX call to save my form. Currently my form submit function is: function checkForm(){ var error = 0; var error_msg = ""; var FullName = document.getElementById("FullName").value; var BdayMonth = document.getElementById("BdayMonth").value; var BdayYear = document.getElementById("BdayYear").value; var BdayDay = document.getElementById("BdayDay").value; var PhoneNumber = document.getElementById("PhoneNumber").value; var AddressStreet = document.getElementById("AddressStreet").value; var AddressState = document.getElementById("AddressState").value; var AddressApt = document.getElementById("AddressApt").value; var ZipCode = document.getElementById("ZipCode").value; var AddressCity = document.getElementById("AddressCity").value; var isAdmin = document.getElementById("isAdmin").value; var isValidated = document.getElementById("isValidated").value; var aboutMe = document.getElementById("about_me").value; //Lets do some basic javascript checks before we go calling ajax stuff if(FullName.length == 0){ error = 1; error_msg = " Full Name field is empty \n"; } //Phone Number var PhoneReg = /^\((\d{3})\)(\d{3})[- ](\d{4})$/; if(!PhoneReg.test(PhoneNumber) || PhoneNumber.length < 12){ error = 1; error_msg = error_msg + " Phone Number is in incorrect format \n"; } //Check Street Address var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~_"; for (var i = 0; i < AddressStreet.length; i++) { if (iChars.indexOf(AddressStreet.charAt(i)) != -1) { error = 1; error_msg = error_msg + " Address contains invalid characters \n"; } } //Zip Code if(ZipCode.length < 5){ error = 1; error_msg = error_msg + " Zip Code is too short \n"; } //Check Street Address if(AddressStreet == ""){ error = 1; error_msg = error_msg + " Street Address is blank \n"; } //Check City if(AddressCity .length < 5){ error = 1; error_msg = error_msg + " City is too short \n"; } if(error > 0){ //and Error has occured alert("Fix the selected errors before submitting: \n\n" + error_msg) return false; } jQuery.ajax({ type: "POST", url: "include/ajax/check_username.php", data: 'username='+ username, cache: false, success: function(response){ if(response == "OK"){ alert("ok!") }else{ alert("not ok?") return false; } } }); } Notice that I use getElementById to grab the variables. This is because using the jQuery selector $('xxx') would not pull the variable, it would only echo give me "undefined". All of the error checking works just fine, just can not get the jquery call to work. Can someone please point me in the right direction?
  22. Ok, that was not the issue. The problem lies within javascripts ability to manipulate tables. In order to achieve what I wanted I would have had to change my javascript completely and change each cell individually. To overcome this, I just switched to using DIVs to arrange the information and it works just fine
  23. I think that is the problem, but how do I fix that? The element isnt created until after the first ajax call is made. I am fairly new with ajax so I don't truly understand it.
×
×
  • 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.