-
Posts
309 -
Joined
-
Last visited
-
Days Won
5
Everything posted by jodunno
-
I'm not being rude but math involves numbers. <script> document.write(screen.width); </script> - 20 = not valid mathematics. you must realize that you are assigning a string to the $screenwidth variable and not a number. if you use a number then the following code will work: $screenwidth = 3072; echo $screenwidth - 20; As a string, you could echo the string where you want the script to execute within the dom. But then you cannot use the JavaScript to assign the value to a php variable. PHP is a server-side scripting language. JavaScript is a client-side scripting language. I hope that my post helps you understand what is wrong with your logic.
-
Going insane. Ajax call sets session as expected but does not persist.
jodunno replied to jtorral's topic in PHP Coding Help
Hi jtorral, I think that, based upon your posted four-point problem, responsive css is a better method than trying to use php to respond to media sizes. https://developer.mozilla.org/en-US/docs/Web/HTML/Responsive_images media queries can also help for images or overall css adjustments for "other functions on the page like resizing pop up boxes and so on" https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries when you veer away from JavaScript driven pop-up dialogs and move to css modal methods, the above methods will save you alot of hassle, such as trying to post to an included php file and expecting it to receive the post. Have a look at the css and try that method instead. The session should be used to maintain state, which includes databases by storing a user id for repeated querying. You could post CSS questions in the CSS Help forum: https://forums.phpfreaks.com/forum/17-css-help/ And have a second look at what Gizmola posted, John -
easy to forget, i guess. I'm used to working on my own projects on an up-to-date xampp installation. I just forgot that we have an outdated dump file. I suppose that it is simply a common mistake when focusing on the code. I have found several resources on the recursive cte topic: https://dev.mysql.com/doc/refman/8.4/en/with.html https://www.mysqltutorial.org/mysql-basics/mysql-recursive-cte/ https://bobcares.com/blog/mysql-recursive-cte/ https://mariadb.com/kb/en/with/ https://mariadb.com/kb/en/recursive-common-table-expressions-overview/ https://matthewdaly.co.uk/blog/2022/12/18/two-techniques-for-handling-recursive-relationships-in-mysql/ I'm going to play with this concept to gain some experience as quickly as possible, although mastering the subject will cost some time. Very fascinating. I need to upgrade my knowledge of sql in the process of this forum. Thanks for the tip, Barry. Now please spend some time relaxing. I have to log off now as my son has an appointment with a doctor. I will be back in a few hours, then i will continue upgrading my sql skills.
-
yes, of course. I seem to have forgotten that i am using a dump. I need my coffee. LOL but it works with INTERVAL 2 WEEK. meantime, i'm reading about temporary tables, what a fascinating and useful method of retrieving data without effecting permanent storage. I'm enjoying this concept.
-
yes i see that the recursive code is working. Thank you for correcting me. At least i learned how to use aliases with JOINs. I also Thank you for educating me on this subject. hmm. the query that you designed is working but the last line of sql is returning an empty set for me. I'm using xampp with mysql mariaDB. if i replace the last line with LIMIT 20 to test that the query is working, then i get results. Something is not working with the date. Do you know why?so WHERE FROM_UNIXTIME(p.time) > CURDATE() - INTERVAL 7 DAY
-
I'm sorry that it didn't work out for you after three hours. I should've included the table structure in the file. My apologies for not properly planning. Barry, you never cease to amaze me. Your code is fantastic and you only had the structure to work with. I hope that i can get my level of sql programming to such a position as to build from table structure alone and it works. I still have trouble with advanced sql since i have neglected this language. But i am learning from you. I decided to take this JOIN concept with aliases and put it to practice. I had displayed the board index forums using basic sql but i noticed that a board structure table exists. I thought that i should be loading the forums according to the board structure, so i implemented your sql concept to arrive with the following query: select s.parentID, s.boardID, s.position, b.title, b.description, b.boardType FROM wbb1_1_board_structure s JOIN wbb1_1_board b USING (boardID); it works 🙂 i have the forums displayed in the order specified in the board structure table. More importantly, i learned from you -- pending your approval. i would like to rebuild the database because from day one i have had a difficult time looking at it. I am not a db architect and my level of sql is currently basic or entry level. However, from what i knw about db design from you and a few others at this forum, the db is not correctly designed. I also do not understand why username and userid has to exist in every table. I thought that one is supposed to relate the tables using a common field, such as id. I do not see this being implemented. But my first goal is to upgrade the php, html, css and sql to php 8, html 5 , css3 and pdo. Then i can look at the db but then i suppose that doing it this way will mean that i have to rewrite the sql parts of my current code. So i have to think about that. Once again, my dear friend, Thank You. You have helped me more than you know. I am going to keep reading sql tuorials in my free time. I need an upgrade too 🙂 Please get some rest, Barry and i hope that your Netflix binging was entertaining and satisfying.
-
Thank you. You should know that i have a text file of data that you have posted. I always appreciate the wisdom from the top talent here at phpfreaks. I have learned alot from this forum and its top members. I give credit where credit is due. I actually learned how this JOIN is working and i have successfully implemented my own query on the db last night before bed. I'll post the code in a reply to Barry. My point is that i learn from Barry and not simply take code and be on my way. I'm not looking for a free ride, only help when something is above my current level of knowledge. I hope that you have a splendid day, Gizmola.
-
Hi Gizmola, very helpful post. I've read about this topic for quite some time today and it is very fascinating to me. I should've explored sql many years ago but atleast i'm trying to catch up now. I have learned alot from Barand but i never implemented it with my own code to gain experience. I am learning alot today and your notes are also very helpful. I see how it is working now and it is quite clever 🙂 Thank you for taking time to educate me on this subject. I appreciate your expertise. I appreciate Barand's expertise always, although he may not know it. I hope that you have a pleasant evening and i'll keep experimenting with this concept to gain more experience with it.
-
I have been reading so much sql that i am getting dizzy. I need a break. I'm going to switch to the html 5 and css 3 code a bit, then i will watch a film with my wife to relax. I'm trying to convert the forum to php 8, html 5 and css 3 with better session handling and security. I hit a wall with the sql code. I just need to rebuild the posts with attachments and finish the index page, then the forum will be stabilized. I cannot believe the sloppiness of this commercial code and database implementation. Anyway, my friend is too old to battle code and i am helping him for free since i use the forum as well. Some experts are in the forum and i'd hate to see it disappear. I'm trying to rescue it from a hacking death. I can tell that sql injections are working on this forum and i believe that bots may be the reason that the site crashes with a session error. I just watched Venom Last Dance and Saturday Night movies. Very good films if you are looking for something to watch. Unless you are not a fan of Marvel or Saturday Night Live.
-
it is an alias, yes? i didn't know that we could use an alias. I only know basic sql: select what from table_name or from table_name where whatID = thisID etc. i found a cheat sheet: https://learnsql.com/blog/sql-join-cheat-sheet/joins-cheat-sheet-letter.pdf very fascinating!
-
well i have finally made a dump and sent it to you. I am still trying to find a way to instruct my brain of how i could come up with the same query that you have posted. I really need to master sql now. Not to take any more of your time but what is with the b. t. prefix. How is this working? what do i call it so that i can research it? adding b. and t. to the column seems like a reference that can be used in multiple tables. I have not seen this before...
-
Hi Gizmola, The links that you have provided are excellent resources. Thank you! I am trying today to understand Barry's code from an sql point-of-view. I really must learn this aspect of programming. I have neglected sql for far too long. Now i have a need to know it and i am struggling. I am trying to learn it but you know how that goes, i will need time to grasp all of this material. I have alot to learn. I always appreciate your insight and also Requinix and Kicken. I have learned alot from all of you. Yet i have failed to master sql. It is biting me in the behind today... Best wishes, John
-
i have a text file full of notes from Barand. at some point in my programming quest, i will need to learn sql and database design and i only want to learn from pros. Thus, i maintain notes that from posts that you have made here at freaks forum. You really are a fantastic database designer and a master of sql. I admire your knowledge of this field. I mention your name to my wife during discussions about sql. She knows who you are from my time here at freaks. She remembers the database help that you provided for my private messaging system idea for my nature website. From what i know about good db design from your notes, i find this db from the forum to be amateurish and i told my wife that if Barand had built this forum it would be clean, smart, correctly coded and much easier for me to understand. Although i need to strengthen my knowledge of complex sql commands, I am really in kindergarten with sql. regarding the posts table, i made an error: i ran the dreaded select* from posts and it is still running 40 minutes later. so now i know where the 20 years of forum life is being stored. yikes! i do not want to interrupt mysql in mid operation, so i will let the query finish. What a stupid idea of mine ...
-
You are the best sql programmer that i have seen to date. I have seen you imagine a db and a corresponding form and code both in twenty minutes or less. I would need twenty hours as my sql skills are entry level at best. I appreciate you more than you know. I will implement the code this evening. yes, there is a posts table. I can send it to you later if you wish to look at it for arguments sake. I do not recall the structure since i was trying to rebuild the index page. I was doing fine on the php, html and css side until i hit this wall. i'm not an sql programmer but surely this db could be designed better, yes? i do not think that storing last thread in its own table is correct but i would need your opinion about that since you are a master db architect. I just find this db to be a bit of a wild west scene.
-
Hi Barry, you already know that it is not my forum and not my database. I have no problems with the php revision code but this sql code is difficult for me. Here is the result of the show columns, actually a select * from each table. I changed boardID to categoryID for simplicity. I see them as categories. board; +-----------------------------+--------------------------------------------------+------+-----+-----------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------------------+--------------------------------------------------+------+-----+-----------+----------------+ | boardID | int(10) | NO | PRI | NULL | auto_increment | | parentID | int(10) | NO | | 0 | | | title | varchar(255) | NO | | | | | description | mediumtext | YES | | NULL | | | allowDescriptionHtml | tinyint(1) | NO | | 0 | | | boardType | tinyint(1) | NO | | 0 | | | image | varchar(255) | NO | | | | | imageNew | varchar(255) | NO | | | | | imageShowAsBackground | tinyint(1) | NO | | 1 | | | imageBackgroundRepeat | enum('no-repeat','repeat-y','repeat-x','repeat') | NO | | no-repeat | | | externalURL | varchar(255) | NO | | | | | time | int(10) | NO | | 0 | | | prefixes | mediumtext | YES | | NULL | | | prefixRequired | tinyint(1) | NO | | 0 | | | prefixMode | tinyint(1) | NO | | 0 | | | styleID | int(10) | NO | | 0 | | | enforceStyle | tinyint(1) | NO | | 0 | | | daysPrune | smallint(5) | NO | | 0 | | | sortField | varchar(20) | NO | | | | | sortOrder | varchar(4) | NO | | | | | postSortOrder | varchar(4) | NO | | | | | isClosed | tinyint(1) | NO | | 0 | | | countUserPosts | tinyint(1) | NO | | 1 | | | isInvisible | tinyint(1) | NO | | 0 | | | showSubBoards | tinyint(1) | NO | | 1 | | | clicks | int(10) | NO | | 0 | | | threads | int(10) | NO | | 0 | | | posts | int(10) | NO | | 0 | | | enableRating | tinyint(1) | NO | | -1 | | | threadsPerPage | smallint(5) | NO | | 0 | | | postsPerPage | smallint(5) | NO | | 0 | | | searchable | tinyint(1) | NO | | 1 | | | searchableForSimilarThreads | tinyint(1) | NO | | 1 | | | ignorable | tinyint(1) | NO | | 1 | | | enableMarkingAsDone | tinyint(1) | NO | | 0 | | +-----------------------------+--------------------------------------------------+------+-----+-----------+----------------+ 35 rows in set (0.027 sec) last_post; +---------+------------+----------+ | boardID | languageID | threadID | +---------+------------+----------+ | 1 | 0 | 131614 | | 2 | 0 | 131699 | | 4 | 0 | 131409 | | 6 | 0 | 131448 | | 7 | 0 | 131644 | | 8 | 0 | 109430 | | 9 | 0 | 131636 | | 12 | 0 | 131447 | | 14 | 0 | 131211 | | 15 | 0 | 130124 | | 16 | 0 | 47890 | | 19 | 0 | 131610 | | 20 | 0 | 130326 | | 22 | 0 | 131693 | | 23 | 0 | 131702 | | 24 | 0 | 131705 | | 25 | 0 | 131687 | | 26 | 0 | 131683 | | 27 | 0 | 71457 | | 28 | 0 | 131566 | | 29 | 0 | 131550 | | 30 | 0 | 131462 | | 31 | 0 | 131597 | | 33 | 0 | 131670 | | 34 | 0 | 131701 | | 35 | 0 | 131048 | | 36 | 0 | 55605 | | 40 | 0 | 127001 | | 47 | 0 | 59622 | | 48 | 0 | 56781 | | 49 | 0 | 59625 | | 50 | 0 | 57619 | | 51 | 0 | 59683 | | 52 | 0 | 131695 | | 54 | 0 | 10964 | | 53 | 0 | 131441 | +---------+------------+----------+ 36 rows in set (0.020 sec) thread; +------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+----------------+ | threadID | int(10) | NO | PRI | NULL | auto_increment | | boardID | int(10) | NO | MUL | 0 | | | languageID | int(10) | NO | MUL | 0 | | | prefix | varchar(255) | NO | | | | | topic | varchar(255) | NO | | | | | firstPostID | int(10) | NO | MUL | 0 | | | firstPostPreview | text | YES | | NULL | | | time | int(10) | NO | | 0 | | | userID | int(10) | NO | MUL | 0 | | | username | varchar(255) | NO | | | | | lastPostTime | int(10) | NO | MUL | 0 | | | lastPosterID | int(10) | NO | | 0 | | | lastPoster | varchar(255) | NO | | | | | replies | mediumint(7) | NO | | 0 | | | views | mediumint(7) | NO | | 0 | | | ratings | smallint(5) | NO | | 0 | | | rating | mediumint(7) | NO | | 0 | | | attachments | smallint(5) | NO | | 0 | | | polls | smallint(5) | NO | | 0 | | | isAnnouncement | tinyint(1) | NO | | 0 | | | isSticky | tinyint(1) | NO | | 0 | | | isDisabled | tinyint(1) | NO | MUL | 0 | | | everEnabled | tinyint(1) | NO | | 1 | | | isClosed | tinyint(1) | NO | | 0 | | | isDeleted | tinyint(1) | NO | MUL | 0 | | | movedThreadID | int(10) | NO | MUL | 0 | | | movedTime | int(10) | NO | MUL | 0 | | | deleteTime | int(10) | NO | | 0 | | | deletedBy | varchar(255) | NO | | | | | deletedByID | int(10) | NO | | 0 | | | deleteReason | text | YES | | NULL | | | isDone | tinyint(1) | NO | | 0 | | +------------------+--------------+------+-----+---------+----------------+ 32 rows in set (0.039 sec) the threadID of the lastposts is how i can pull the correct data from the threads table but how can i get that without the boardID from query one? it is complicated. an sql dump is too large, the forum has 20 years of data.
-
I'm not an sql programmer, so i am unable to find a solution to a problem with my basic sql knowledge. The problem is a forum database that has three tables of interest to me. The first table is a basic select query but the two other tables require matching categoryID field from the first query. It is complicated to explain. table one has categoryID and i need to get a threadID from a lastposts table based upon the categoryID from the first query. Then i need the actual thread from a threads table based upon the threadID from the second query. For the first two tables, i could run a single select query then match the two arrays by categoryID but the only way that i know to get the columns from table 3 by categoryID is to loop over the array results from query one. But now i have an sql query in a loop. is it possible to use union or join or some other sql construct to accomplish this task, or do i need to write 50 separate select queries for the table 3 data? query one works fine: select categoryID, categoryTitle, categoryDesc, categoryType from categories; i need the threadID from the lastposts table which can be obtained by using the categoryID from the first query but i cannot use a where clause when i cannot provide the info from query one without looping over the resulting array and using each categoryID in a loop query. select threadID from lastposts where categoryID = [cannot change this value for each value from the first query] then i need to use the threadID from the second query to get the actual thread information from a threads table. select title, userID, timestamp, username from threads where threadID = (i cannot provide this info from the second query because it is variable); i guess that i need a loop over the arrays if there is not other way to get the data with changing/variable column values. i didn't write the database but i need to display the categories with the last post in each category. Any ideas?
-
0.0 empty works. see my included code and use it in xampp. if you open an anchor tag outside of php, then close the anchor tag outside of php. because apparently the user variable is undefined and the ending anchor tag is contained within illogical php code that is not executing. <?php //$undefinedVariable = '!empty'; //$user = ''; $user = 'test'; $userhref = $user ? 'href="https://www.example.com/mycp.php"': 'href="https://www.example.com/login.php"'; $usertext = $user ? $user: 'Member Login'; ?> <ul><li class="li-btn"> <a class="custom-btn custom-btn--small custom-btn--style-4" <?php if (empty($user)){ echo 'href="https://www.example.com/login.php">Member Login'; } else { echo 'href="https://www.example.com/mycp.php">'.$user; } ?> </a> </li></ul> <ul><li class="li-btn"> <a class="custom-btn custom-btn--small custom-btn--style-4" <?php echo $userhref . '>' . $usertext; ?></a> </li></ul> <ul>Also: <li class="li-btn"> <?php echo empty($undefinedVariable) ? 'empty == true': $undefinedVariable; ?> </li> </ul> start over and think about what you are trying to accomplish. for one thing, user must mean that you have a login. How are you storing user on every page within your site? is user variable based upon a form input (post)? then one has to login on every page? one would have to login on every different page because a variable is local to the current script. You should be using a session variable or reading user from a database. Show us your code for user variable.
-
try empty(), which will supress warnings if a variable does not exist: <?php <a class="custom-btn custom-btn--small custom-btn--style-4" if (empty($user)){ echo 'href="https://www.paratuberculosis.com/login.php">Member Login</a>>'; } ?> https://www.php.net/manual/en/function.empty.php it will handle '', 0, !isset and false I assume that you are using wordpress or some other pre-coded resource You should be in control of your variables, especially user-based variables.
-
well it bothers me that you think that a full uri is a problem, so i revisit your code and voila! you have output before the header, which is an error. You must use header before any output is sent. I apologize for not noticing this error beforehand. I overlooked it yesterday. So perhaps that was your problem all along. Meantime, i have to work on reading and comprehension skills. I missed that yesterday. yikes!
-
Danke schön. Sehr nett, aber: a full uri should not be a problem. <?php session_start(); if (is_int(intval($_POST["PQty1"]))) { $_SESSION["PQty1"] = $_POST["PQty1"]; } header("Location: http://localhost/p5k/form.php"); exit; ?> you could also submit to the same page: <?php session_start(); print '<html><body> <form method="POST"> <select name="PQty1"> <option value="">Please select quantity</option>'; for ($i=1;$i<=20;$i++) { print '<option value="'.$i.'">'.$i.'</option>'; } print '</select><input type="submit" value="Add"></form>'; switch ($_SERVER['REQUEST_METHOD']) { case 'POST': if (is_int(intval($_POST["PQty1"]))) { $_SESSION["PQty1"] = $_POST["PQty1"]; } if (!empty($_SESSION["PQty1"])) { print '<p>'.$_SESSION["PQty1"].'</p>'; } break; } print '</body></html>'; ?> still, the general rule for redirection is to follow the redirection with exit. Otherwise, the script will continue executing to the end of the script. Not good if you have data after the redirection, which should not be processed. If you are happy and the script is working, then i am happy for you. I hope that you have a pleasant day, John
-
well i have changed a few things in your script which irritate me but the majority of the code is unchanged. I tested your code in xampp and i do not have any issues with the session. I have to enable cookies in Firefox or the session will not function but everything is working as expected after i enable cookies. <?php session_start(); print "<html><body> <form method=POST action=Cart1.php> <select name=PQty1> <option value=>Please select quantity</option>"; for ($i=1;$i<=20;$i++) { print "<option value=$i>$i</option>"; } print "</select><input type=submit value=Add></form>"; if (!empty($_SESSION["PQty1"])) { print "<p>".$_SESSION["PQty1"]."</p>"; } print "</body></html>"; ?> <?php session_start(); if (is_int(intval($_POST["PQty1"]))) { $_SESSION["PQty1"] = $_POST["PQty1"]; } header("Location: /p5k/form.php"); exit; ?> you have to check the local storage to see if your session cookie matches that which is sent by the server.
-
form.php start tag should be <?php you are assigning user input directly to a session variable without validating the input. I recommend casting to an integer intval() and using is_int to verify a number. or die(); will cause an error. simply exit after a header redirection: header("Location: form.php"); exit; if session cookies are not being set in the browser, then you will have empty session files (the browser will continue starting a new session). Which brings you back to the suggestions posted by requinix.
-
okay but now you need to take a closer look at your code. Specifically, not equal to. if ($_SESSION["AdmKeyy"] !== "T54") { } it seems as though your sessions may not be coded properly. Requinix is a pro and will easily be able to spot any problems. Perhaps you could post a full example of your session code.
-
and hopefully you also have session_start(); before that line of code on every individual page that needs to continue the previously started session. we cannot see your code, so we are feeling around in the dark for a flashlight...
-
I do not see a reference to a book. I find the answer to be sufficient for trouble shooting. And i will add to this: https://firefox-source-docs.mozilla.org/devtools-user/ https://developer.chrome.com/docs/devtools https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/landing/ https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/Introduction/Introduction.html https://www.php.net/manual/en/book.session.php browser issues: disabling all cookies will include session cookies in certain browsers. clear your cache before testing. check php session file permissions, typical path is /var/lib/php/sessions check php.ini for PHP session path location: /etc/php.ini search for session.save_path in php.ini check PHP error logs: query a search engine for error log locations of your preferred web server. I also wonder what you mean by "Ubuntu only". So this problem doesn't happen in OpenSUSE or Linux Mint? or you mean that the problem is not with a Microsoft Windows system, rather a Linux based system like Ubuntu?