-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
I really didn't expect this kind of trouble for anyone. Just thought I was missing something simple. As for test data, the sample of my 'problem' should be sufficient if you add a 2nd row to each drillatt with a new drill_no value, ie, 2 drill nos having the same date in the drills table and 2 attendance records for each roster with different drill nos. Sleep well!
-
Here are the structures. If that is not sufficient, please don't make that extra effort. I completely understand. I just was hoping that someone like you knew something that I didn't. MMS_Drills Drill_no, Drill_date, Description MMS_Drillatt Drill_no, Roster_no The tables represent my firehouse drill records - 1 per drill and the attendance to each drill, multiple naturally. What is happening is recently we now have 2 drills per night where people are supposed to sign for one or the other, but not both. I'm trying to search for those bad instances where they do sign both. So I'm querying for counts of guys who sign 2 drills with the same date. Does this help?
-
There is quite a bit of data on file, so I kinda can't. Is there something specific you are interested in, or just the total structure. I can understand if you want to pursue it deeper. As I said though - the query is correct. I just want to clean it up via query, rather than using php, if that is possible.
-
That is exactly what is happening. And you are saying that I have to eliminate the dupes programmatically?
-
Need a little help with this query. A bit complex and definitely at the limit of my abilities since I don't write that many queries that often and not usually this tricky. Here's the query with the output from it next: SELECT d.Drill_date, q.Roster_no, q.drills FROM MMS_Drills d LEFT OUTER JOIN ( select a.Roster_no, t.Drill_date, count(a.Drill_no) as drills FROM MMS_Drillatt a, MMS_Drills t WHERE a.Drill_no = t.Drill_no and YEAR(t.Drill_date) = '2022' AND t.Description Not Like '%National%' GROUP BY a.Roster_no, t.Drill_date ) q ON q.Drill_date = d.Drill_date WHERE YEAR(d.Drill_date) = '2022' AND d.Description Not Like '%National%' AND q.drills > 1 ORDER BY Drills DESC, d.Drill_date, q.Roster_no Output: (wouldn't post into a 'code' box) Drill_date Roster_no drills 2022-04-26 175 2 2022-04-26 175 2 2022-04-26 220 2 2022-04-26 220 2 What I would like to do is eliminate these duplicate rows. The data is accurate, just my output is more than I want. Any ideas? I realize that this is perhaps too much to solve without knowing more but perhaps there is a simple solution that a more experienced query writer knows.
-
Very clever. Didnt' think that far along. @Suraj - scratch my idea!
-
Suggestion. When a user logs in successfully post a record of it in a separate table, say 'active_users'. Then when they try and login again, check if they are already active (in that table), and if so, delete them and continue on to the normal login process. Your 'active_users' table may need a datetime value in it that allows for a record to expire and be automatically cleaned up by a separate process, perhaps a cron job that runs once a day or something.
-
You apparently do not communicate at the same level as most IT professionals, whom you are dealing with here. What is being said is to not only clarify what you are doing incorrectly but also the background as to why you need to change the things you are doing. I have read some pretty detailed explanations on this topic from very talented and extremely dedicated Pros about what you need to do but apparently you are not ready to get into this business that deeply. Your responses tell me that you do not understand this business. That's not a condescending answer but simply the assumption that I (and perhaps others) are getting from your repeatedly abusive responses. You have chosen a topic that is very complex for many long-time users of PHP and you are simply not ready for that it seems. Despite the attempts from a couple of our best and brightest to involve you and educate you you insist on being hurtful and dismissive of the time and effort that has been put into trying to help you. Good luck.
-
OK - if you are worried about multiple users creating and removing the same filename why not use a random filename that only exists for that particular instance of the script? That way if there is more than one executing at the same time they won't interfere with each other when it comes to that filename usage.
-
You control that by doing checking of the events you are trying to prevent from happening I suppose. What is it in your 'long-running' script that you don't want interference from another instance to occur? And just what is it that could be so long-running that 2 scripts would actually meet up at?
-
And the question is why? Why do you need to post the same file at the same time? What are you really testing? I imagine also that the OS will run into a lock situation if you try and write the same file at the same time. This seems like a fruitless exercise unless you can give us some idea what your goal is.
-
The way to show an image that is 'clickable' is to write an anchor tab (<a>) that uses an img tag in place of the ordinary text that you might use for an anchor. Use php code just the same way you would use text. $img_name = '/folder/image1.jpg'; echo "<a href='mypath/script.php'><img src='$img_name'></a>"; (My syntax may not be perfect but you should get the idea)
-
Is there a better way to avoid the duplicate code
ginerjm replied to beginnerForPHP's topic in PHP Coding Help
Glad it makes sense to you Requinix. I don't even recognize the code. -
All I see is you are trying to save a bit of text as a file. What I don't understand is the clearstatcache and the sleep(20). So what is NOT happening - the file is not created? How about turning on error checking and see if you get anything?
-
Me neither. I think it might have something to do with large projects that involve many scripts and many variables and I'm thinking namespace is a way of avoiding collisions with names.
-
Because I saw the binds I didn't even notice that he was using PDO. Surprised!! Yes - you are right. The array method is so much easier and using a list to capture the query results is even easier than the bind.
-
Did you check if you got a row from your query? Do you have error checking enabled? // Attempt Log In $submit = $_POST[ 'submit' ]; if ( $submit == 'Log In' ) { $username = $_POST[ 'username' ]; $password = sha1( $_POST[ 'password' ] ); // echo "Your username is ".$username.' and your password is '.$password; $sql = $dbh->prepare( "select username from fr_admin where username = ? and password = ?" ); $sql->bindValue( 1, $username, PDO::PARAM_STR ); $sql->bindValue( 2, $password, PDO::PARAM_STR ); IF (!$sql->execute()) { print_r($sql->errorInfo()); EXIT(); } // execute ran. // did we get a row back? if ($sqlresults = $sql->fetch()) { $uname = $sqlresults[ 'username' ]; if ($uname == $username) // WHY THIS TEST??? YOU JUST ASSIGNED THE VALUE SO IT HAS TO BE == { $_SESSION[ 'admin' ] = 'authorized'; $_SESSION[ 'username' ] = $username; } else { echo '<p class="text-danger"><strong>There was a problem logging in. Please try again!</strong></p>'; } } This is the only part I think that we are interested in...
-
Still discussing this when what I gave you days ago solved all of your problems? A single script that displayed the blank form, validated the data and processed it without using JS if you didn't want to.
-
Ok - this code says to show the field-container div if your field is not empty. And to show the 4 other divs if it is empty. Plus you have an extra </div> tag in the else part that is not necessary. PS - not a good idea to use the dash character in names, just use the underscore. As for adding things, of course you can. Just code them.
-
Show me your new code . And what are the "two divs"? One choice is outputting a single incomplete div and the other is outputting 5 divs.
-
So change the if to match what output you want. If plafrorm2 is empty (ie, == '') and you want to only show the one div then make it so. If it is the other way change the if to <> '' More importantly note how I altered your output style. Entering and leaving php mode to do output is such a tedious method of coding when you can avoid it by STAYING in php mode and using the echo. Or by reading up on php's "heredocs" command that makes it much easier to output html and non-php code as well as php code.
-
So now that the 3 of us readers have shown 3 interpretations of the 'problem', we need to see what the OP can do to clear up our thoughts.
-
This is how the code could look: if($game['platform2'] ==" ") echo "<div class='field-container'>"; else echo "<div class='field-container'> <div class='title'>Platform</div> <div class='information'>{$game['platform2']}</div> <div class='title'>Launcher</div> <div class='information'>{$game['launcher2']}</div> </div> "; Problem is - you say you want to check if 'platform2' has text in it but you are testing if it has a space in it. Perhaps you want to check if it is not equal to '' ?
-
@mac_gyver - that was not the question he asked. Or at least I didn't read it into this topic. The original post showed data items which I took to mean they were existent records that just didn't have that 'word' value from the where clause.
-
Why would you NOT want it in a database table? Having it in code means the user has to have access to your code in order to make changes. Having it in a db means you would only have to have an authorized user who can make necessary improvements getting at the values. Modifying code or modifying data? The better choice is always data until you begin talking about algorithmic changes.