Jump to content

eevan79

Members
  • Posts

    240
  • Joined

  • Last visited

    Never

Everything posted by eevan79

  1. Ok it seems that I have solve it. In my class database handler I have added following code: $result = $db->query("SET NAMES 'utf8'"); And now everything works fine. Is there any other solution?
  2. I do not know how many times was this question, but simply can not solve it. Field in database: Type: mediumtext Collation: utf8_bin When I insert text like: ŽĆČĐĆ I get this: ŽĆČÄĆ I have tried various solution but none works. Also tried to change php file encoding: UTF8, UTF8 without BOM, ANSI, Different character sets but no results. How to insert this latin characters into database?
  3. $result = mysql_query( "select yearID, year from sss.years")
  4. Fixed $command = "/usr/bin/mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupFile";
  5. $link = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname,$link); $backupFile = $dbname . date("d-m-Y-H-i-s") . '.gz'; $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile"; system($command); It creates empty .gzip file. It doesnt work.
  6. I am using small script (with crone) to backup database every morning, zip and send me mail (with .sql/zip attached). But backup is not in UTF-8 format, so I get this: "Č" -> "C" "Š" -> "S" etc. I have tried various solution but nothing works. Also tried utf_encode() function, but then I get strange characters. Script looks like this: function backup_tables($host,$user,$pass,$name,$tables = '*',$date) { $link = mysql_connect($host,$user,$pass); mysql_select_db($name,$link); //ALL TABLES if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } //GET DATA foreach($tables as $table) { $result = mysql_query('SELECT * FROM '.$table); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE IF EXISTS '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = str_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //SAVE $handle = fopen('Backup-'.$date.'.sql','w+'); fwrite($handle,$return); fclose($handle); } Database Collation: utf8_binType: [/size]MyISAM [/size]How to save .sql file in proper UTF-8 Format?[/size]
  7. Here is function that backup mysql database. It's working fine, but I want to download file instead of creating it. /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = '*') { $link = mysql_connect($host,$user,$pass); mysql_select_db($name,$link); //get all of the tables if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } //cycle through foreach($tables as $table) { $result = mysql_query('SELECT * FROM '.$table); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = str_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //save file $date= date("d-M-Y_h-i"); $handle = fopen('Backup-'.$date.'.sql','w+'); fwrite($handle,$return); fclose($handle); } Usage: But this will create backup file on server. I also tried to add following code in function (at the end): echo $return; header('Content-type: text/plain'); header("Content-Disposition: attachment; filename=\"$filename\""); How to just download file, without showing it on screen instead of using fwrite/fclose function?
  8. Ok, I solve it. First I must find records per page. And limit it if there is less than total files per page. $total_on_page = $per_page-(($page*$per_page) - $file_count); if ($total_on_page<$per_page) {$per_page = $total_on_page;}
  9. I already try that, but count($files) is total files in folder. This will also create undefined offset for last page.
  10. I'm sorry, but I thought it was obvious that it is in loop. It shows that it is in line 50 and 52 which is: Complete code: Errors highlighted in red. Also, I understand why this throws an error. Error occurs when there is more definition in the array, and these files donot exist (for example, when I go to the last page where it displays 3/ 10 results per page - the other 7 files were undefined). How to fix it?
  11. I am getting following notice in code: Notice: Undefined offset: 2 in ... Notice: Undefined offset: 3 in etc.. I want to get all files from directory with pagination system. It is working, but how to remove this notice (when error_reportings is enabled). Here is code: $exts = array('w3g'); $per_page = 10; // How many files per page $files = array(); $dir = opendir($replayLocation); while( ($file = readdir($dir)) != false ) { if( !is_dir($file) && !in_array($file,array('.','..')) && in_array(substr($file,strrpos($file,'.')+1),$exts) ) { $files[] = array( 'path' => $file, 'filename' => pathinfo($file,PATHINFO_BASENAME), 'name' => pathinfo($file,PATHINFO_FILENAME) ); } } closedir($dir); $file_count = count($files); $page_count = ceil( $file_count / $per_page ); $page = ( isset($_GET['page']) && is_numeric($_GET['page']) ) ? (int) $_GET['page'] : 1; if( $page > $page_count ) { $page = $page_count; } if( $page < 1 ) { $page = 1; } $offset = ( ( $page - 1 ) * $per_page ); for( $i = $offset; $i < ( $offset + $per_page ); $i++ ) { //$files[$i]['path']; //$files[$i]['filename']; if (file_exists($replayLocation."/".$files[$i]['filename'])) { $current_file = $files[$i]['filename']; echo "<a href='./$replayLocation/$current_file'>$current_file</a><br>"; } } echo '<br><table><tr><td style="padding-right:24px;" align="right" class="pagination">'; if( $page > 1 ) { echo ' <a href="./file.php?page=1"><<</a> <a href="./file.php?page=',( $page - 1 ),'"><</a> '; } $range = 5; for( $x = ($page - $range); $x < ( ($page + $range) + 1); $x++ ) { if( $x > 0 && $x <= $page_count ) { if( $x == $page ) { echo ' [ ',$x,' ] '; } else { echo ' <a href="./file.php?page=',$x,'">',$x,'</a> '; } } } if( $page != $page_count ) { echo ' <a href="./file.php?page=',( $page + 1 ),'">></a> <a href="./file.php?page=',$page_count,'">>></a> '; } echo '</td></tr></table>';
  12. I want to get latest posts from phpbb3 forum. Here is my code: $table_posts = "phpbb_posts"; $table_users = "phpbb_users"; $sql = "SELECT $table_posts.post_id, $table_posts.topic_id, $table_posts.forum_id, $table_posts.post_subject, $table_posts.poster_id, $table_posts.post_time, $table_users.user_id, $table_users.username FROM $table_posts LEFT JOIN $table_users ON $table_users.user_id=$table_posts.poster_id WHERE forum_id <> 3 AND forum_id <> 21 ORDER BY post_time DESC LIMIT 5"; And it's working fine. But I want to improve this code and dont get data from same topic_id . Thats mean if there is already post from topic_id 45, I dont want to get another post from same topic_id. How to get latest posts, but not from same topic_id?
  13. Hi, I have tried your code and it gives me wrong results or error. Can't remember what it is. I'll try to combine your and my code to get all items with one query.
  14. I found solution. It's not so hard. Here is code: SELECT count(*) as total, item1 FROM dotaplayers WHERE hero = '$heroid' GROUP BY item1 having count(*) > 1 ORDER BY total DESC LIMIT 5 Thats for item1
  15. Ok, I have tried your code but it gives me following result: ItemType -> item1 Item -> blank (nothing) ItemCount -> 3105 This is my code: SELECT 'item1' AS ItemType, item1 AS Item, count(*) AS ItemCount FROM dotaplayers GROUP BY ItemType, Item UNION SELECT 'item2' AS ItemType, item2 AS Item, count(*) AS ItemCount FROM dotaplayers GROUP BY ItemType, Item UNION SELECT 'item3' AS ItemType, item3 AS Item, count(*) AS ItemCount FROM dotaplayers GROUP BY ItemType, Item UNION SELECT 'item4' AS ItemType, item4 AS Item, count(*) AS ItemCount FROM dotaplayers GROUP BY ItemType, Item UNION SELECT 'item5' AS ItemType, item5 AS Item, count(*) AS ItemCount FROM dotaplayers GROUP BY ItemType, Item UNION SELECT 'item6' AS ItemType, item6 AS Item, count(*) AS ItemCount FROM dotaplayers GROUP BY ItemType, Item $getItems = $db->query($sql); $rowItems = $db->fetch_array($getItems,'assoc'); echo $rowItems['ItemType']; echo $rowItems['Item']; echo $rowItems['ItemCount'];
  16. I know, but it's only possible if hosting program (which is used for importing data) modify to update another table. Maybe solution is to periodically update count for items table via cron (or some script). Then I need to check for about 300 items. Only problem is that items is chained with heroes (another table). My goal is to check most used items for each hero. So I dont need items count table, but hero_items and update data for every filed (hero_items.item1, hero_items.item2 etc.) where I match most used item. I'm not sure which is best way to do something like this.
  17. Fileds: Values: \0\0\0\0 - This is empty/blank item and no need to count. All items have 4 characters and it's not separated by a space, comma... item1 filed is slot 1 for item item2 is for slot 2... There are 6 slots and I want to find most used item for each slot. Let's start for item 1...then it'll be easy to find for other slots.
  18. This field contain 4 letters code like 'H45T', 'AB7T' etc. Also I have images H45T to match selected item. So I want to find most used item in filed items. There are lots of records with different or same items code, so I want to find what same items are most used. This can be very hard job for MySql cause it need to compare every filed . Maybe this is impossible to do in this way.
  19. How to find most frequently word in table field? I have table players with filed items and want to find most used word in that filed. Items are like 'HIDU', 'I099', 'I05F'. Thats item code (id) that is used for images. I also have table items where is filed itemid same as items in players table. In that table I have additional information about that item. So how to find one frequently used item in from players table ?
  20. Yeah...that was my question about (look at first post) . I know that I can solve it with adding additional vars into javascript, but my script is a bit complicated then that. var offsetfromcursorX=12 //x offset of tooltip var offsetfromcursorY=10 //y offset of tooltip var offsetdivfrompointerX=10 //x offset of tooltip DIV relative to pointer image var offsetdivfrompointerY=14 //y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1). document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV document.write('<img id="dhtmlpointer" src="img/arrow.gif">') //write out pointer image var ie=document.all var ns6=document.getElementById && !document.all var enabletip=false if (ie||ns6) var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "" var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : "" function ietruebody(){ return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body } function tooltip(thetext, thewidth, thecolor){ if (ns6||ie){ if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px" if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor tipobj.innerHTML=thetext enabletip=true return false } } function positiontip(e){ if (enabletip){ var nondefaultpos=false var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft; var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop; //Find out how close the mouse is to the corner of the window var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20 var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20 var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000 //if the horizontal distance isn't enough to accomodate the width of the context menu if (rightedge<tipobj.offsetWidth){ //move the horizontal position of the menu to the left by it's width tipobj.style.left=curX-tipobj.offsetWidth+"px" nondefaultpos=true } else if (curX<leftedge) tipobj.style.left="5px" else{ //position the horizontal position of the menu where the mouse is positioned tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px" pointerobj.style.left=curX+offsetfromcursorX+"px" } //same concept with the vertical position if (bottomedge<tipobj.offsetHeight){ tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px" nondefaultpos=true } else{ tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px" pointerobj.style.top=curY+offsetfromcursorY+"px" } tipobj.style.visibility="visible" if (!nondefaultpos) pointerobj.style.visibility="visible" else pointerobj.style.visibility="hidden" } } function hidetooltip(){ if (ns6||ie){ enabletip=false tipobj.style.visibility="hidden" pointerobj.style.visibility="hidden" tipobj.style.left="-1000px" tipobj.style.backgroundColor='' tipobj.style.width='' } } document.onmousemove=positiontip I'll probably switch this script to JQuery...
  21. Yes...finally I debug it. Problem is WHERE dg.winner <> 0 So this query is only for wins and losses. 0 means DRAW. And thats why other disc arent counted. I totally forgot that this query ignore unfinished/uncompleted games. So many headaches .... and always turns out to be a simple problem.
  22. bah...now we are at start with this code. It's working only in FFox, cause there is no quotes for <img src inside tooltip function in your code... Still my old code is working...
  23. OMG, you are right. I made big mistake, sorry. I put your code instead of my code, but there one quote left from my previous code. So thats why we can see that layout. Anyways here is your code (I have added one more string, but basically its yours) $hero = '<a onMouseout="hidetooltip();" onMouseover="tooltip(\''.$heroname.'<br><img src=img/heroes/'.$hero.'.gif\');" href="hero.php?hero='.$hero.'"><img alt="" width="28px" src="./img/heroes/'.$hero.'.gif" border=0></a>'; Apologies for the misunderstanding...what else can I say EDIT:
  24. Ok...thank you for your time. Just note that code is working for you, not for me. It depence what is your tooltip function. And there is no additional code that I'm not sharing or else. HTML is valid. Your forgot say about quotes for ...HREF=" and string $string="<a... $string = "<a href=' I understand why its not valid your example. Because you open single quote for mouseover and then for tootip. Try it in HTML, and you will see this is not valid. "<a onmouseover='tooltip('some_text, or whatever')'..." Yes, it's escaped but in html there's double opening single quotes. We have this quote "structure" (blue are double, red are single and orange is single inside red quotes): " ' ' ' ' " It's not Pyhton that have triple quotes. You can see almost same problem here . Anyway, thank for your time, I appreciate it. (marked as solved.)
×
×
  • 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.