-
Posts
2,134 -
Joined
-
Last visited
-
Days Won
42
Posts posted by benanamen
-
-
Your query is failing. You are using single quotes so the variables are not being interpolated. You should be using Prepared Statements anyways. NEVER EVER put variables in the query and don't create variables for nothing. There is no need to manually close the connection. Php will do it automatically.
I would also recommend you use PDO. Here is a tutorial to get you going.
-
Correct me if I am wrong, but you want to use the value of $id by using a completely different variable named $customerID?
-
Based on your post on the other forum, you should take the time to learn the basics of Laravel. I would suggest you check out the Laracast video tutorials. The third party app you are trying to modify is using a very old version of Laravel.
-
OP was already advised about his code on another forum and did not implement any of the advice whatsoever. His response was "Could you please write it to me".
OP, we are not a coding on demand service. You apparently didn't even attempt to copy and paste the complete working example from the tutorial you were referred to. If you just want someone to write it for you then post a job offer on any of the forums jobs section.
-
WHERE `district`= {$_SESSION['g_district']} ");
-
There is no such thing as a "from" tag.
- 1
-
3 hours ago, purge08 said:
Can you please provide the default sql so we can run the code.
-
OP, do you seriously think we can do something with PICTURES of CUTOFF CODE?
-
58 minutes ago, mactron said:
I'm just trying to prevent duplicated entries this way.
That is not the way to handle it.
- Set a unique constraint on the DB column(s)
- Attempt the insert and catch the duplicate error if any.
- 1
-
OMG! I could care less about your code dude! I was just trying to help you. Good luck getting assistance with that attitude.
-
Hi @NotionCommotion, long time no chat.
This is all interesting stuff. I was just wondering, are you actually having a problem to where this matters or is this just for learning?
-
Tell you what, if you can provide a zip of your files I will review it and tell you what is wrong.
-
1 minute ago, SaranacLake said:
I am just interested right now in refactoring this particular problem
In that case, just remove the session start from your include files. You should have no need to check if a session has been started.
-
1 minute ago, SaranacLake said:
Thanks, but no. I am looking to fix how I currently sue sessions, not re-architect my site.
I'm sorry, I assumed you wanted to learn how to do things better. My bad.
-
4 minutes ago, SaranacLake said:
maybe you have an even better approach?
The better approach is to have a single point of entry to the site/application. Then as mentioned, you set the session once in the main file.
Here is a free video series tutorial on Php by the Laravel Laracast guy. Even I, after more than 30 years of programming learned several new things.
-
-
19 minutes ago, Jim R said:
Can't I query it out and sort it on the backend rather than creating all that extra data input?
Sure you could but you are going to need code gymnastics to cover every possible case. Not really optimum IMO. The "extra data input" is a one time insert and you are done with it. At that point, it is as simple as selecting the column in your query.
-
Based on the site link I would say what you are looking for is a "short name" for the schools. I would add a column to the DB to hold that data. So you have columns city, school_full_name, school_short_name
-
14 minutes ago, Jim R said:
Yes it does matters. It matters to my Users, and it matters to those who want to see their school represented as the school is named. It matters to me.
That makes no sense at all. If you are displaying the data from the school name column why would it not be what the school is named?
-
4 minutes ago, Jim R said:
In cities where the school is just the name of the city, city is NULL.
IMO, you are just creating a problem mixing data. It doesn't matter if the school name is the same as the city. A city is a city, a school is a school.
- 1
-
Thanks for letting us know.
-
1 hour ago, Psycho said:
Factorials of negative numbers is not possible
Thanks @Psycho. Shows how much I knew about Factorials, lol.
-
7 hours ago, requinix said:
Your brain needs to stop working on this and do something else.
This is a real thing how the brain works. It has to do with how the prefrontal cortex works. I have solved many a problem by not trying to solve the problem and stepping away from it. Without trying, you get that A-ha moment and the answer comes to you.
-
A function also known as a method when in a Class should do one thing and do it well. It should also be easily re-usable and not have to be edited to use it elsewhere. What you have is none of that.
What you will probably discover as the first problem is that you have hard coded the groups which means if you want a group other than uk you now have a problem on your hands. Duplicating the function for every group is not the answer. What you want to do is pass the groups value to the function as a parameter. Now you can use the same function for any group. Same thing goes for the hard-coded table name. There is also no option to specify specific columns. Again you would run into problems with the hard coded column headers and every other hard coded item.
Here is something you get you going towards a dynamic solution. (It's not a cut n paste solution)
<?php declare(strict_types=1); $sql = 'YOUR-QUERY-HERE'; $stmt = $db->pdoQuery($sql); $row = $stmt->fetch(PDO::FETCH_ASSOC); if (!$row) { echo '<H1>No Records Available</H1>'; } else { $data = []; foreach ($row as $key => $val) { $data[ucwords(str_replace('_', ' ', $key))] = $val; } ?> <div class="table-responsive"> <table id="myDataTable" class="table table-bordered table-striped table-hover table-sm"> <thead class="thead-dark"> <tr> <th><?= join('</th><th>', array_keys($data)) . "</th>\n" ?> </tr> </thead> <tbody class="searchable"> <?php do { echo "<tr>\n<td>" . join("</td>\n<td>", $row) . "</td>\n"; echo " </tr> \n"; } while ($row = $stmt->fetch(PDO::FETCH_ASSOC)); ?> </tbody> </table> </div> <?php }
mysqli_connect - what am I doing wrong
in PHP Coding Help
Posted · Edited by benanamen
Take the quotes off the constant connection parameters in the connect string. It is also standard practice to use all UPPERCASE for constants.