Jump to content

cindreta

Members
  • Posts

    36
  • Joined

  • Last visited

Everything posted by cindreta

  1. Hey requinix, thank you for your answer. I tried to include your verion which i really find more better looking and shorte than mine but it didn't work, it didnt mark anything. I once again reverted to mine just to check if all is good and for now mine works: $string = preg_replace("/(\<strong\>)?\(([son])(\d+)\)(\<\/strong\>)?/i", '<a href="ajax/load-content.php?type=$2&marker=$3&category='.$category_id.'" data-target="#read-modal" data-toggle="modal"><span class="rule-annotation">$2</span></a>', $string); I am very interested in getting your thing to work though, so if you could check why it wouldn't be.
  2. UPDATE 1: I have somehow managed to get the following to work: preg_replace("/(\<strong\>)?\(([son])([0-9])\)(\<\/strong\>)?/i", '<a href="ajax/load-content.php?type=$2&marker=$3&category='.$category_id.'" data-target="#read-modal" data-toggle="modal"><span class="rule-annotation">$2</span></a>', $string); But this is not completly what i need. For instance it doesnt recognize above the number 9, so if somwhere there would be S12 or N34 it wouldn't replace it. Plus i readlly don't know if i did the strong tag part right, sometimes it might be there and somethimes not. Anyone?
  3. Hi guys, i am very new to Regex so i would need some guidance here. I am trying to save myself of going trough each article and replacing a bunch of similar tags with something else - to be exact i need to replace all markers marked (S1) with let's say <a href="#" class="modal" data-type="tip" data-number="1"><span class="tip">S</tip></a>. The problem of course is matching what i need. Example would be: <p><Lorem Ipsum <strong>(S1)</strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. <strong>(O2)</strong> It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like <strong>(S3)</strong> Aldus PageMaker including versions of Lorem Ipsum./p> As you can see in the example, i will get some HTML content that has keywords like S1...Sx or O1...Ox and i need to find them and replace them with some other HTML content. The pattern can go something like this: starts with letter "S" or "O" or "N" - the letters can be upper or lowecase after the 3 possible letters above there should be a number from 0-9 the combination is mostly emebeded inside a HTML strong tag, but it doesn't have to be. If it is in the strong tag then i need to remove that strong tag completly. i need to know the number after the letter so i can use it later to do a database request I am pretty sure that the patterns S1,O1,N1 will only occur in the cases i need to replace them. I won't have meaningfull text that will have the same pattern. So if someone can help me target this so i can replace it with some anchor tags. Thank you so much.
  4. i am working on this search engine. and in the advanced section you can turn on/off some of the options. So it you turn on an option it will search another table and so on. Instead of building a massive query and left joining lots of stuff. I tried a different approach. There is always a basic query and it returns the results to an array like this $sql = mysql_query("SELECT SQL_CACHE id FROM table WHERE field LIKE '$getquery' ORDER BY field"); while ($row = mysql_fetch_array($sql)) { $idArray[] = $row['id']; } mysql_free_result($sql); and if something is turned on then it adds something like this: if($_POST['value'] == "1") { $sql = mysql_query("SELECT SQL_CACHE table1_relation_id FROM table2 WHERE field2 LIKE '$getquery' ORDER BY field2"); while ($row = mysql_fetch_array($sql)) { $idArray[] .= $row['table1_relation_id']; } mysql_free_result($sql); } //end if so basicy i just continue the array and it keeps pumping ids into a big aray. after that i run array_unique and remove all duplicate results and then i foreach and get the whole item info ased on every id. it runs pretty fast. now i would like to make the second one a function. but when i do that it does not work. function sample($query, $table, $field) { $sql = mysql_query("SELECT SQL_CACHE naziv_id FROM ".$table." WHERE ".$field." LIKE '$query'"); while ($row = mysql_fetch_array($sql)) { $return[] .= $row['naziv_id']; } mysql_free_result($sql); return $return; } before i put it into a function $idArray vas a single continuous array. And if i try to do it like this: $arr[] = sample($query, "table1", "filed_id"); $arr[] .= sample($query, "table2", "filed_id"); it returns the result of the first array ok but if there are more then one results in other arrays it returns and arary inside of the array. like this: array(4) { [0]=> array(2) { [0]=> string(4) "9057" [1]=> string(5) "14186" } [1]=> string(5) "Array" [2]=> string(5) "Array" [3]=> string(0) "" } and all i wanna have is a single id variable that has all the id's in it. like $array = 1,2,3,4,5 but from different sources/functions can you help? thank you so much.
  5. Hi i have this ajax table that displays resutls from the database and you can search it live. if you type anything it returns the results and so on...everything normal untill i typed "pregled" - it's a croatian word and it wont find it, but phpMyAdmin finds it. Then i tried the part of that word just "preg" and all it did it returned all the results in the db, like he didnt eaven make the search. i check the firebug NET window and he does post the word "preg" to the server but the server just sends everyhing back. What could be the problem to this. Is "preg" somekind of a safe word or something and how can i fix this. thank you.
  6. yes maybe the best thing to do is your idea. get the time when a person opens the article edit, increment that time by let's say 5 minutes and store it to the database for that article. This way nobody can edit the article in the next 5 minutes, it sorta works like a queue, i can also tell the second user that he will be able to edit it in 5 mins or if the current user hits save before the 5 mins i can check with ajax if something changed. i guess this can work. its more of a hack than a solution ; ) i thought it's gonna be something extra complicated. thank you for ideas.
  7. Yes, i taught something similar. but it always comes back to what if the user just closes the window or a tab and doesnt eaven save anyhing. the database will still have a record that somebody is editing. i saw that wordpress has something similar but i couldn't figure out how exactly did it. they show you a message when you open up an article for editing saying that "username is editing the article...". you think it could work with sql only? thx for a fast replay btw
  8. So i have this CMS that is used by lots of users and generally they do have rights to edit each others article. So now i'm thinking how can i at least warn them that somebody else is already editing it. Just that. maybe with sessions? but what happens when a user just closes the windows, will it destroy it. i taught about storing the value to mySQL but again what if the user closes the windows and so on. i never did this and i could use a boost. thanks guys
  9. thank you very much for now it is working : )
  10. hi thank you very much five! it did stop the repeating of results : ) but now i does not implode those values with ";" or whatever i define. the code now looks like this: $query_t = "SELECT tag FROM tags WHERE news_id='$id'"; $result_t = mysql_query($query_t) or die('Error : '.mysql_error()); $rows_t = mysql_num_rows($result_t); if ($rows_t != "0") { while ($row_t = mysql_fetch_row($result_t)) { $glue_t = array(); for ($i = 0; $i < mysql_num_fields($result_t); $i++) { $glue_t[] = "$row_t[$i]"; } //end for loop $joined_t = implode("; ", $glue_t); echo $joined_t; } //end second while loop } //end if has results it echo's out the unique results but like this: "tag1tag2tag3" and like i said thats why i put implode so it would be: "tag1;tag2;tag3" any ideas? maybe i am putting somewhere in the wrong spot or something, but i am close to what i need so thank you very much, if you can figure this out it would be wonderfull ; )
  11. can anybody help me then, i still didn't manage a way to fix it : ( thank you all
  12. hi ignace, i tried your fix but it still repeats the results? what can i be doing wrong?
  13. Hi i have this problem where i have to export my database and it has a lot of tables and all. But ill give you an example of two i have the news table and tags table. And there can be like xx number of tags for every news item in the db, and i have to implode them with ";". But thats the problem, when i run this code all the tags do appear but they keep repeating like this: and for every next news id he repeats all the tags from every last item. can you help me fix this? thank you $sql = "SELECT * FROM news WHERE pid='$getp' ORDER BY added"; $result = mysql_query($sql) or die("Couldn't execute query: Reason; ".mysql_error()); while ($row = mysql_fetch_assoc($result)) { $id = $row['id']; //get the id for use in late query $query_t = "SELECT tag FROM tags WHERE news_id='$id'"; $result_t = mysql_query($query_t) or die('Error : '.mysql_error()); $rows_t = mysql_num_rows($result_t); if ($rows_t != "0") { while ($row_t = mysql_fetch_row($result_t)) { for ($i = 0; $i < mysql_num_fields($result_t); $i++) { $glue_t[] = "$row_t[$i]"; } //end for loop $joined_t = implode("; ", $glue_t); echo $joined_t; } //end second while loop } //end if has results } //main while
  14. so i have a cms and i would like to disable all other users to be able to edit a file that is currently being edited by some other user. i couldn't even get the idea how to start making this? do i use some kind of "temp" files or something. All the data comes from the database so entries hav an id? any ideas? thanks
  15. by that i ment i know i have to at the end go and make an htaccess file but i did not manage to do what i described in the post with htaccess only... well please tell me how it's done, or show me an example since you already know, i am very interested in keeping my query id's and still haveing the title in the url. can you show examples, code, web site tutorials or something? (ps. i searched google and there are mainly htaccess tutorials only? thank you
  16. Hi, please just don't tell me to use htaccess only with sef urls, i have been trying to solve this myself. Basicly my question is i have a cms and i wanna make seo friendly urls from this: site.com.news.php?id=55 to per say site.com/news/some-news-title if i got the idea right i would have to generate a sef url for every article and store it to mysql, and then do i have to change my queries(since i want titles and not id's in url) to be look something like this: select stuffhere from table where sefurl=$_GET[sefurl] is this how it works? i mean is this going to be slower then getting it by id? is there a way to still have id's in a mysql query an have titles in sef urls?? please i really need somebody to explain or show, its driving me crazy
  17. wow thank you so much i get it now, and thank you for the code sample u are the best : )
  18. ok, basicly i don't understan how this api stuff works but here is what i wanna do: i have a small cms and i would like it if i could integrate some kind of version checking for the cms,for instance if a client has like v1.2 and there is a newer version it should warn him. so i think i am supposed to make an api call to my server and check the latest version and send it back to the clients cms. so i need help writing that server api and the client code. im thinking that the lateste version could be kept in a xml file like myserver.com/api.xml and then the client code reads it and compares it if somebody can post some code examples i would be very thankfull
  19. no i can display the comments like you said, not seprated with |. i tried you'r code and it just displays <comment/> and nothing inside that? and also if a news has two comments it does display two of those <comment/><comment/> but nothing inside??? why is that, i only copy and pasted it and i don't know why it doesn't work. LATEST EDIT: i just replaced this: while ($row_c = mysql_fetch_row($result_c)) with this: while ($row_c = mysql_fetch_array($result_c)) and it seems to be working for now.
  20. yes yes i see, hm well this is what i got here now: $sql = "SELECT id,title,body from news"; $result = mysql_query ($sql) or die ("Couldn't execute query: Reason; ".mysql_error()); while ($row = mysql_fetch_assoc($result) ) { $xml .= "<news id=\"".$row['id']."\">"; $xml .= "<title>".$row['title']."</title>"; //get the comments $query_c = "SELECT id,body FROM comments WHERE news_id=".$row['id'].""; $result_c = mysql_query($query_c) or die('Error : ' . mysql_error()); $rows_c = mysql_num_rows($result_c); if($rows_c != "0"){ //while and count the number of comments and get them while ($row_c = mysql_fetch_row($result_c)) { for ($i=0; $i < mysql_num_fields($result_c); $i++){ $glue_c[] = "$row_c[$i]"; } } $joined_c = implode("|", $glue_c); $output .= " $joined_c"; } else { $output .= " none"; } }//end main while i have that pretty lame solution for getting the comments (please if you have a better ways for getting all the comments with the same id tell me) but and i do get an output, the problem if for the firsth news item it displays the right comments then for the second it shows the comments from the firsth plust the second and in the third news item all off them and so on? what am i doing wrong??? thank you
  21. so this is the scoop, i am doing some exporting from the database and i have two tables: news (id,title,body,....) second one is comments (id,body,news_id) and now i need to export all the database info to a xml structure document. so now i have per say this: $sql = "SELECT id,title,body from news"; $result = mysql_query ($sql) or die ("Couldn't execute query: Reason; ".mysql_error()); while ($row = mysql_fetch_assoc($result) ) { $xml .= "<news id=\"".$row['id']."\">"; $xml .= "<title>".$row['title']."</title>"; } and now i need to print the comments for that news item, but how to print multiple coments separated by "|"? Should i put another query inside the while loop? and how to count and echo all the comments for one news item? example of what i need: <comments>comment text 1|comment text 2.... </comments> i know i have to use implode to join them, i just don't know how to get them into that while loop
  22. ok so i kinda devided the sql code into two parts, one gets all the results and then later on it puts a limit to it... i used the phpfreaks tutorial for pagination. BUT I HAVE ONE PROBLEM, if you do a search for something and it turns out to have per say 13 results, and my limit per page is 10, whenever you click on a page number that resets, i guess it losses the search string value and just displays the whole database as a result. So how do i fix it, that i have that value of the search trough the whole pagaination process. 1. my sql search code: //SEARCH $q = $_POST['inputString']; $trimmed = trim($q); //trimaj $sql = "SELECT some stuff from table then a few joins WHERE name LIKE \"%$trimmed%\" OR lasname LIKE \"%$trimmed%\" GROUP BY idx"; $numresults = mysql_query ($sql) or die ("Couldn't execute query: Reason; ".mysql_error()); $row_num_links_main =mysql_num_rows ($numresults); 2. and then i put the first paggination code //results per page $rowsperpage = 10; $totalpages = ceil($row_num_links_main / $rowsperpage); if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } if ($currentpage > $totalpages) { $currentpage = $totalpages; } if ($currentpage < 1) { $currentpage = 1; } $offset = ($currentpage - 1) * $rowsperpage; $sql .= " LIMIT $offset,$rowsperpage" ; // continue the sql query with a limit 3. finish the pagination links // range $range = 10; if ($currentpage > 1) { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1' title='first'>first</a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage' title='previous'>previous</a> "; } for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<strong>$x</strong>] "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } } } if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage' title='next'>next</a> "; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages' title='last'>last</a> "; }
  23. Thank you for a fast replay. here is the deal. first i don't know if i can put COUNT () into this search query, plus because i wanna work with only one query how do i get the actual $offset value, because i have to first have the number of total results in order to get the offset, when i worked with smaller query's i just put first query like this: $sql_pagin = "SELECT COUNT(id) FROM table"; i get my variables then from here like totalnumber of rows, offset and all and then i do the second query with the limit and the offset value SELECT a lot of stuff here FROM table WHERE a lot of conditions GROUP BY id LIMIT $offset, $rowsperpage so how do i have only one query for search and get the offset number, have the count and all?
  24. So i have worked with pagination before but on simpler and smaller query's, this time i have a really long and huge search query and i don't wanna use it twice (once to count the results without the limit and then again the same query with a limit). I don't know how to use only one main query and somehow get the totalnumber of results and limit and everything. if you get what i am talking about, i can post more info and the code if needed. thank you hope someone helps ???
  25. GKWelding & R0bb0b thank you very much for the idea, no it won't be a problem to set thosse queryes at all...thank you very much for helping, if mods are reading you can make this into solved cos the answer is here....i just needed an idea of how to make it. Thanks guys
×
×
  • 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.