Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Everything posted by ginerjm

  1. If pdo is THAT complicated for you to switch to then simply write your mysqli way of doing something and we can easily show how it needs to look. That's what we are here for. Of course if you just went to the php manual you would see examples of how to use pdo. And once you do that you will see how much simple pdo is as opposed to all of the other functions that mysqli uses. When mysql was deprecated and removed I made the highly-suggested move to PDO and am so glad I didn't make the easier switch to mysqli.
  2. Is this a repeatable task or a one-time exercise? If it is the latter why not just use Windows or FileZilla?
  3. This took me some time but here is what I wrote: $weekdays = "Saturday, Closed;Sunday, Closed;Monday, 9AM to 12PM, 1 to5:30PM;Tuesday,9AM to 12PM, 1 to 5:30PM;Wednesday, 9AM to 12PM, 1 to 5:30PM;Thursday, 9AM to 12PM, 1 to 5:30PM;Friday, 9AM to 12PM, 1 to 5:30PM"; $days = explode(";", $weekdays); echo "Days are<pre>",print_r($days,true),"</pre>"; foreach ($days as $day) $parts[] = explode(",", $day); // now output as Monday 9:00,12:00,13:00,17:30|T $time_str = ''; foreach ($parts as $day) { $str = trim($day[0]) . " "; for( $i=1; $i< count($day); $i++) { $d = trim($day[$i]); if ($d == 'Closed') $str .= " Closed"; else { $times = explode('to',$day[$i]); foreach($times as $t) { $t = trim($t); If(!$time_val = date('G:i',strtotime($t))) { echo __LINE__. "Could not convert $t to date<br>"; exit(); } $str .= $time_val . ","; } } } $time_str .= rtrim($str," ,\t") . '|'; } echo "Result is <br>$time_str<br>"; And here is what it produces: Days are Array ( [0] => Saturday, Closed [1] => Sunday, Closed [2] => Monday, 9AM to 12PM, 1 to5:30PM [3] => Tuesday,9AM to 12PM, 1 to 5:30PM [4] => Wednesday, 9AM to 12PM, 1 to 5:30PM [5] => Thursday, 9AM to 12PM, 1 to 5:30PM [6] => Friday, 9AM to 12PM, 1 to 5:30PM ) Result is Saturday Closed|Sunday Closed|Monday 9:00,12:00,19:00,17:30|Tuesday 9:00,12:00,19:00,17:30|Wednesday 9:00,12:00,19:00,17:30|Thursday 9:00,12:00,19:00,17:30|Friday 9:00,12:00,19:00,17:30| You have a data issue where you don't specify a recognizable time value for the 1 o'clock start times.
  4. My critique of your code: - you have a function with an incoming argument but you don't even look at what it may be. You simply load it up with a string that follows no pattern. - then you work on a var named $atts which is supposed to be an array. But where is this defined? It's not available in your function - you have a series of similar looking lines of code following the bad reference to $atts but only one of them will be executed even if you define that $atts var somehow. Read up on how the if statement is used. - You are then trying to reference $weekdays as if it were an array. It's not. It is a string. The rest of the code is useless until you fix what I have gone over. And just why is this input string/data arranged like that? Are you producing this or are you getting it from somewhere that you have no control over? Either way your work would be much easier if you rearranged the input data.
  5. I"m not seeing the original source text that you want to work on.....
  6. Start with a check of the user's position. Set a value. Then when you output your html code check that value before you output each value that you want to control. Simple as that.
  7. YOu are making the same errors we just tried to educate you on NOT doing.
  8. The first code was wrong. What I & Barand gave you corrected it. Can we see the new line you are using?
  9. You didn't use the code that I gave you. Do you not understand the use of quotes in strings with php vars? Barand just gave you the same string that I wrote. Are you going to massacre his as well?
  10. echo "<br><div id='$index' class='mydiv'>";
  11. Nice pickup on that double id considering how it was written. Plus it references a class yet includes a lot of css that could be better included in the class definition. And since we're picking up on duplicate things, how about the duplicate background color settings? Ps - note that the break up of the line of code to include the "index" variable is really not necessary. You are starting the string with a double quote so the id only needs to reference the value in single quotes without breaking the string.
  12. Way too complicated. I tried to rewrite this but got lost in your logic and your very convoluted coding methods. Resolve your input issues before creating your html code. Get the values you want to use by returning it from the function and then use that value in your html so that you don't have to use a php tag in the middle of your html. Very bad coding IMHO. And I strongly recommend using heredocs; Here is an example of how it works for you: $sel1 = $sel2 = ''; $value1 = get_value(???); if ($value1 == $state1) $sel1 = "selected='selected'"; $value2 = get_value(???); $dropdown=<<<heredocs <select name='list'> <option value=''>Select a State</option> <option value='$value1' $sel1>$value1</option> <option value='$value2' $sel2>$value2</option> </select> heredocs; Now use the $dropdown var in your html output area. You can see how I avoided leaving php mode and let the heredocs combine the assigned values with the html. Not sure my code makes sense (as your code was confusing me too) but this shows you a cleaner way of coding. If I read it correctly you have some session values that are to default your desired values when they are not in the POST'ed input. You do know that POST values from text inputs are always set so you don't have to do an isset on those parts. They may be blank but at least they are present as blanks.
  13. Here is a cleaner looking copy of your code. if($_SERVER['REQUAST_METHOD']=='POST') { include 'connect.php'; $sql = "SELECT * FROM users where email='$email' and password='$password'"; $result = mysqli_query($sql); if($result) { $num = mysqli_num_rows($con,$result); if($num > 0) echo "login successful"; else echo "invaild"; } Now if you just clean up your spelling it just may work.
  14. How do you think I feel? I haven't had to use my site since Covid and now I am and finding a whole bunch of errors that I have to fix to be able to run the app. Including some plain old JS xmlhttrequest that don't work anymore. I don't even remember why I have them!
  15. You do not have access to the individual users sessions. You can't remove them. Over time each session will go away.
  16. YOu still haven't told us what the logout button does to make them be logged out. Is there some other table that tracks each 'session' that? Could that be what the logout button updates?
  17. When you click the logout button what changes on these records you have showed us? You are not telling us the difference between "looking offline" and being logged out.
  18. So - WHAT makes them look "logged out"? The absence of their record? Or some setting that you are not telling us about? It's really very simple so I don't know what the problem is.
  19. How will you know who was in the latest session that needs to be logged out? Is that not stored somewhere?
  20. Then instead of a delete query you do an update query. Doh.
  21. If you have a table of the ids I would use that to get all of them and then do the logging out with just one query execution that uses that array of ids. Delete from my_table_name where table_id in ("key1","key2","key3"........)
  22. What is the second line above supposed to be doing for you? It is not a usable statement. If you had error checking enabled you would probably get a message. Add this to the start of your script, right after the session_start: error_reporting(E_ALL); ini_set('display_errors', '1');
  23. I would like to see the code that the OP has already tried. Otherwise we are just being asked to do his/her thinking for him...
  24. Take care and be well. And I hope you can get yourself into a "programmer's state of mind" once again.
×
×
  • 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.