Jump to content

eaglehopes

Members
  • Posts

    102
  • Joined

Profile Information

  • Interests
    Logic games, computer programming.

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

eaglehopes's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

6

Community Answers

  1. Thanks kicken! So, I learned that "ordering" its importance in such situations. Without it, I am working on this solution: 1. a loop on the first query results and start a counter 2. match the path of the filename with the filename(or path) in the row 3. get the counter and find the page number by dividing counter to the result per page variable But, your solution is much more simple and elegant. Mehcanics always said that "less number or parts cause less errors and provide higher reliability". Less code does the same. That will solve my problem and I can find that my file is on which page by COUNT(*).
  2. My question is about how to get where is the old row in new query. Let me explain in detail. I have a categorized blog pages such under "computer programming". Computer programming has its own sub categories too. One is "Linux" for instance. And when I did "pagination" to show all blogs under "computer programming"\"Linux" such as, list of id and link were in table by sql query SELECT id,path, subCategoryId FROM `files` WHERE categoryId=5 AND subCategoryId=15 result table was : id path subCategoryId 297 /pages/blog/PH/GT/10.html 15 298 /pages/blog/PH/GT/11.html 15 299 /pages/blog/PH/GT/12.html 15 300 /pages/blog/PH/GT/1.html 15 301 /pages/blog/PH/GT/2.html 15 302 /pages/blog/PH/GT/3.html 15 303 /pages/blog/PH/GT/4.html 15 304 /pages/blog/PH/GT/5.html 15 305 /pages/blog/PH/GT/6.html 15 306 /pages/blog/PH/GT/7.html 15 307 /pages/blog/PH/GT/8.html 15 308 /pages/blog/PH/GT/9.html 15 333 /pages/blog/PH/GT/13.html 15 There are some missing files(htmls), so their id numbers did not match with the neither id number nor their filename. PH -philosophy is the category name, GT - general topics is subcategory name. In my home page, I listed the most current ones according to their edit dates and when user clicked the link of one of the latest blogs, link directed page to the according category page. There is a pagination at each category and I am showing three records per page. So when I clicked the for instance the link of the file "8.html", I knew that I will be in number 4 in the result of the first query and know that it will be shown in the page #4(since three records was shown in each page). The point I stucked is that : 1. I did the first query and get the results (table above) 2. How can I find the position of the page 8.html in the query I did in above using sql ? So my question is simply : how can I get an queried item's order/position? What I want to achieve is that, in my webpage's home, I show latest blogs. When user clicked one of them, I want to go to the related category and subcategory page and correct pagination link that include the blog will be back-colored with green. (one can get/test the question idea in my web page by clicking the latest blog in my home page and see the result : http://enginery.freecluster.eu/index.php?page=blog&subblog=CP&fin=WEB&blogPage=./pages/blog/CP/WEB/14.html. It opens the correct category and pagination is working, but I could not find the position of blog, where it was under the correct pagination. I want to color the correct link of the page number when I got there.) I hope, I could explain my question clearly. Thanks for any help.
  3. I finally learned a bit of SQL and transferred the main part of my webpage content to MySQL database. Now my website became much faster! Just a few lines of SQL code solved lots of problems and opened a new vision, i.e. TODO list 😮 .
  4. I wanted to record the code below that worked to extract CSS attributes : 1. In CSS file get :root { --width: 300px; --height: 300px; --innerPadding : 3px; --radius : 4px; --borderThickness : 1px; --diameter : calc(2*(var(--radius) +var(--borderThickness)) ); } #innerDiv { width : var(--width); height : var(--height); ... } 2. in javascript file : innerDiv = document.getElementById("innerDiv"); const elementStyleValues = getComputedStyle(innerDiv); // to extract CSS attributes innerDiv.style.width=( (width - 2*diameter) - 2*innerDiv.style.borderWidth.replace("px","") )+"px"; innerDiv.style.height=( (height - 2*diameter) - 2*innerDiv.style.borderWidth.replace("px","") )+"px" ; // get and write CSS attribute height of innerDiv element : errorLine.innerHTML= elementStyleValues.getPropertyValue('height'); // worked! So, using CSS attributes, kind of automation for dimensioning and sizing can be done by using javascript's getComputedStyle() function.
  5. Ok requinix, then can I say that CSS could not change any of the attributes of any objects in HTML? If so, then I put some width for div element in CSS, then I can not get it as attribute. But how can I see it has some width then? Is CSS cause some kind of mask? How is this possible, does browser cause this? I think I found to how to get the "CSS attribute" of element from javascript code : using getComputedStyle() function! So I learned that: 1. I can not change any HTML attribute directly by using CSS, 2. to get changed CSS attribute of HTML element in javascript, I should use getComputedStyle() function ! Thanks requinix for guide.
  6. Actually, I noticed that, when I explicitly define width and height attributes in HTML (not from CSS), they worked. It looks like a "hard-coded" vs. "soft coded" or something like that... I do not know : what worked was : <svg id="dotBorder" width="300" height="300" class="borderedSVG" > ... </svg> When I define width and height in CSS by var(--width) or var(--height), javascript does not understood it. Why?
  7. Thanks requinix, 1. What I am actually trying to do is that creating a custom div element having a border with my drawn SVG. I will try to get svg's width and height but not worked too? 2. parentOfSVG has the same dimension, I put it as a wrapper, but now worked like mine 3. If so, I could get svg's width and height, but I could not? 4. there are very good illustrations in the link ! I am looking them !
  8. Hi, I am trying to get the element's width and height by using element.getAttribute() function, but not worked. Not worked function was : function loading() { svg = document.getElementById("dotBorder"); errorLine = document.getElementById("error"); innerDiv = document.getElementById("innerDiv"); parentOfSvg = document.getElementById("parentOfSVG"); console.log(" svg : " + svg + " errorLine :"+errorLine+ " innerDiv :"+innerDiv+ " parentOfSvg:"+parentOfSvg); width = parentOfSvg.getAttribute('width') ; height = parentOfSvg.getAttribute('height'); console.log(" w1 : " + width + ", h1 :" + height ); } since error saying that "parentOfSvg" element is "undefined", width and height variables gave error. My code was available in https://codepen.io/eaglehopes/pen/MWZOEgg . Can anybody says that what is wrong? Thanks.
  9. Thanks Barand, I did and I saw other errors at last and finally I noticed that the error is in dateTime format! Thanks. I think I can solve it now! My code was : try { $result1 = executeSQLStatement($con,$subCategoryInsertQuery); } catch (Exception $e) { if( mysqli_errno($con) != 1062 ) { // if it's not a dupe error echo $e ; // report it. } }
  10. third option : "I want to prevent them but not report them if they are attempted?".PATH is not the primary but the unique key, because it is unique for each subcategory.
  11. Thanks Barand, I opened error reporting and it gives : Fatal error: Uncaught mysqli_sql_exception: Duplicate entry '/fold1/' for key 'PATH' in /htdocs/filer.php:728 What does that mean? I am looking the table and see no duplicate entry! How can I prevent duplicate entry ?
  12. Hi all, I have a php code which did not give any error(I think) but nothing inserted into the database. I am trying to insert all file structure and contents of the files into database by getting info from them and supply these into to insertData function: <?php ini_set('display_errors', '1'); error_reporting(E_ALL); //mysqli_report(MYSQLI_REPORT_ALL); // can give a fatal errors ans stops php script! mysqli_report(MYSQLI_REPORT_OFF); function insertData($folderName,$subFolder,$file,$parentId,$dateAdded,$dateEdited,$summary,$title,$content) { $subCategoryIdSQLQuery= "SELECT id FROM `subCategory` WHERE subCategory.path = '/pages/blog/$folderName/'"; $con=OpenConnection(); // < OPEN DATABASE CONNECTION $sql2 = mysqli_prepare($con,$subCategoryIdSQLQuery); // < SQL Statement 1 if($sql2 !== FALSE ) { $result2 = executeSQLStatement($con,$subCategoryIdSQLQuery); $subcategoryId= $result2->fetch_row()[0]; $pathy="/pages/blog/".$folderName."/".$subFolder."/".$file; $fileInsertQuery="INSERT INTO `files` (path,categoryId,subCategoryId,dateAdded,dateEdited,title,summary,content,active) VALUES( '$pathy', '$parentId', '$subcategoryId', '$dateAdded', '$dateEdited', '$title', '$summary', '$content', '1')"; $sql3=mysqli_prepare($con,$fileInsertQuery); // < SQL STATEMENT 2 if( $sql3 !== FALSE ) { $result3 = executeSQLStatement($con,$fileInsertQuery); } else { echo mysqli_error($con)." at file : ".$folderName."/".$subFolder."/".$file; // for sql3 } } else { echo mysqli_error($con); // for sql2 } closeConnection($con); // < CLOSE DATABASE CONNECTION } function CloseConnection($conn) { mysqli_close($conn); } function executeSQLStatement($con,$query) { if($con) { return $con->query($query); } else { return null; } } function OpenConnection() { $dbhost ="hostname"; $dbuser ="username"; $dbpass ="password"; $db = "filesDb"; global $conn; // DEFINE conn as global variable to be able to use in other functions as well! $conn = new mysqli($dbhost, $dbuser, $dbpass,$db); if( $conn == true ) { //printf("Success... %s\n", $conn->host_info); } else if ($conn->connect_errno) { //printf("Connection failed!... %s\n", $conn->host_info); throw new RuntimeException('mysqli connection error: ' . $conn->connect_error); exit("Connection failed: %s\n".$conn->connect_error) ; } return $conn; } ?> I could not insert any info into database! Where did I do wrong? Is there any way to make error(if there is any) visible? Thanks.
  13. Sorry, I had made a mistake, I noticed it ! I corrected my code as above : :D
  14. Thanks all, I corrected my code and finally got and see correct returns for "thumbing" variable and use it in my php code to add it to mysql database. I did not changed anything in my fetch code(so I did not re-post it here), but I did : 1. I used $_REQUEST[] to see whether my response goes there or not, but finally I deleted $_REQUEST[] line. 2. I used strider64's code to see all errors in console. As Barand's suggestion(after strider64's code), I looked to the console and all errors shown in console in fantastically detailed such that finding and correcting my code takes about a minute ! Thanks strider64! Then I returned to my own code and it worked like a charm! 3. replace wrong string concetanation operator (+) in my php code(sql_connection.php) with correct ones (.) Yes, Chrome's F12-console is very helpful in debugging ! I added my php code to use thumbing result to add it into my mariadb database (in sql_connection.php). I gave it, maybe, I hope it helps someone . My code was : if( isset($thumbing) ) { echo "thumbing is ok" . $thumbing; addThumbValues($sendedFilePath,$thumbing); } function addThumbValues($thumbResponse) { $up=""; $down=""; // TODO can use ternary operator to save code lines in future if($thumbResponse == 1 ) { $up=1; $down="0"; } else if (thumbResponse == -1) { $down=1; $up="0"; } $conn = OpenConnection(); // open database connection $sql = mysqli_prepare($conn,"INSERT INTO `thumbs` (up,down) VALUES ('$up','$down')"); if($sql !== FALSE){ if(mysqli_stmt_execute($sql)){ //echo "New record created successfully"; } else { echo mysqli_stmt_error($sql); echo "Error in record creation : failed!"; } } else{ echo mysqli_error($conn) ." sql statement is false"; } CloseConnection($conn); // close database connection } Thanks.
×
×
  • 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.