Jump to content

eaglehopes

Members
  • Posts

    102
  • Joined

Everything posted by eaglehopes

  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.
  15. I think I do something with these? if( isset($_POST["thumbing"] ) ) { $thumbing=$_POST["thumbing"]; echo "thumbing is set : ".$thumbing; } else { echo "thumbing is not set..."; } I think I echoed if the "thumbing" variable passed successfully? Didn't I do it correctly?
  16. Hi all. Today I tried a form which sends data inside the formData object to a php file with fetch method. But when I try to capture the sended "thumbing" variable from php file, I could not got it! sql.html <form id="thumbEvaluationForm" method="POST" action="sql_connection.php" > <div> <input id="thumbup" type="radio" name="thumbing" value="1" > <input id="thumbdown" type="radio" name="thumbing" value="-1" > <input type="submit" name="Submit" > </div> </form> and sql_connection.php file content : <?php error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_OFF); unset($thumbing); if( isset($_REQUEST["thumbing"] ) ) { echo " request get as thumbing ".$_REQUEST["thumbing"]; } if( isset($_POST["thumbing"] ) ) { $thumbing=$_POST["thumbing"]; echo "thumbing is set : ".$thumbing; } else { echo "thumbing is not set..."; } then I add a listener to submit event of the form to send formdata to php file(sql_connection.php). window.onload= function() { var thumbform = document.getElementById("thumbEvaluationForm"); thumbform.addEventListener('submit', (event) => { event.preventDefault(); // disable event's default behaviour const thumbFormData = new FormData(thumbform); alert("thumbing is send as : " + thumbFormData.get("thumbing")); // got correct result of thumbing from radio button ! fetch("sql_connection.php", { method: 'POST', body: thumbFormData }) .then(response => { if (response.ok) { // Handle the successful response } else { // Handle the error } }) .catch(error => { // Handle the error }); }); } I could not get $_POST['thumbing'] or $_REQUEST['thumbing'] in sql_connection.php code? Why? Where is the mistake? Thanks.
  17. Then the code and "tight dependency" comments are in another forum page are totaly garbage ! When I saw in there code and it got 46 positive responses, I supposed that it was a working code... but not! Daniele Rugginenti as the last commenter said the correct thing! I hope in the future, one internet firm should apply a "correctness filter" to all of search results by the help of user contributions, if not, for learners it will be a waste of time to learn from internet sources. Or everyone should go back to learn from books as it were in the past
  18. OK, I found the problem why it sometimes work sometimes not : because it is javascript line contains a php code and when page load, first php code run and awkward results comes! Therefore, my above method is not a correct way of calling a function inside a php! So, as kicken said that, it is not a request at all ! It is a just a php code written inside a javascript line !
  19. Why I asked this question is that because of the comments to user Sandeep Kapil's similar code in tight dependency comments of another forum in the internet. I learned that tight dependency occurs when stateful protocol used but someones claim the otherwise. Thanks kicken for great answer, but I have difficulty to understand your above statement, why it isn't count as a request? Until your answer I am thinking that I am triggering and requesting/calling the result of the function inside the php file after run it server. Can you explain a little bit more what happens really when my code run, please? Because what I understood that, php code injected into javascript code calls the function inside another file and returns the function's returned result(I am not so quite sure since I experienced that any echoed string value before the return statement will return as a result). I know that my code does not seem the right way to get/fetch the result of function in another php file and I found at least one disadvantage of using it although it workes as I expected. So, I am not insisting on the "properness" of the code, but I am really curious to learn why it works only sometimes, not always? Thanks.
  20. I found Guawong Miao's blog which defines when request become stateless or stateful. I think my request does not requires server to save any state of user, so it uses stateless protocol, am I right? How can I determine/learn while developing a request, which one use which(i.e. stateless or stateful)? Is there any tool (such as can Chrome's developer tool or wireshark) show that? Which one is the simplest one? Thanks.
  21. I have a such javascript code in a php file called index.php; <?php include mathfunctions.php; ?> ... <script> var a=10, b=20; var stars=<?php echo multiply(a,b); ?> </script> I learned that there are two types of protocols, stateless(such as HTTP) and stateful (such as FTP). My question is that, when I used above line of code, does this cause my request to use stateful or stateless protocol? Didn't both use HTTP request? Thanks.
  22. No, I could not manually configured anything before installing XAMPP since I did not know where and how to do it(by the way I am still do not know it). However, after installing XAMPP, it puts all apache, php and sql files under the same folder(/opt/lampp) and by the help of XAMPP's own help documents I learn that how to configure each(including php.ini etc.). I managed my website by using php-javascript code combination such that, php code does : 1. first checks category/subcategory folders and put their names on the menu 2. checks folders for each subcategories 3. lastly, checks files under each subcategories and prepage them as links 4. javascript get all those links and put them into pagination process. Therefore, when I add a "x.html" file under category/subcategory folder, it automatically put it into the menu as a link, similar for category and subcategories- each folder creates a new item in menu.... I read some specific tags from each ".html" file I added such as title, date publish/edit and summary....etc. and when users clicks on it, everything will be tranferred to the div inside the main page... goes on like that, so I did my some kind of automatic website management system. I am now trying to do all these jobs by using sql database. So when I delete some files, it automatically removed from web page links. Therefore, in such times I need to create XML sitemap again! So list of files is basically for 1. creating XML sitemap and 2. to see which file I edit the latest. Since I put some of the latest edited blog pages in my home page (main.js does that). It means it includes last edit time info too. I created a shell(bash) script file and using this file, I can create XML sitemap easily. Script is very easy, simply add page's own link and some xml tags and before and end of file's path ! No problem every bit knowledge is important.
  23. 1. I tried installed them package by package but, could not start Apache2. Since I didn't know there is log, but I could not know etc. so I changed my tactic and uninstall all and install XAMPP. Even after XAMPP apache server did not start since it gave error "port already listening..." due to that another program had already used apache's port etc. I used "ss" command etc. to solve it manually(i gave details in my own blog page). So normal procedure did not work as I expected for me as a beginner, so I used XAMPP which is more compact and solves all of my configurations related problems(except port ) . And using XAMPP in Linux is not a guilt, XAMPP has Linux version . 2. Since English is not my mother/native language, it is my mistake. 3. Thanks for drawing an attention to that point,I am learning so I will be more careful about that point next time. Ok, as you said, file_put_contents error was solved, since I copied everything from server to local htdocs folder of XAMPP but under folder named "enginery", not to its root(htdocs). So as you said my php code did not work locally because of that ! I love red flags . If I prevent access to that file by .htaccess file, can I drop that red flag? I used them as root but changed as you suggested and now everything is easier than before! Thanks requinix from a short course from English to Linux & PHP !
  24. Hi all, I installed XAMMP for Linux 8.2.4 to run my website including php codes test locally first. When I copied everything one-to-one from server to my local htdocs folder of XAMMP, I can run my page and php codes, and css codes. However, not javasript codes. My index.php file includes external javascript file defined as in meta tag : <script type="text/javascript" src="/js/main.js"></script> File is there but developer console said "main.js could not found". Then I looked at the w3schools website(https://www.w3schools.com/tags/att_script_src.asp) and I changed the line as : <script src="./js/main.js"></script> I added "." infront of the path and remove 'type="text/javascript' words. Then error gone, but none of the function worked correctly. New error was : Warning: file_put_contents(/opt/lampp/htdocs/pages/filesList.txt): Failed to open stream: No such file or directory in/opt/lampp/htdocs/enginery/pages/standards/home.html Warning : file_put_contents(/opt/lampp/htdocs/pages/filesList.txt): Failed to open stream: No such file or directory in /opt/lampp/htdocs/enginery/pages/standards/home.html What is happening? Both files are there, is there any problem with write premission? Everything under XAMMP's htdocs are under root's control, is this the problem? Does anybody guide me to solve this error? 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.