Comment by andrewsi on Not returning data from multiple tables (php/sql)
You're running fetch twice, once in each loop. if there's data to be found, then the first fetch will find it, so there's nothing left for the second to do. Try putting the final three echoes inside...
View ArticleAnswer by andrewsi for Error when tried to allocate bytes
The issue is with these lines:$result = $sth->fetchAll(PDO::FETCH_ASSOC);while ($row = $result) { $data[] = $row;}You're assigning $result, and then using that value in your while loop. What is...
View ArticleAnswer by andrewsi for MySql Bulk(ish) Insert
When you use INSERT INTO `order_status_histories` VALUES (....)you need to pass each value that the table structure requires, in the correct order. You can omit fields from the values if they have a...
View ArticleTransformer stage and dynamic files structure
I'm reading a datafile that's being generated from a data source that's denormalizing data into a flat file. As an...
View ArticleTransformer stage, with dynamic number of columns
I have an unstructured data file, that's being extracted from a database, and de-normalized along the way. As a very quick example:File References,Reference_Count,Reference_1,Reference_2...
View ArticleComment by andrewsi on Moving through Detail Pages of Recordset
You're not saving the query per se; you're saving the WHERE clause. When the user clicks to pull up an individual record, say id=3, you need to re-run that search query again, and go through the...
View ArticleComment by andrewsi on Not returning data from multiple tables (php/sql)
You're running fetch twice, once in each loop. if there's data to be found, then the first fetch will find it, so there's nothing left for the second to do. Try putting the final three echoes inside...
View ArticleComment by andrewsi on How to set form input data to equal specific strings...
You're using the wrong operator. = is to set a value; try if ($_POST['fName'] == "Megan") to do a comparison, instead.
View ArticleAnswer by andrewsi for SELECT id FROM table_name WHERE column = $variable
SELECT id FROM order WHERE orderNumber = '$orderNumber'ORDER is a reserver word in SQL; I'd recommend you change the name of the table to something else.If you really can't, then you can escape column...
View ArticleComment by andrewsi on How to increment a datetime by one day?
if you set d to 8/31/18 then this returns 8/32/18. If you change the year from 18, it just breaks.
View ArticleAnswer by andrewsi for Odd and confusing PHP syntax
It's using the operator precedence rules of PHP in an unusual way. If you have an and statement, PHP will stop processing it if the left side is false - there's no need to check the right hand side,...
View ArticleAnswer by andrewsi for Foreach PHP PDO query
I think this should do what you're asking - you're generating $color as a variable in the foreach, but you were accessing it as an array. $colors = explode(' ', $_GET['color']); foreach ($colors as...
View ArticleAnswer by andrewsi for Display different content depending on Referrer
Your logic is slightly skewed; you're checking to see if the URL from parse_url matches the domains in your array; but you're running through the whole array each time. So you get both a match and a...
View ArticleAnswer by andrewsi for php - xml parser Notice: Trying to get property of...
If it works with integers, but not with strings, you probably just need to quote your variable in your query: $result2= $xpath2->query('/root[@name="gf"]/node1[@id="'. $id2.'"]');
View ArticleAnswer by andrewsi for Extended class instance cannot access the injected...
I think you're misunderstanding how objects work. class dog { public $id = 0; public function __construct($attributes = array()) { foreach($attributes as $field=>$value){ $this->$field = $value;...
View ArticleAnswer by andrewsi for Why do Wordpress code consistently have the uncommon...
There's an explanation on the WordPress site: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#yoda-conditions It's called Yoda conditions; in short, it's because it's very...
View ArticleAnswer by andrewsi for Displaying multiple rows in PhP
There are a few things wrong with your code: $query = "SELECT * FROM hotel"; $results = $conn->query($query); $hotel = $results->fetch(); At this point, you've loaded the first record into...
View ArticleAnswer by andrewsi for User Active Check
The issue is here: $userRow=$stmt->fetch(PDO::FETCH_ASSOC); if($userRow == '0'){ You're getting an associative array back from fetch, and comparing it with 0 on the next line. Instead, you want to...
View ArticleAnswer by andrewsi for Anagram Algorithm in PHP
(I'm adding this as a separate answer, as it's a different way of dealing with the issue than I mentioned in my first issue) This is a more complex way of working out which words in the dictionary are...
View ArticleAnswer by andrewsi for How to get last inserted inserted row id from PDO
You're almost there. If you look at the manual page for lastInsertId, it's called on the database handle - you're currently calling it on the statement. You just need to call:...
View Article