Jump to content

neuroxik

Members
  • Posts

    43
  • Joined

  • Last visited

Everything posted by neuroxik

  1. Hooo! It works now! Thank you so much for all your time!
  2. Sorry for replying late again, pretty busy week + sick but I really appreciate your help and input. I thought it might be the regex. I did use the as different trailing ID numbers as quoted in my previous post. I'll try the alert and put it on my server so you can see by the source, if ever you have the time that is. My test of the previous example can be seen here : http://arraykey.com/ajaxtests/test9.php . The reason the second link makes it jump a line is because the strings I fetch are embedded in <p></p> tags, so that's what's creating the break-line (not an issue, I was just mentioning in case you were wondering) And here's with alert(divID) as you suggested : http://arraykey.com/ajaxtests/test10.php
  3. Hmm, it halfway works, but I see where you're getting at, great idea. Thanks! I'm not trying you to solve it, I'll only explain what happens in case you were wondering : <a href="ajaxtest.php?data=1" class="reload tDiv" id="tDiv1">Click Here 1</a> <!-- yeh, I had them named as tDiv by now, but same principle as you --> <a href="ajaxtest.php?data=2" class="reload tDiv" id="tDiv2">Click Here 2</a> <div id="tDiv"><!-- load here --></div> What this does (with your functions) is the first link (Click Here 1) loads the data correctly in tDiv, but link 2 loads it, somehow, where "Click here 2" itself was. At first I thought the data was only appending itself until I saw the 2nd link itself dissapear. Again, no big deal, I'm trying to figure this out myself. I suck at Javascript to be honest, but I think that's clearly been made obvious. Thanks again for your input! Great insights.
  4. Thanks! Now that works. Yes, should've checked the console. By the way, speaking of consoles, I use Console² and Firebug for Firefox, would you have any better suggestions? A huge thank you to Xaotique and you, DavidAM, for having shed alot of light on this. I'll still try to manage passing the target Div through argument (maybe through the "rel" attribute? I was worried about semantics but again, it is sort of "related" if you take it into context). Atleast now I have some working ground to do this by myself, I just didn't know where to start, so a huge thank you again! {marking as solved}
  5. Ah, I can't edit my last post anymore, sorry for bumping. Tried the above code and doesn't work, it loads the page like a href normally would do.
  6. Sorry, I've been really sick for the last couple of days and wasn't able to get back to you. So I've just tested changing the load(url) to html(data) (I had actually tried load(data) as last resort the other day, which obvisouly didn't work either) and now this seems to work so far. Thank you! I'll post the code below as requested, only difference is the other day html(data) was load(url). There's not much, I only did test files apart without any sanitization because they're only tests : test4.php : <!DOCTYPE html> <html> <head> <meta charset='utf-8'> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> </style> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".myClass").click(function(e) { e.preventDefault(); $.get($(this).attr("href"), function(data) { $("#myDivID").html(data); /* chg'ed "load(url)" to "html(data)" */ }); return false; }); }); </script> </head> <body> <a href="ajaxtest.php?data=1" class="myClass">Click Here 1</a> <a href="ajaxtest.php?data=2" class="myClass">Click Here 2</a> <div id="myDivID"><!-- load here --></div> </body> </html> and ajaxtest.php : <?php $data = addslashes($_GET['data']); if($data) { if($data=='1') echo '<p>some data one</p>'; elseif($data=='2') echo '<h1>other data two</h1>'; } ?> I'll just try to re-put some code you had suggested earlier so that some instances can have some content load by default on page load. EDIT: I'm still trying to figure out how I could pass the target ID within the link so I can use different links (in other sections of the page) that would load in other divs rather than load them in #myDivID. Of couse, I wouldn't name those links with the "myClass" class, but would I have to create a different function for each case or can I just pass the target div (div to load content in) as an argument rather than hardcode it as #myDivID ?
  7. Yeah, I'm sorry about the class, I know you mentioned it now but I was so overwhelmed by the Javascript that I thought you meant writing a class as in OOP class. Wow! This worked! But when I changed alert(data) to $("#myDivID").load(url); it doesn't load, I don't know what I'm doing wrong there. I did obviously include the div itself with #myDivID. By the way, a huge thanks, I know this must seem like trivial stuff for you guys but it's helping me out alot.
  8. Hm, great idea. Unfortunately it doesn't load anything. Atleast it solves the double ID and the 2nd link loading a new page doesn't do that anymore. Thanks nonetheless for having taken the time to check out my problem!
  9. Thanks for you reply again! I tried this like you said: $("#myLinkID").click(function(e) { var url = $(this).attr("href"); /* <-- added var url THIS */ e.preventDefault(); $("#myDivID").load(url); return false; }); /* and for test links : */ <div id="bla">links : <a href="ajaxtest.php?action=no&data=1" id="myLinkID">1</a> <a href="ajaxtest.php?action=no&data=2" id="myLinkID">2</a> </div> <div id="myDivID"><!-- load here --></div> It works on the first click (thanks!) but doesn't when say I click on link 2, it loads the called (href) page instead of loading it in the div. I'm presuming because both links share the same Div ID. Anyway, thanks alot for your input, I'll try figuring out from here on, atleast I have some base to work on.
  10. Thanks for the reply! I read and tested the code and the first ones loaded the content into the div on page load. I'm not looking to autoload content but rather load the content when the user clicks. The last part of your code did actually work for that, this part: $("#myLinkID").click(function(e) { e.preventDefault(); $("#myDivID").load(url); return false; }); Now two things as I've mentioned earlier : 1 - Can I put the url part (the one that in your code is declared as var url) in the link? I want this because my links are change depending on the context and get the context via GET variables, so I can have (in this case a calendar) "cal.php?sel_year=2013&sel_month=04". I'm trying to figure out how to pass the url string as an argument. 2 - I'll be using this on multiple links on multiple divs for different purposes. Do I have to write a function for each target div or can I (most logically) pass the Div ID as an argument too?
  11. I've searched everywhere and just can't seem to find my answer, so here: I'm powerful with php and that I can deal with, but I never really had the chance to develop my javascript skills. I want to use JQuery to load part of a page in a container div. The problem is every tutorial I check out, the target (or result) div where the content will load is already defined in the function. Is there a way to include 2 arguments like this : (pseudo-code, I don't know the real syntax, still a newb at JQuery) function ajaxpage(url, containerid){ // do the magic here } // and calling the page <a href="javascriptTheJQueryWayHere:ajaxpage('page.php?id=12','load_in_this_div')">link</a> <div id="load_in_this_div"></div> I don't necessarily want a baked answer, just any link to any resource except RTFM would be of great help!
  12. Thanks! I was hoping this was not the case but now atleast I know. I was going to check my browser cache to see but then again, doesn't mean it's not cached that it hasn't been downloaded.
  13. Hey everyone, I've been starting to use @font-face in the last year or so seeing that most major browsers support it now. I usually just use 1-3 fonts max, but most often I include the italics version, bold and italic bold version, which can easily amount to a couple MBs of data minimum (depending on the font). Since I use EOT, TTF, WOFF and SVG to work in most browsers, the filesize augments. I don't want too much bandwidth (and load time) used, especially when it's not absolutely necessary upon the customer's request, so I was wondering : say if Firefox (or any browser) successfully loads the EOT version of the file, will that browser still download all 3 others or it will specifically ignore the rest? If it does ignore the rest (not download them) then bandwidth would be much less of an issue. I know some of you might say "well, bandwidth nowadays...", but I still prefer to keep things minimal by habit.
  14. I'm pretty much out for the rest of the week but I'll try that out some time soon and let you know if I come across a problem or come and praise you if this works. Thanks alot. I hate having overkilled on the code because I ignored about metaphone and the similar functions, but hey, we're always learning.
  15. Wow, you've opened me up to a world of possibilities with metaphone, soundex and the similar functions. If only I would've known about this before. Thanks. Sorry for over-complicating my examples, I'll try keeping with the basic output for these examples' sake. Thanks for all your input, by the way. Here's a list of user input strings and what they generate: SELECT * FROM `gni` WHERE `name` REGEXP '".$ns_src."' ORDER BY `name` ASC 1 - "Anna " outputs http://img211.imageshack.us/img211/9466/13116717.jpg (I'm using a screenshot because upon clicking Preview, the special characters aren't encoded properly here) (It searches Ana|Anna , having found that alternate spelling in $name_similes array) The reason for the multiple a's is that different languages use different characters sometimes, as I mentioned earlier. It returns, among other too numerous results: Ana Beatriz Barros Anna Christine Speckhart 2 - "Anna Chri" outputs http://img411.imageshack.us/img411/2329/99856546.jpg (screenshot) This one only outputs this (which is what is expected) Anna Christine Speckhart Note: There's no [[:<:]]word boundaries[[:>:]] around the last "Chri" because a user will rarely put a space at the end of his last word, and I also want to be able to fetch with partial results. Where the problem comes is if someone enters "Anna Speckhart" in the input. (screenshot just in case: http://img32.imageshack.us/img32/1576/33794545.jpg ) "Christine" being the middle name, it doesn't find it since the name is Anna Christine Speckhart. That's why I was wondering about the "[word] [word | space] [word]" (to put it in a vulgar way).
  16. I'm sorry I'm bumping, can't find the edit button on my previous post, but: how would you write space or word? Would (\s|\w) do the job ? But I'm also thinking, another word means surrounding spaces too, so could it be ( \s | (\s \w \s) ) (without the spaces)
  17. For code, there's quite a bit, but since you ask: function prepStrForSrc($str=NULL,$nm_similes=NULL) { $r = array( 'go_on_with_src' => FALSE, 'src_str' => ltrim($str), # trim only leading spaces 'passed_thru_prep_func' => 1, 'orig_str' => $str ); $tr_str = trim($str); if(empty($tr_str)) return $r; $r['go_on_with_src'] = TRUE; $r['src_str'] = strtolower_utf8($r['src_str']); $has_backslashes = strpos($r['src_str'],'\\'); if($has_backslashes===FALSE) $r['src_str'] = addslashes($r['src_str']); if(empty($nm_similes)) $treat_similes = FALSE; else $treat_similes = TRUE; # even if no treat_similes, still want seperators on each name pieces for mysql src $pcs = explode(" ",$r['src_str']); $num_pcs = count($pcs); // 'ali' will return 1, 'ali ' (with space) will return 2, so trim each then to know if empty, but atleast now know (when space) that previous is "[word]" /* works this way: [[:<:]] (name1|name2|name3) [[:>:]] without the () around name1|name2|name3, it'll find alizee with ali (not wanted) -- wouldn't do that on last since not alot of chances someone will write "John Doe " (instead of "John Doe") */ $new_terms = array(); $is_last = FALSE; // until set to TRUE. "John Doe", on first loop (John) still false, then true on "Doe". $i = 1; if($num_pcs > 1) { foreach($pcs as $k=>$word) { $trimmed = trim($word); if($i == $num_pcs) $is_last = TRUE; if(!empty($trimmed)) { if($treat_similes) { # cond 1 $t = getKeyNameSimiles2($trimmed,$nm_similes,$is_last); if($t['similes_found']===TRUE) $tmp_new_word = $t['nm_similes_formatted']; else $tmp_new_word = $t['term']; // hmm... still need to put a [[:<:]] around it if not last $new_terms[] = $tmp_new_word; } else { # cond 2 $tmp_new_word = sqlTermWrappers($trimmed,$is_last); $new_terms[] = $trimmed; } } $i++; } } else { // no [word] wrappers because maybe word ain't finished # cond 3 // only one str word, maybe incomplete yet, but still want to check (if strlen > 1) for similes if(strlen($pcs[0])>1) { $t = getKeyNameSimiles2($pcs[0],$nm_similes,$is_last=TRUE); if($t['similes_found']===TRUE) $tmp_new_word = $t['nm_similes_formatted']; else $tmp_new_word = $t['term']; } else $tmp_new_word = $pcs[0]; $new_terms[] = $tmp_new_word; } // implode $new_terms , also use chars for mysql here BETWEEN each term, if necessary, use here $new_terms_specchars = array(); foreach($new_terms as $k=>$v) { $new_terms_specchars[] = specCharVariations($v); } unset($new_terms); $r['src_str'] = implode(" ",$new_terms_specchars); /* now, to find "John Doe" even if write "Doe John", have to use formated return as above, then separate like this (string_query_1|string_query_2), string_query_2 for Doe Jogn. No spaces (works) << DO LATER */ return $r; } function sqlTermWrappers($str=NULL,$is_last=TRUE) { # $is_last can also be used if only one term has been entered with no spaces yet, used as 'not_necessarily_complete', so no () around if(empty($str)) return $str; if($is_last) $str = sprintf('[[:<:]]%s[[:>:]]',$str); else $str = sprintf('[[:<:]](%s)[[:>:]]',$str); return $str; } function specCharVariations($str=NULL) { if(empty($str)) return $str; #$str = utf8_fix($str); // DON'T INCLUDE mysql query REGEX chars such as [:< $str = preg_replace("(e|?|?|?|?)","(e|?|?|?|?)",$str); // we don't want these, only for test purposes $str = preg_replace("(a|?|?|?|?|?)","(a|?|?|?|?|?)",$str); // ? $str = preg_replace("(i|?|?|?|?)","(i|?|?|?|?)",$str); $str = preg_replace("(o|?|?|?|?|?)","(o|?|?|?|?|?)",$str); $str = preg_replace("(u|?|?|?)","(u|?|?|?)",$str); $str = preg_replace("(?|c)","(?|c)",$str); $str = preg_replace("(?|n)","(?|n)",$str); /* CHANGES DONE HERE MUST BE PASTED INTO ../config.php:specCharVariations() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ //$str = utf8_decode($str); return $str; } function strToAlpha($str=NULL) { if(empty($str)) return $str; // expected to already be strtolowered $str = preg_replace("(?|?|?|?)","e",$str); $str = preg_replace("(?|?|?|?|?|?)","a",$str); $str = preg_replace("(?|?|?|?)","i",$str); $str = preg_replace("(?|?|?|?|?)","o",$str); $str = preg_replace("(?|?|?)","u",$str); $str = str_replace('?','c',$str); $str = preg_replace("(?|ń)","n",$str); $str = str_replace('?','ae',$str); $str = str_replace('?','oe',$str); return $str; } Then prepStrForSrc calls getKeyNameSimiles2() : function getKeyNameSimiles2($term=NULL,$nm_similes=NULL,$is_last=FALSE) { # also chk comments inside prepStrForSrc() func $r['similes_found'] = FALSE; $r['term'] = $term; $r['nm_similes_formatted'] = ''; // if $is_last is TRUE, then don't limit to that (ex.: John Doe, user input: "John Do", want to find "John Doe", so no () around "Do" ) if(empty($term) || strlen($term) < 2) return $r; if(empty($nm_similes) || !is_array($nm_similes)) return $r; // now need to temporarily switch to strict alpha (example: Jos?e becomes Josee). Will use specCharVariations() anyway, so no interference $term_alpha = strToAlpha($term); foreach($nm_similes as $k=>$v) { if(is_array($v)) { foreach($v as $k2=>$name) { if($term_alpha == $name) { $r['similes_found'] = TRUE; $nm_similes_arr = $nm_similes[$k]; $new_terms_f = array(); foreach($nm_similes_arr as $alt) { $new_terms_f[] = addslashes(strtolower_utf8($alt)); } $r['nm_similes_formatted'] = implode("|",$new_terms_f); $r['nm_similes_formatted'] = sqlTermWrappers($r['nm_similes_formatted'],$is_last); break 2; } } } } return $r; } Above, it'll get similarities from another array, which is not quite important to mention here but I just didn't want the type of answer "you don't need REGEXP for this", that's why I gave the context of similar names, alternative letters found in specCharVariations so that writing "St?phanie" still finds "Stephanie" as well as "Stephany". Then I call it this way: /* I'M NOT INCLUDING ALL THE CLEANING HERE, like if strlen < 2, addslashes, etc */ $ns_src = utf8_decode($ns_src); $q_str = "SELECT * FROM `gni` WHERE `name` REGEXP '".$ns_src."' ";
  18. Hey everyone. So I want to be able to find "John Bee Doe" when the user input is "John Doe". I'm using REGEXP because I'm already using what I call $name_similes containing an array of similar names (ex.: Britney, Britanny, etc). I'm stuck on this part though (John Bee Doe). I tried using REGEXP imploding on spaces after each word (search term) to replace with ([[:alpha:]]|[[:space:]]) which I assumed would include either a space, but it doesn't work. Anybody hae any advice or ideas ?
  19. Hmm... I'm kind of ashamed. I'm answering to you both to thank you for your time and effort. Kicken: exactly, why didn't I use sprintf, which does exactly what I was aiming for. I do not know WHY my head interpreted sprintf as the equivalent of printf (which actually prints the data and doesn't assign it to a variable, as you most probably know), so what I was looking for was a function LIKE printf but that you can use inside variables, but it happens that my example was the solution. I'm quite confused as to why this even processed in my mind. So my problem is solved, thanks to you all. p.s.: I'm not experienced on this board, so do I "mark as solved" when a thread is solved or do I leave time for others (like you guys) to reply?
  20. The point was that your query is invalid, both in the example and your code. A query can only have a single WHERE clause, not several joined together using ||. Also, since your using an OR condition, you can just use the IN clause in your query to make things easier. ex: WHERE SUBSTRING(name,1,1) IN ('a', 'b', 'c', ...) The value you put in the IN clause can be generated very easily via imploding an array of multiple possible values. You would just find your array of alternatives in the list and implode that and stick it into the in clause. About the multiple WHERE's, I wasn't sure anymore and upon execution I got an error, so removed the WHERE and just put it in the SQL before including my variable, I just couldn't edit the post above after that. But again, that's not my point, I should have avoided MySQL in my question altogether. I don't care whether the MySQL works or not, I just used it quickly to give a case scenario. My question is: is there any way to use a sprintf-like function that will concatenate variables inside variables? in the way I've described in my first post, a bit à la sprintf. But on another note: thanks for the IN trick, will spare me some time one day
  21. Maybe I haven't been clear about what it is I was (my bad), but the imploding part for the mysql is done later and I found it irrelevant to my question. My question isn't about mysql, I just happened to use it as an example. Here's my code in context as you asked: $sl = 'e'; function sqlWhereMultipleChrs($c=null) { $default = " WHERE SUBSTRING(name,1,1) = '".$c."' "; $w_start = ' WHERE SUBSTRING(name,1,1) = \''; $w_end = '\' '; if(is_null($c)) return $default; $alternatives = array( 'a' => array('a','à','á','â','ä','ã'), 'b' => array('b'), 'c' => array('c'), 'd' => array('d'), 'e' => array('e','è','é','ê','ë'), // 'f' => array('f'), 'g' => array('g'), 'h' => array('h'), 'i' => array('i','ì','í','î','ï'), // 'j' => array('j'), 'k' => array('k'), 'l' => array('l'), 'm' => array('m'), 'n' => array('n','ñ'), 'o' => array('o','ò','ó','ô','ö','õ'), // 'p' => array('p'), 'q' => array('q'), 'r' => array('r'), 's' => array('s'), 't' => array('t'), 'u' => array('u','ù','ú','û','ü'), // 'v' => array('v'), 'w' => array('w'), 'x' => array('x'), 'y' => array('y','ý'), 'z' => array('z'), ); $possibs = $alternatives[$c]; $cnt = count($possibs); if($cnt == 1) $sql = $w_start.$possibs[0].$w_end; elseif($cnt > 1) { $sql = array(); foreach($alternatives[$c] as $v) { $sql[] = $w_start.$v.$w_end; } $sql = implode(" || ",$sql); } else return $default; return $sql; } $sqlwhere = sqlWhereMultipleChrs($sl); // outputs : WHERE SUBSTRING(name,1,1) = 'e' || WHERE SUBSTRING(name,1,1) = 'è' || WHERE SUBSTRING(name,1,1) = 'é' || WHERE SUBSTRING(name,1,1) = 'ê' || WHERE SUBSTRING(name,1,1) = 'ë'
  22. Hey everyone, I've come around this problem quite a few times now, so I'm looking for a cleaner way to do what I always resort to. Here's my scenario: The following line is fairly straightforward: $sql_where = " WHERE SUBSTRING(name,1,1) = '".$c."' "; But sometimes I need to explode on some values, rising a need for multiple instances of the above, as in MYSQL's WHERE bla = 1 || WHERE bla = 2 || WHERE bla = 3 Of course, I could always write it out manually, like this: foreach($c as $v) { $sql_str .= "WHERE SUBSTRING(name,1,1) = '".$v."' "; } But I want my code to be more modular. The only solution I've been using so far is something like this: $where_start = "WHERE SUBSTRING(name,1,1) = '"; $where_end = "' "; foreach($c as $v) { $sql_str .= $where_start . $v . $where_end; } I find this technique a bit ridiculous and I was wondering if there was a similar method as say when you want to sprintf like this: $v = 'Bla bla %s bla'; sprintf($str, $v); So my question is basically this: is there any way to use a sprintf-like function that will concatenate variables inside variables? Thanks for any suggestions or input.
  23. I had trouble understanding what you were asking for, but if you want to convert the to the smiley GIFs, but only the first 3 found in $txt, and the rest just represented as text, escaping it ( :\) )worked on my side: $txt = "Bla bla ya no maybe please 1 2 3 4 5 nada"; $replace = array(""=>"<img src=html/emoticons/smile.gif>", "2"=>"b", "3"=>"c", "4"=>"d", "5"=>"e"); $txt = preg_replace("'(:\)|2|3|4|5)'e", '$replace["\1"]', $txt, 3); echo $txt; // outputs: Bla bla <img src=html/emoticons/smile.gif> ya <img src=html/emoticons/smile.gif> no <img src=html/emoticons/smile.gif> maybe please 1 2 3 4 5 nada You said you tried it and it didn't work on your side, just letting you know THIS (quoted above) works on my side.
×
×
  • 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.