-
Posts
3,372 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Muddy_Funster
-
Nested Json to PHP Array for csv export
Muddy_Funster replied to reldridge's topic in PHP Coding Help
Hi and Welcome to PHPFreaks. Could you paste up the results of var_dump($json_obj['items'][0]['items']); so we can see what's in there? -
if you stop using SELECT * you will be able to choose the output names for the columns. nonsense example: SELECT s.col1 AS state_name, s.col2 AS sColumn2, c.col1 AS county_name FROM state s INNER JOIN county c ... even though the DB has a column called col1 in both tables once the query is processed then you will have the aliased names to work with in the PHP array ... echo "State ---> {$row['state_name']} "; echo "County ->{$row['county_name']}"; ...
-
As said, you should be using prepared statments. Not only does it mitigate the escaping issue but dropping raw $_POST values into an SQL query is a mahoosive security hole.
-
Almost - you did part of it, but you didn't sort out the joins. You're also joining the same users table twice, by giving it two aliases, even though you are only taking a single column from it. That's the most likely reason for the issue, which is far more apparent now that you cave the column list that you are selecting. SELECT DISTINCT sRank.rank_title, sPro.pf_fleetposition, sPro.pf_usergamesplayed, sUser.username FROM sv1users AS sUser INNER JOIN sv1profile_fields_data AS sPro ON (sUser.user_id = sPro.user_id) INNER JOIN sv1ranks AS sRank ON (sRank.rank_id = sUser.rank_id) WHERE site_order BETWEEN '01A' AND '34D' ORDER BY site_order ASC Let me know how that works out (will probably need tweaked before it will run)
-
Help me with Wordpress MYSQL Query Data Posting
Muddy_Funster replied to axepex's topic in PHP Coding Help
OK, let's go one step at a time - do you know if there is anything in the $user_login at the time when you are trying to use it? And if so what is it? -
Moving from Java to PHP .... A good career move?
Muddy_Funster replied to venkatdabri's topic in Miscellaneous
Being honest, I think it depends on location as much as anything else. In the UK at least .NET and asp jobs are far more prevalent than PHP. Java isn't something I would lose touch with at this point in time, with the IoT starting to flesh out it's a strong contender, along with Python and RoR, for keeping costs minimal for cheap functional devices. PHP is worth learning in addition to Java, as there is quite a bit of contract work going about for it and it's something that's not going away any time soon. With a strong Java background you should find it a quick language to pick up, once you burst through the syntax barrier. -
Please help with database query -- PHP Beginner
Muddy_Funster replied to PNMorrison's topic in PHP Coding Help
what CMS is it? -
Please help with database query -- PHP Beginner
Muddy_Funster replied to PNMorrison's topic in PHP Coding Help
Not exactly what I was looking for, I was looking for the code that handles the database query and results. Although you could apply some logic to the function (which looks more like a single method from within a larger object, but I could be wrong) that you have posted, it wouldn't be the best approach. Can you post up the code that handles the db transaction that you are using to check for events? -
Getting only last date of transaction with join
Muddy_Funster replied to I-AM-OBODO's topic in MySQL Help
I'm curious now requinix, I would have done it something along the lines of: SELECT c.firstname, c.surname, c.regDate, trn.mLastTrans FROM confirmed c INNER JOIN ( SELECT user_id, MAX(t.lastTrans) AS mLastTrans FROM transaction t GROUP BY user_id ) AS trn ON c.user_id = trn.user_id WHERE c.status = 'confirmed' ORDER BY c.user_id Asides from being a bit more long winded, would you say there would be any other issues with using a subquery join in that manner? Or is it just a personal thing? -
Please help with database query -- PHP Beginner
Muddy_Funster replied to PNMorrison's topic in PHP Coding Help
Hi and welcome to PHPFreaks, could you please use code bb tags (open with code wrapped in square brackets and close with /code - also wrapped in square brackets, or highlight the code once it is in your post and click on the |< >| icon in the toolbar of the post box) when posting your code in the future. We will need to see the current control script for processing the DB results to provide you a response relevant to your current code. -
Get User IP in PHP and cURL to Remote File
Muddy_Funster replied to wolfwood's topic in PHP Coding Help
could you elaborate on what you are actually doing here? I ask because the little you have posted smells a bit nefarious, like IP harvesting for malware bot control, which isn't something a lot of people are going to help you with. Also, post up the code you have tried already so we can see where you have gotten to. -
You have dug up someone else's post from almost a year ago, you would be far better creating your own thread on this that way you will get the update alerts, rather than the OP who I expect is no longer interested in this topic. Please start your own topic and give us some more details to work with - i.e. what languages are you familiar with / looking to use, what setup are you planning to implement, what's the scope of the project etc. Then we will be able to give you a far more complete answer.
- 10 replies
-
Instead of SELECT * list the columns you want to return in the format of tablename.columnname (where tablename is the alias you are using. Then explicitly define the join for sv1profile_fields_data the way you did for the other two tables. That probably won't fix the issue by itself, but try it and post up the new query if it's still giving duplicates.
-
Help me with Wordpress MYSQL Query Data Posting
Muddy_Funster replied to axepex's topic in PHP Coding Help
Firstly : You really shouldn't be using mysql_ any more - it has been depreciated for years and is written out of the new PHP7 and does not work at all. Second: where is the $user_login coming from and does it contain what it should? Third: I really don't think you should have a > conditional in the select statement. -
Foreign Keys: Childless rows (NULL values in fk field)
Muddy_Funster replied to doni49's topic in MySQL Help
The child can only contain a null value if the parent contains a null value. The point of a foreign key is that it forces relational values between the parent and child, all the parent ID fields that you are attaching to with the foreign keys are set to NOT NULL - as ID fields should be. You can't have a NOT NULL parent and then insert NULL values in the child. I think you should revisit your design. At a glance: condensing "acctXID, defCatID or catID" into a single column e.g. refID and then having a second column to flag the reference source e.g. sourceID which you can match up that using a crossover table could be a better solution. -
User profiling homework - need some help
Muddy_Funster replied to jdgrcorp's topic in PHP Coding Help
I'm with Jim here, you are coming at this with the wrong perspective. You need to step back, sit down and look at the overall requirement. You are coming at this by focusing on a specific part of the problem and spiraling out to try and capture the rest of the requirements as you go. This is only going to get you tied up in knots and will eventually - on anything more than the most simple requests - result in you having to re-write a huge part of your code because it just doesn't have the scope to handle everything that your project requires. Take the problem as a whole, find the start and the end, identify the specific requirements in between and then use that to crystallise the overall process. once you have that, break each part down and identify the stages required as well as the process flow between each part and remember to document everything in a way that you can follow. When you have that, and not before, then you start to code. Some people have a gift, they can naturally visualise problems in this way and just jump in with a high degree of success, the rest of us have to spend anything up to three to four times as time on the project design stage as we do actually coding. Dont try to run before you can walk. We can't answer any more specific questions without seeing the full and proper project brief. What you described in the original post has the potential to either be quite an intricate piece of software, or a fairly straightforward mock simplification. Either way I can't find a way to use categories as defining characteristics and still keep them meaningful for a shopping cart. Something else that you could consider would be looking at the currently available e-store software solutions and see if any of them do what you are trying to. If there is all you need to do is quote it and give a brief essay on why "reinventing the wheel" is a waste of a developers time. -
when doing large/multiline blocks of text like that, consider using heredoc or nowdoc to help avoid this issue.
-
All you need is a basic counter in the loop (although you seem to not have included said loop in your code...) combined with an if conditional check to specify an output dependant on the state of the counter.
-
the php function is looking for a parameter called ($vid), you would need to catch and pass this info through the ajax call, and then tweak the php code in the controller to check for the post value in the event that the page is being loaded through an ajax call and then call the function using the post variable in the parameter. ajax: //make the content of your JS function something like this $.ajax({ method: "post", url:"...control.php", data: {'sender': 'customAjaxMethod', 'vid': $(this).attr("data-id")}, //<<-- this is just an example, you should change $(this).attr("data-id") to whatever holds the vidID reference in the DOM element. success: function(data){ ... } }) PHP: // add something akin to the following to the control.php file if(!isset($_POST['sender']){} elseif(!isset($_POST['vid'] || $_POST['sender'] != "customAjaxMethod"){} else{ videohitCount_function($_POST['vid']); } This obviously isn't meant as a copy and paste solution, only a guideline for you to work from. Good luck.
-
how to use the boolean in php with json response code
Muddy_Funster replied to livetrainstatus's topic in PHP Coding Help
You are very welcome, best of luck with the rest of your project. If you are done could you mark the topic as answered please? -
it's a single . [dot] ./ = start in current directory ../ = start in parent directory
-
Having issue passing id to url after login
Muddy_Funster replied to ianhaney's topic in PHP Coding Help
It's probably more simple than that. One of the issues with the script is that the OP has used the reserved word "password" for the title of a column in the database. This means that the SELECT query isn't going to return what they think it is. To be honest though, that's only one of several serious issues here and can be fixed by wrapping the column name in backticks. -
how to use the boolean in php with json response code
Muddy_Funster replied to livetrainstatus's topic in PHP Coding Help
You would use an if conditional check on the value of the has_arrived element in the array and present an output depending on the content. A shorthand way of doing this is with a ternary operator ... foreach... ($stop['has_arrived'] === true) ? $stop['has_arrived'] = "Arrived" : $stop['has_arrived'] = "Still not here yet!"; echo ... ... -
Having issue passing id to url after login
Muddy_Funster replied to ianhaney's topic in PHP Coding Help
You have some bad practices going on here, in fact that could be one of the most bizarre login procedures I have ever seen. I also hope that those DB credentials are fake or run on a purely local test server. What is the ID and where are you getting it from? -
Help understanding why this Mysql Query is badly designed.
Muddy_Funster replied to blmg2009's topic in MySQL Help
Using SELECT * is like letting go of the steering wheel while driving - it's not an issue while the road is straight, but sooner or later there will be a corner, it's all about control. Keep control at all times, always explicitly list columns. Also, by listing columns you allow yourself to alias them in the SELECT. This means that, regardless of the table structure, you can pick and choose the titles of the columns as they will appear in the query output. This goes hand in hand with the fact that listing the columns in the SELECT makes it much easier to establish exactly what the query is bringing back without having to look through the whole FROM and WHERE sections. It used to be that SELECT * did funny things to index performance (like ignoring there were any indexes at all) as well, but I expect that's all been sorted now (It's been a while since I used SELECT * for anything other than debugging). NOTE: Always make aliases relevant. It's all good and well having single letters for tables and all, but when you look back at the code in the future to change or add to it, it makes it far more difficult to establish what's going on if you use "customer_current_active AS c" rather than "customer_current_active AS cust" As for the running of 10 sub-queries against the same table individually: they are all hitting the same dataset, so could be run as a single query. Properly you would JOIN the tables, as Barand said, and only use subqueries for either pulling out a limited dataset from a huge table to apply the JOIN to instead, or to run any aggregate functions against the table that need to be pre-established to work with the final dataset. There are plenty of resources online if you search for "writing efficient SQL queries" and the like. There's also likely to be a couple of good books on the matter too, and - if you're feeling flush - Oracle offer expensive training courses on DBA.