ChenXiu
Members-
Posts
177 -
Joined
-
Last visited
Everything posted by ChenXiu
-
No, nothing is external. No internal javascript styling, the 20 css rules are all in the <head> and the javascript I use is in the bottom of the page (completely removing all scripting doesn't make things better). My CSS is error-free, my HTML is error free, and my page loads in about .05 (5/100ths) of a second. I don't see any "flash of unstyled content," rather, I see a very quick "repositioning" of things. For example a <textarea> starts to appear in the middle of the page, and then quickly scoots over as the <ul><li> appears next to it. Like wearing one brown sock and one black sock, nobody else would really notice (or really care).... but I do 😀
-
No sir. With the new query code you suggested, I will only be doing single queries. Previously I had been doing very inefficient queries -- if one table returned "null" I would run a second query to see if the second table had the product. I knew it would be too inefficient to query both tables and compare prices one by one, so I actually never did that. Now I will be able to do that. I was reading up on the "both_tables" you used in your suggested query. I wonder if that is necessary when the "where" clause involves a primary key? In other words, should "both_tables" always be used?
-
That's amazing! There's no way I would have ever come up with that! (I've been spending the day trying to read up on how to do "join," and by golly THAT'S a big rabbithole.......). QUESTION: Because I just query one fruit at a time (e.g. "....where fruit = 'grape' ) where do I put "where fruit = 'grape'" without getting the error message "fruit column is ambigous" EDIT: this appears to work: SELECT fruit , MIN(price) FROM ( SELECT fruit, price FROM fruit1 UNION ALL SELECT fruit, price FROM fruit2 ) both_tables where fruit="grape" GROUP BY fruit; Is that OKAY? Thank you!
-
Thank you. Yes, I agree. On the shared server I'm on, due to space constraints, I can't have a 3rd large table. And I have to maintain the orig 2 tables (I'm not allowed to delete one to make room). So, currently, I run 2 queries. And then I use PHP to compare the result (e.g. if only one or the other table has the desired item, and then if both have the same item, which has the best price, etc.) I'm sure there must be a much more efficient way (like a "one liner") in mySQL that I could run. Thank you.
-
Two tables list different fruits. I don't need to know which tables have which fruit. I just need to know the best price. mysql> select * from table1; +-------+-------+ | fruit | price | +-------+-------+ | grape | 5.00 | | melon | 1.00 | +-------+-------+ 2 rows in set (0.00 sec) mysql> select * from table2; +-------+-------+ | fruit | price | +-------+-------+ | lemon | 4.00 | | grape | 3.00 | +-------+-------+ 2 rows in set (0.00 sec) What would be the most efficient (fastest speed, least code) way of querying per fruit? e.g. "...where fruit = 'grape' " // $3.00 "...where fruit = 'strawberry' " // no result "...where fruit = 'lemon' " // $4.00 Thank you.
-
Submitting just on <input> from column of inputs
ChenXiu replied to ChenXiu's topic in PHP Coding Help
Nevermind. I figured it out. -
Submitting just on <input> from column of inputs
ChenXiu replied to ChenXiu's topic in PHP Coding Help
I can't make it work. I'm trying to capture the $_POST value of the specific input that I've changed. But they all get posted (they all isset = true). -
Submitting just on <input> from column of inputs
ChenXiu replied to ChenXiu's topic in PHP Coding Help
Absolutely, after I posted the question I realized that was the key piece of the puzzle ( <input type="text" name="2021-07-02ABC" value="44.99"> ). I have heard of what you are suggesting... but I've never done that before :-) This would probably be the HTML for PHP to echo out, right? echo '<input type="text" name="orderid['.$row['order_id'].'" value="'.$row['dollar_amount'].'">'; ... and then using foreach($_POST["orderid"] as $var => $val) would narrow down and limit the loop to just the "order_id" posts. Now I have to figure out how to capture the exact <input> that I changed, and insert that into mySQL. -
My PHP code for mySQL query result: echo '<input type="text" value="' . $row [ "dollar_amount" ] . '" onInput = "submit();" >'; This yields a neat HTML column of retrieved prices on my PHP page that looks kinda like this <input type="text" value="19.99" onInput="submit();"> <input type="text" value="7.55" onInput="submit();"> <input type="text" value="10.00" onInput="submit();"> <input type="text" value="4.99" onInput="submit();"> <input type="text" value="12.75" onInput="submit();"> Desired Effect: I want to change the "10.00" amount to "20.00" simply by typing and entering "20.00" where it says "10.00" and have the form submit and update that specific mySQL record. Question: What's the best way to capture that specific post variable? Problems I've Encountered: 1. The page has several inputs and submit buttons, thus all kinds of different $_POST variables exist. 2.) I could add "name = $unique_order_number" to each input field, but when I submit the form, I still have to have PHP loop through everything. 3.) I could add "name" and have it match "value" (e.g. <input name="$row['dollar_amount']" value="$row['dollar_amount']") It seems the only way to do this is to have PHP loop through EVERY post variable every time anything is posted and this seems inefficient. Example: (to make this inefficient example work, I would have to append "updatedollar" to the name, like "updatedollar".$row[dollar_amount'] ) foreach($_POST as $var = $val) { // loop through all the posts on the page if(substr($var,0,12) == 'updatedollar') { // make sure it's an "updatedollar" post and not one of the other posts on the page. if(substr($var,12) != $val) { // get rid of "updatedollar" part and see if it's the value I wanted changed // do a mysql update query and update the table } } } So, there has to be a better way? Thank you.
-
Certain "CSS-heavy" page that loads weird: when they load, I can see movement, jostling and repositioning taking place until a "homeostasis" occurs. It feels as if there is some conflicting CSS that the browser "eventually figures out." My CSS has no errors. However I'm sure some things can be done better. Other than a.) Spending the next year and a half learning CSS from the ground up, or b.) hiring a CSS Master to review my pages, is there on online tool that can help? Or even something built into Firefox/Chrome Developer tools that can help? The internet searches I have done on this topic only point to "CSS minifiers" and "CSS error detectors" ... but I have no errors, and minification has no effect on what I've described. Thank you.
-
haha -- I'll resign THEM if they want my pages pink and lime green :-) Thank you, your point is well taken. Even when making the most minor change, so much time is wasted scrolling up to, and searching for, the CSS rule in my <head><style>, and then returning back to the code portion... and then having to do that for every page. Having just ONE page of CSS rules, and then just using PHP "require" would speed things up by not having to make individual page changes. Regarding browser caching... I wonder if you jump from a 50 CSS rule page, to a 20 CSS rule page, and then from there to a 50 CSS rule page if that slows things down. (I'm going to guess browsers don't cache individual rules.)
-
Because my CSS files are small, they are located in the <head> of my pages (not linked as a stylesheet). Best Practices Question: Should each page have ONLY the CSS rules necessary for that page? -or- Should the exact same <head><style>css rules</style></head> be duplicated across every page (even when some of the pages don't need all the rules)? Simplistic example: page1.html has four elements: paragraph, table, button, and a footer. page2.html only has two elements: paragraph and a footer (but no table and no button). Should both page1.html and page2.html have CSS rules for all four elements (paragraph, table, button, and footer)? Or should page2.html omit the two CSS rules it doesn't need? I would think it's best to be conservative and ONLY include CSS rules necessary for the page. But I wonder if browser caching improves when you "keep things the same" across your pages. Thank you.
-
I would think something this simple would work: <span style="border: 2px solid black;"> <input type="checkbox"> <span style="vertical-align: middle; position: relative;">Not Vertically Centered</span> </span> I know I can acheive the desired effect with "flex," "display:table-cell," etc., however I am questioning the aforementioned code. Questions: 1.) Why doesn't this work? 2.) What is needed to make this work? 3.) Why is CSS always like this for me? Thank you.
-
Dear Mr./Mrs. Jodunno, just a kind word of advice, if I may. This PHP forum has a small handful of VERY top-level experts. Barand is one of those experts. In my opinion, it would behoove you to not display the rudeness you displayed, especially to Barand. Be disciplined, and hold this type of words to yourself. On a positive note, you did say something 100% correct: the part where you said "...someone is out of place challenging you." Yes, you are definitely out of place. Because you did not even correctly 'challenge' Barand. He did NOT say "modulus was invented".... what he said was the modulo operator was invented for situations like this. And it was. And Barand is right. Again, these are just kind words of advice. I, too have been very frustrated with some of the answers... but I know it is in my best interest to practice discipline (you know, the "bite your tongue" expression?). Further, on several occasions, the answer that frustrates the most, sometimes ends up being the correct answer as I continue to evolve and develop my PHP skills. Peace.
-
@Requinix, thank you. I tried your suggestion using Ajax and it works great. And thank you for the suggestion to disable the submit button to prevent additional submissions, I had not thought about that. Then, I tried the basic "dim the page, and show spinner" (where clicking the submit button "onClick" changes a dark-full-page-with-spinner from "display:none;" to "display:block;"). The Ajax method looks better for pages that take a really long time to load. The javascript display/show method "feels" better for faster-loading pages. I ended up going with the the first part of your reply ("...it'll probably be easier if you don't use a new page"). In my case where the 3rd party Shipping Label Generating Service takes exactly 3 seconds, implementing the easier "display:none / display:block" style looked best. Oddly, it changed my perception of time -- it made the 3 Seconds "feel" like only a half second. Weird. (Maybe that circle spinner causes a temporary hypnosis 😀 ) Thank you.
- 2 replies
-
- swirly crap
- loaders
-
(and 1 more)
Tagged with:
-
Olden days: 1.) Visitor fills out form 2.) Visitor clicks submit button 3.) Page looks stalled forever while php/cURL script retrievs shipping label from slow 3rd party server. 4.) While waiting, Visitor ponders how they hate slow websites and then unplugs computer. Today (year 2021) 1.) Visitor fills out form 2.) Visitor clicks submit button 3.) Then what? What are the "best practices" implemented now? ...... Based on today's self-study, it appears this is a good technique: • Visitor clicks submit button. • Skeleton page appears that says "Thank you please wait while your shipping label is loaded" • Shipping label appears • Visitor ponders "What a neat fast website." I'm thinking I could do it like this: #1.) I turn that "final page" (that slow one that uses cURL to retrieve shipping label) into an Ajax target. #2.) When the visitor clicks submit button, they immediately see my skeleton page (which actually targets the Ajax target) #3.) Shipping label magically appears. Am I on the right track? Or, at my skill level (a " . 5 " on a scale of 1 to 10) would I be better off to leave things as they are, but simply add an animation overlay while the cURL script runs? As I'm typing out this question.... it appears the actual issue is the default behavior: $_POST pages stay there until all scripts finish running, then the final page loads. I am trying to provide the appearance of a "final page" immediately loading before the scripts finish running.....
- 2 replies
-
- swirly crap
- loaders
-
(and 1 more)
Tagged with:
-
@requinix, thank you, that sounds the simplest. Also, your response made me further investigate the difference between padding and margin. I'll definitely go with margin (for housekeeping reasons, I'll set html to margin:0 padding:0 also). @Strider64, I was learning about those a few days ago, I don't think I'm "at that knowledge level" to implement those yet. But thank you for the suggestion. @Barand, thank you for pointing that out. I didn't even think of that. After I read your response, I stuck this into my stylesheet to tide me over: @media all and (max-width:600px) { html, body { margin:0;padding:0;text-align:center; } } ... however, this "fix to tide me over" seems to work and look really well. So maybe that's okay At one point, I tried making everything "responsive" using "vw" and various "stretchy" css, but it crossed the line between "this is how I want my website to look" and "let's please everybody in the world." ALSO IF ANYBODY WANTS TO COMMENT ON THIS: I am finding CSS annoying sometimes. For example if I want to vertically center 3 items in a row and maybe have 2 of those items grouped together on the right, I have to implement an absolutely RIDICULOUS TANGLED mess of nested upon nested divs, floats, or flexes, blah blah blah, when all I need is a good ol' fashioned <table><tr><td>. I'd like to go "PURE CSS" but I can't bring myself to replace some of the simple <table> code with 100 lines of CSS code. You should see the crazy hour-long youtube tutorials how to spend days making 2 damn items line up side by side when all you need is a <td valign="center"> that still works on all browsers 😀 I'm open to anyone yelling at me for this. I'm easily persuaded by the experts here :-)
-
I always want 100px from left and right, no matter how much the browser is resized. I currently have: html { padding-left: 100px; padding-right: 100px; }Is this the best way? Is this the best way? Comments: 1.) Putting it in "body{" works the same. 2.) Using "margin-left: 100px; margin-right:100px;" works the same. 3.) Setting body and html to margin:0; padding:0; and putting 1 big div in the body with 100px padding/margin works the same. With so many ways, what is the "accepted Best Practices" way of doing this? My html pages are super simple: just 4 rows! 1st row: header links. 2nd row: big logo. 3rd row: big paragraph. 4th row: footer links. Thank you.
-
Table consists of the past 1000 dates. To put an id tag in the first table row on-or-after July 1, 2020, I have to use 2 mySQL queries. There has to be a more efficent way of doing the following: $search = $db->query( "select datetime from myTable where datetime > last_day('2020-06-01') order by datetime asc limit 1" )->fetch_assoc(); if (isset($search)) { $tag = $search["datetime"]; $mainQuery = $db->query("SELECT datetime FROM myTable order by datetime desc"); if (isset($mainQuery)) { while($row = $mainQuery->fetch_assoc()) { if($row["datetime"] == $tag) { echo '<tr><td id="tag">' . $row["datetime"] . '</td></tr>'; } else { echo '<tr><td>' . $row["datetime"] . '</td></tr>'."\n"; } } } } Thank you.
-
I know. But I don't know how to do that, other than with a bunch of complicated string manipulation: $query = "SELECT datetime FROM myTable order by datetime desc;"; $result = mysqli_query($db,$query); if($result->num_rows == 0) { echo 'No Data Found'; } else { while($row = mysqli_fetch_array($result)) { // The tagged row should be: 2020-07-18 09:23:53 // Therefore, "anything after 2020-06-30 ***" echo '<tr><td>'.$row["datetime"].'</td></tr>'; } All I know how to do is convoluted "if (substr($row["datetime"]......." manipulations. It is a mess. There must be a mysql trick. Or a complicated extra mysql query like $queries = "SELECT * FROM datetime where datetime between '2020-07-01' and last_day('2020-07-01') order by datetime asc"; And use substr to capture the first row And the use an "if next row == captured aforementioned substr, then tag the row" Any thoughts? Thank you.
-
Displaying date records in an HTML table from a "select datetime" mySQL query makes a HUGE page. <tr><td>2021-08-15 07:12:03</td></tr> <tr><td>2021-11-09 14:38:06</td></tr> <tr><td>2020-12-10 13:37:35</td></tr> <tr><td>2020-10-29 14:52:45</td></tr> <tr><td>2020-11-21 01:56:32</td></tr> <tr><td>2020-07-18 09:23:53</td></tr> // I would use <tr><td id="tagged">2020-07-18 09:23:53</td></tr> <tr><td>2020-05-15 08:09:35</td></tr> <tr><td>2020-04-07 12:17:05</td></tr> | (thousand more lines) Jump to desired month? When page loads, I can use a <select> input and a "<body onLoad...scrollIntoView>" javascript to "jump" down to a date range. For example, if I want the page to jump to "records starting with July 2020," I would want to jump to the "2020-07-18" line above. When using while($row = mysqli_fetch_array($result)), Is there an easy/efficient way for mySQL to "tag" the row where July 2020 starts? Thank you.
-
Which is better? if(!isset($_SESSION['user'])) { exit; } if($_SESSION['user'] !== 'SiteOwner') { exit; } - or - if(!isset($_SESSION['user'])) { exit; } else { if($_SESSION['user'] !== 'SiteOwner') { exit; } } Is the "if else" version more secure? Basically, if nobody's logged in, exit immediately. But if somebody's logged in, make extra sure it's the Site Owner. p.s. I know that " if( !isset($_SESSION['user'] || ($_SESSION['user'] !== 'SiteOwner')) { exit; } " works, but I want to keep the code flexible for adding other types of users in the future. Thank you.
-
Thank you, I appreciate your answer. For fun, I made it so each post turned into a get using $_SESSION["post"] = $_POST, and then $_POST = $_SESSION["post"], and indeed I could "go back" but it was disconcerting how every page was basically a redirect. I decided to let it be like it is. If the visitor feels like they have to hit the back button, it really means I need to do a better job with placement, positioning, etc., to keep visitor moving forward.
- 3 replies
-
- prg
- post redirect get
-
(and 1 more)
Tagged with:
-
Thank you very much for your answer. I think for the first time I'm "getting it." For me, Permissions have always been like chess, string theory, and religion: lots of trial and error.... and faith. Now, not only do I know what the typical permissions should be (750), I'm also "getting" what the r, w, and x mean. Thank you!! p.s. While I'm now finally getting it, I'm having fun lowering my permissions notch by notch... until something fails. Like having a window open just enough to let fresh air in, but not let rain in.
- 3 replies
-
- permissions
- write and execute
-
(and 1 more)
Tagged with:
-
PHP is owner of image directory with "permissions 660." Why can't PHP write to it? (a "permission denied" error is generated.) But if I allow execute permission ("760") then it works. Why?? My script is: $imagePath = '../imageDirectory/'.gif'; $image = imagecreatefromstring(base64_decode($raw_image_data)); $rotate = imagerotate($image,-90,0); imagegif($rotate,'../imageDirectory/'.gif'); Is it because the imagerotate and imagegif functions need the execute requirements to be able to monkey with the image? Thank you. Sub question (maybe more important than the first question): PHP is configured to run as "user = www-data" and "group = www-data" I am also a member of the group "www-data." For me to be able to read and delete files in that aforementioned imageDirectory, should the imageDirectory be chown www-data:www-data ?? or chown myself:www-data ?? (both styles work) Thank you.
- 3 replies
-
- permissions
- write and execute
-
(and 1 more)
Tagged with: