-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Unless you have code somewhere above that conditional that is doing $pageimg = $row['pageimg']; then the variable $pageimg is not the same as $row['pageimg']. That's why I asked to see how it's being defined. It seems to me like maybe you are expecting that $pageimg just magically exists because it's the name of a column in your DB table, but that's not how things work. If you don't assign a variable a value at some point, then it doesn't exist. And if it doesn't exist, then using empty() on it will always return true, which is the problem you seemed to be having.
-
Where do you define the variable $pageimg then? Why are you using two variables instead of just the row result?
-
The JS from my post only sets up the event handling for the click event. It still needs the copyToClipboard function from your original post to work.
-
You don't have the copyToClipboard function in your code.
-
It's generally better to just avoid ID's entirely. Use classes or your HTML structure to find the elements you need instead. Your HTML is hard to read being all in a single line like that, and using nl2br on a single line is fairly pointless. The code would be a lot nicer if you spaced it out and made it readable. You might then notice that you have an error in your HTML in that your copy button has two name attributes. Once that is all fixed up, you'd have something like this: echo " <div> <div class='copy-content'>".nl2br($row['info'])."</div> <br> <a href='updatecopypaste.php?id={$row['id']}'><img src='/ppreq/editbtn.jpg'></a>     <a class='leftf' href='deletecopypaste.php?id={$row['id']}'><img src='/ppreq/deletebtn.jpg'></a>     <button name='copy-button' class='unstyled-button' style='cursor:pointer'><img src='/ppreq/copybtn.jpg' border='0'></button> </div> <br><br> "; Your copy button and copy content are now wrapped in a common parent element, which will make it easier to locate one relative to the other. There are no more IDs so no more conflicts that need to be handled. The content is identified via a class and your button via a name, both of which can be duplicated. Now you need to create a single piece of JavaScript that can respond when any of the copy buttons are clicked. That JavaScript code would use the button that was clicked as an initial point of references in the document, and locate the content to be copied by looking for the element with the class copy-content contained within the same parent element as the button. window.addEventListener('DOMContentLoaded',()=>{ //Find all the copy buttons document.querySelectorAll('button[name="copy-button"]').forEach((button)=>{ //Add a click handler to each of the buttons button.addEventListener('click', (e)=>{ //Locate the copy-content element const copyContent = button.parentElement.querySelector('.copy-content'); //Do the copy copyToClipboard(copyContent); }); }); }); Example.
-
Small confusion about redirection in Linux
kicken replied to polaryeti's topic in Other Programming Languages
The redirections are part of the setup for running a command. > and < tie the STDOUT and STDIN streams to a file. This processing is handled by the shell, not the program being executed, so they are not considered part of the programs argument list. Since this is pre-execution setup work as well, the redirection happens before the program is executed, thus happen even if the program execution fails. So, given the command line: zcho It is cold today! > winter.txt The shell would Parse the line into it's components Argument list: ['zcho', 'It', 'is', 'cold', 'today!'] Redirections: STDOUT -> winter.txt Setup STDIN, STDOUT, and STDERR STDIN: tied to the shell's current STDIN stream STDOUT: tied to a new stream created by opening winter.txt for writing (with truncation) STDERR: tied to the shell's current STDERR stream. Extract the first argument and use it as the program/command name (zcho) Attempt to execute the program/command with the arguments given You can confirm the redirection happens first by running your invalid command with STDERR redirection: kicken@web1:~$ zcho It is cold today! 2> error.txt kicken@web1:~$ cat error.txt -bash: zcho: command not found The error message from the zcho command is redirected to the error.txt file rather than displayed in the terminal. -
How to count the number of rows of a table used in the query?
kicken replied to polaryeti's topic in MySQL Help
Why? It can be done in a round about and terrible way, if your version of MySQL is new enough. select * from ( select *, row_number() over (order by salary desc) as rowNumber, count(*) over () as totalRows from employee ) r where r.rowNumber = r.totalRows-3 It'd be far more efficient and easier to read just doing and ASC sort and taking the 4th row. You can't do a simple limit expression with a single query because the numbers in the limit cannot be column references. You have to instead find a creative way to count the rows then select the one you need based on that count. -
As far as I know, the standard allows for columns that are directly dependent on the group by columns to be used as well. For example, since orders.OrderId is a primary key, any other column in the orders table could be selected as well since there will only be one value for any given order id. The same would be true for customers.CustomerId and employees.EmployeeId. The way you are doing the joins would ensure there's only a single values from those tables for any given order ID, so in theory you could select any columns from those tables as well. In practice, whether a DB supports this type of analysis of the situation or not can vary. MySQL must support it to some extent. Microsoft's SQL server doesn't support it at all so you have to follow the rule of thumb describe above. I'm not sure about other DB systems. Since support varies, the safest thing to do is just follow the above rule of thumb and limit the select to your group by columns and aggregate functions.
-
querySelectorAll returns a NodeList, which does not have an addEventListener method. Assigning an event handler to a collection of elements is a jQuery thing. In plain JavaScript, you have to loop over the elements in the collection and assign the event handler to each one individually, or attach it to a common parent element. document.querySelectorAll("p").forEach((e) => { e.addEventListener('click', fn); });
-
bash -c in linux? What does it actually do?
kicken replied to polaryeti's topic in Other Programming Languages
shell_exec is an example of where such functionality is used. The function is used to run a shell command, which is done by executing the shell program with -c. So in your code something like this: shell_exec('someCmd && someOtherCmd >/dev/null'); Is translated into /bin/sh -c 'someCmd && someOtherCmd >/dev/null' and executed by the OS. Essentially, the use case is for whenever you have a command stored in a string that you want to run. It's not something you'd typically use directly in a terminal, but rather in a script or program. -
You wouldn't do the comparisons in JavaScript, you'd do it in PHP when building your UPDATE query. Select the current data from the DB, compare it with what you received, then UPDATE whatever has changed. I wondered the same thing a while back, as this is something that Doctrine ORM does. I use MS SQL Server and from what brief searching I found, it does make a difference there. If I understand correctly, SQL Server like MySQL won't re-write the same data to disk, but it does record an entry in the transaction log. As such, unnecessary writes can cause increased overhead when it comes to transaction log management / replication. That said, I've never bothered doing this and instead just updating all the fields. I believe this level of optimization isn't really necessary until you get to pretty large applications. Adding the change detection complicates your PHP code and requires more processing overhead there so it's kind of a trade-off. Adding overhead to your PHP code and lowering the load on the DB is preferred though, as it's easier to scale your application code processing than it is to scale your database server.
-
Stopwatch (server side) to see from severals clients
kicken replied to elsafraslastra's topic in PHP Coding Help
I would probably look into using WebSockets for this if possible. Have the clients connect to a WebSocket server and obtain the initial time to display. Each client handle updating the display itself using some local timing, potentially with a periodic sync. Whenever the admin pauses/starts the timer, broadcast that event + the current time to each client so they can pause/start their display and sync it. -
Yes, for example, in Thunderbird which is what I use, there is this setting: Unless that is checked, anything that requires accessing a remote server to display will not be loaded. The learn more link goes here if you're interested. Since I leave that setting off, most of the marketing emails I get end up like this: A little bit of text, lots of image placeholders / alt text. Some companies manage this better than others. Attaching images or using data: url's will allow them to show, but of course that doesn't help you with your desire to track things.
-
Did you enable remote content in your email client? Most block it by default as far as I know.
-
Current search functionality strategies
kicken replied to NotionCommotion's topic in PHP Coding Help
The extent of my searching experience is pretty much just WHERE clauses targeting specific columns, sometimes using LIKE for substring matches. Haven't really had a need for anything more complex than that yet. I was mostly just pointing out that there are dedicated search servers around and might be worth checking. Maybe they would be useful, maybe they won't, but worth checking out. As far as I understand, you would have to setup some kind of sync so if your metadata changes in your DB you update the the search index as well, so in a way you do have the data duplicated. There's a cost-benefit analysis to be made there for your needs. -
Current search functionality strategies
kicken replied to NotionCommotion's topic in PHP Coding Help
Are you trying to search the contents of the documents, or just the metadata (name, category, etc)? I've never looked into them much, but there are dedicated search servers you could look at as yet another alternative (Apache Solr being one example I've heard of). -
Does your new sub query return results for the range? If not, you'll need to left join it for you to still get a result set. Your column names also need to match. You're selecting larimarSales.totallarimar, but the sub-query defines the column as total.
-
This bit of code is very antiquated. For new development, unless you have some need to support ancient IE systems, you should either just use new XMLHttpRequest unconditionally, or preferably, use fetch(). Part of your issue is also not understanding what this means in the code I think. this refers to whatever object a function is attached to. In your onload function, this will refer to your xmlhttp object. Outside of that function, this would refer to something else, so this.responseText outside the function is not the same as this.responseText inside the function. Outside the function, you'd use xmlhttp.responseText. My suggestion is you get rid of this code, and write your code using the modern fetch() api. That would look something like this: fetch('save_pool_history.php?action=select_past').then((response)=>{ if (!response.ok){ throw new Error('Invalid Response'); } return response.text(); }).then((text)=>{ alert(text); }).catch((error)=>{ alert('Error fetching response.'); });
-
You put your join in the wrong place. You put your new join in between the an existing join's table name and it's join condition, which is not valid. You need to add your join either to the end of your query or between the existing joins (after one join's conditions, before the next join).
-
Use LEFT JOIN instead of inner join for the joints to the sub-queries. You'll get NULL for reps with no sales. You can convert that null to a 0 in the select clause if you want by using COALESCE.
-
select reps.rep_name, p41Sales.totalrum, allSales.total from reps inner join ( SELECT reps.rep_id, sum(sales.sales_totaldollars) as total FROM `sales` JOIN reps on reps.rep_id = sales.sales_repid AND reps.rep_touroperator_id = '5' AND reps.rep_active = 1 WHERE (sales.sales_date BETWEEN '2023-05-01' AND '2023-05-15') GROUP BY reps.rep_id ) allSales on allSales.rep_id=reps.rep_id inner join ( SELECT reps.rep_id, sum(salesdetails.salesdetails_pricedollars) as totalrum FROM `sales` JOIN salesdetails on salesdetails.salesdetails_salesticketnr = sales.sales_ticketnr JOIN reps on reps.rep_id = sales.sales_repid AND reps.rep_touroperator_id = '5' AND reps.rep_active = 1 WHERE (sales.sales_date BETWEEN '2023-05-01' AND '2023-05-15') AND salesdetails.salesdetails_productid = '41' GROUP BY reps.rep_name ) p41Sales on p41Sales.rep_id=reps.rep_id Your two independent queries become sub-queries that select the totals you want, grouped by rep ID. You join the results of those queries then to your reps table by the ID and output the rep details and the totals.
-
Sounds like you want to separate totals. The total sales for Product 41 The overall total sales (for all products) Is that right? If so, you'd want to make two queries that will get you each of those totals, then use them as sub-queries in a third query that lists the reps.
-
There is no sure-fire way to accomplish what you want to do. Whatever methods that do exist to try and automatically determine this are typically blocked or otherwise made useless for user privacy reasons. Many email clients for example will not load remote images by default, so your tracking pixel would not work. I think gmail takes the opposite approach and always loads the images, whether the email is read or not so it similarly provides no insight as to whether the user opened the email. You can add a tracking pixel to try and catch the few people using a client that will still load it. Otherwise the next best option is to add tracking data to all the links inside the email so if they click any of the links you will know about it. Even that type of tracking can sometimes be bypassed by clients.
-
Not me, if I try and fill in the missing tables. Since I'm not all that well versed in this area, I don't really have much insight to provide without trying to setup some more complete test db. My general advice would be to not use the views for your updates. At least, not directly. You could probably still use the view to filter, but update the target table directly. For example, this fails with the error above: update _offers o set grade=5 where level=? But this works: update a_players p join _offers o on o.pid=p.id set p.grade=5 where o.level=? Otherwise maybe someone else with more mysql & view experience will chime in.