Mysqli conversion when left join is used
Trying to convert to MySQLi. I have received great help these last few days, thanks. My next problem is how to convert when LEFT JOIN is used.
Working MYSQL code
$q1 = 'SELECT * FROM earth LEFT JOIN cities ON (cities.countryid4city = earth.countryid) GROUP BY countryid ORDER by countryid';
$q2 = 'SELECT * FROM cities ORDER BY cityname';
$mytable1 = mysql_query($q1);
$mytable2 = mysql_query($q2);
echo mysql_error();
mysql_close();
$numrows_table1 = mysql_numrows($mytable1);
$numrows_table2 = mysql_numrows($mytable2);
$i = 0;
while ($i < $numrows_table1){
$countryid = mysql_result($mytable1,$i,'countryid');
$countryname = mysql_result($mytable1,$i,'countryname');
print "<br><br>Country is " . $countryname . ", and these cities are in it";
$j = 0;
while ($j < $numrows_table2){
$countryid4city = mysql_result($mytable2,$j,'countryid4city');
$cityname = mysql_result($mytable2,$j,'cityname');
if ($countryid4city == $countryid){
print "<br><br>" . $cityname;
}
$j++;
}
$i++;
}
Output is as expected. (Note, this website deletes the row breaks in this but they are there).
Country is USA, and these cities are in it
New York
San Francisco
Country is England, and these cities are in it
Chelsea
Clapham
London
Country is Sweden, and these cities are in it
Lidingö
Stockholm
Broken MYSQLI conversion (followed the same logic, I thought)
$q1 = 'SELECT * FROM earth LEFT JOIN cities ON (cities.countryid4city = earth.countryid) GROUP BY countryid ORDER by countryid';
$q2 = 'SELECT * FROM cities ORDER BY cityname';
$mytable1 = mysqli_query($conned, $q1);
$mytable2 = mysqli_query($conned, $q2);
mysqli_close($conned);
while($row1 = mysqli_fetch_assoc($mytable1)){
$countryid = $row1['countryid'];
$countryname = $row1['countryname'];
print "<br><br>Country is " . $countryname . ", and these cities are in it";
while($row2 = mysqli_fetch_assoc($mytable2)){
$countryid4city = $row2['countryid4city'];
$cityname = $row2['cityname'];
if ($countryid4city == $countryid){
print "<br><br>" . $cityname;
}
}
}
Output
Country is USA, and these cities are in it
New York
San Francisco
Country is England, and these cities are in it
Country is Sweden, and these cities are in it
It is only picking up the LEFT JOIN values from the second table for the first value of the first table. What am I missing? I gather I might not have had an ideal solution to the working MYSQL version.
Any help greatly appreciated. Thanks.
php mysql mysqli
add a comment |
Trying to convert to MySQLi. I have received great help these last few days, thanks. My next problem is how to convert when LEFT JOIN is used.
Working MYSQL code
$q1 = 'SELECT * FROM earth LEFT JOIN cities ON (cities.countryid4city = earth.countryid) GROUP BY countryid ORDER by countryid';
$q2 = 'SELECT * FROM cities ORDER BY cityname';
$mytable1 = mysql_query($q1);
$mytable2 = mysql_query($q2);
echo mysql_error();
mysql_close();
$numrows_table1 = mysql_numrows($mytable1);
$numrows_table2 = mysql_numrows($mytable2);
$i = 0;
while ($i < $numrows_table1){
$countryid = mysql_result($mytable1,$i,'countryid');
$countryname = mysql_result($mytable1,$i,'countryname');
print "<br><br>Country is " . $countryname . ", and these cities are in it";
$j = 0;
while ($j < $numrows_table2){
$countryid4city = mysql_result($mytable2,$j,'countryid4city');
$cityname = mysql_result($mytable2,$j,'cityname');
if ($countryid4city == $countryid){
print "<br><br>" . $cityname;
}
$j++;
}
$i++;
}
Output is as expected. (Note, this website deletes the row breaks in this but they are there).
Country is USA, and these cities are in it
New York
San Francisco
Country is England, and these cities are in it
Chelsea
Clapham
London
Country is Sweden, and these cities are in it
Lidingö
Stockholm
Broken MYSQLI conversion (followed the same logic, I thought)
$q1 = 'SELECT * FROM earth LEFT JOIN cities ON (cities.countryid4city = earth.countryid) GROUP BY countryid ORDER by countryid';
$q2 = 'SELECT * FROM cities ORDER BY cityname';
$mytable1 = mysqli_query($conned, $q1);
$mytable2 = mysqli_query($conned, $q2);
mysqli_close($conned);
while($row1 = mysqli_fetch_assoc($mytable1)){
$countryid = $row1['countryid'];
$countryname = $row1['countryname'];
print "<br><br>Country is " . $countryname . ", and these cities are in it";
while($row2 = mysqli_fetch_assoc($mytable2)){
$countryid4city = $row2['countryid4city'];
$cityname = $row2['cityname'];
if ($countryid4city == $countryid){
print "<br><br>" . $cityname;
}
}
}
Output
Country is USA, and these cities are in it
New York
San Francisco
Country is England, and these cities are in it
Country is Sweden, and these cities are in it
It is only picking up the LEFT JOIN values from the second table for the first value of the first table. What am I missing? I gather I might not have had an ideal solution to the working MYSQL version.
Any help greatly appreciated. Thanks.
php mysql mysqli
it won't delete the line breaks if you format your output the same way your formatted the code :-)
– ADyson
Nov 13 '18 at 12:24
By the way, you really don't need two SQL queries to get the output you need. Al the info is already in the first query. You might just want to add a secondary ordering based on the city name, so it's easier to process.
– ADyson
Nov 13 '18 at 12:25
the actual problem with your code though is that you can't run mysqli_fetch_assoc on a row twice...once it's processed that row it won't process it again. You'd have get the second table into an array (e.g. using fetch_all), and then you can re-use the array as many times as you like. But it shouldn't be necessary if you think a bit more about how you could just use the first query's data on its own.
– ADyson
Nov 13 '18 at 12:26
2
The actual problem is that you have a GROUP BY clause but no aggregating functions. Nothing good ever came from this arrangement. Also, NEVER useSELECT *
– Strawberry
Nov 13 '18 at 12:32
add a comment |
Trying to convert to MySQLi. I have received great help these last few days, thanks. My next problem is how to convert when LEFT JOIN is used.
Working MYSQL code
$q1 = 'SELECT * FROM earth LEFT JOIN cities ON (cities.countryid4city = earth.countryid) GROUP BY countryid ORDER by countryid';
$q2 = 'SELECT * FROM cities ORDER BY cityname';
$mytable1 = mysql_query($q1);
$mytable2 = mysql_query($q2);
echo mysql_error();
mysql_close();
$numrows_table1 = mysql_numrows($mytable1);
$numrows_table2 = mysql_numrows($mytable2);
$i = 0;
while ($i < $numrows_table1){
$countryid = mysql_result($mytable1,$i,'countryid');
$countryname = mysql_result($mytable1,$i,'countryname');
print "<br><br>Country is " . $countryname . ", and these cities are in it";
$j = 0;
while ($j < $numrows_table2){
$countryid4city = mysql_result($mytable2,$j,'countryid4city');
$cityname = mysql_result($mytable2,$j,'cityname');
if ($countryid4city == $countryid){
print "<br><br>" . $cityname;
}
$j++;
}
$i++;
}
Output is as expected. (Note, this website deletes the row breaks in this but they are there).
Country is USA, and these cities are in it
New York
San Francisco
Country is England, and these cities are in it
Chelsea
Clapham
London
Country is Sweden, and these cities are in it
Lidingö
Stockholm
Broken MYSQLI conversion (followed the same logic, I thought)
$q1 = 'SELECT * FROM earth LEFT JOIN cities ON (cities.countryid4city = earth.countryid) GROUP BY countryid ORDER by countryid';
$q2 = 'SELECT * FROM cities ORDER BY cityname';
$mytable1 = mysqli_query($conned, $q1);
$mytable2 = mysqli_query($conned, $q2);
mysqli_close($conned);
while($row1 = mysqli_fetch_assoc($mytable1)){
$countryid = $row1['countryid'];
$countryname = $row1['countryname'];
print "<br><br>Country is " . $countryname . ", and these cities are in it";
while($row2 = mysqli_fetch_assoc($mytable2)){
$countryid4city = $row2['countryid4city'];
$cityname = $row2['cityname'];
if ($countryid4city == $countryid){
print "<br><br>" . $cityname;
}
}
}
Output
Country is USA, and these cities are in it
New York
San Francisco
Country is England, and these cities are in it
Country is Sweden, and these cities are in it
It is only picking up the LEFT JOIN values from the second table for the first value of the first table. What am I missing? I gather I might not have had an ideal solution to the working MYSQL version.
Any help greatly appreciated. Thanks.
php mysql mysqli
Trying to convert to MySQLi. I have received great help these last few days, thanks. My next problem is how to convert when LEFT JOIN is used.
Working MYSQL code
$q1 = 'SELECT * FROM earth LEFT JOIN cities ON (cities.countryid4city = earth.countryid) GROUP BY countryid ORDER by countryid';
$q2 = 'SELECT * FROM cities ORDER BY cityname';
$mytable1 = mysql_query($q1);
$mytable2 = mysql_query($q2);
echo mysql_error();
mysql_close();
$numrows_table1 = mysql_numrows($mytable1);
$numrows_table2 = mysql_numrows($mytable2);
$i = 0;
while ($i < $numrows_table1){
$countryid = mysql_result($mytable1,$i,'countryid');
$countryname = mysql_result($mytable1,$i,'countryname');
print "<br><br>Country is " . $countryname . ", and these cities are in it";
$j = 0;
while ($j < $numrows_table2){
$countryid4city = mysql_result($mytable2,$j,'countryid4city');
$cityname = mysql_result($mytable2,$j,'cityname');
if ($countryid4city == $countryid){
print "<br><br>" . $cityname;
}
$j++;
}
$i++;
}
Output is as expected. (Note, this website deletes the row breaks in this but they are there).
Country is USA, and these cities are in it
New York
San Francisco
Country is England, and these cities are in it
Chelsea
Clapham
London
Country is Sweden, and these cities are in it
Lidingö
Stockholm
Broken MYSQLI conversion (followed the same logic, I thought)
$q1 = 'SELECT * FROM earth LEFT JOIN cities ON (cities.countryid4city = earth.countryid) GROUP BY countryid ORDER by countryid';
$q2 = 'SELECT * FROM cities ORDER BY cityname';
$mytable1 = mysqli_query($conned, $q1);
$mytable2 = mysqli_query($conned, $q2);
mysqli_close($conned);
while($row1 = mysqli_fetch_assoc($mytable1)){
$countryid = $row1['countryid'];
$countryname = $row1['countryname'];
print "<br><br>Country is " . $countryname . ", and these cities are in it";
while($row2 = mysqli_fetch_assoc($mytable2)){
$countryid4city = $row2['countryid4city'];
$cityname = $row2['cityname'];
if ($countryid4city == $countryid){
print "<br><br>" . $cityname;
}
}
}
Output
Country is USA, and these cities are in it
New York
San Francisco
Country is England, and these cities are in it
Country is Sweden, and these cities are in it
It is only picking up the LEFT JOIN values from the second table for the first value of the first table. What am I missing? I gather I might not have had an ideal solution to the working MYSQL version.
Any help greatly appreciated. Thanks.
php mysql mysqli
php mysql mysqli
edited Nov 13 '18 at 13:53
Lucky Saini
2,1491234
2,1491234
asked Nov 13 '18 at 12:18
Garry JonesGarry Jones
167
167
it won't delete the line breaks if you format your output the same way your formatted the code :-)
– ADyson
Nov 13 '18 at 12:24
By the way, you really don't need two SQL queries to get the output you need. Al the info is already in the first query. You might just want to add a secondary ordering based on the city name, so it's easier to process.
– ADyson
Nov 13 '18 at 12:25
the actual problem with your code though is that you can't run mysqli_fetch_assoc on a row twice...once it's processed that row it won't process it again. You'd have get the second table into an array (e.g. using fetch_all), and then you can re-use the array as many times as you like. But it shouldn't be necessary if you think a bit more about how you could just use the first query's data on its own.
– ADyson
Nov 13 '18 at 12:26
2
The actual problem is that you have a GROUP BY clause but no aggregating functions. Nothing good ever came from this arrangement. Also, NEVER useSELECT *
– Strawberry
Nov 13 '18 at 12:32
add a comment |
it won't delete the line breaks if you format your output the same way your formatted the code :-)
– ADyson
Nov 13 '18 at 12:24
By the way, you really don't need two SQL queries to get the output you need. Al the info is already in the first query. You might just want to add a secondary ordering based on the city name, so it's easier to process.
– ADyson
Nov 13 '18 at 12:25
the actual problem with your code though is that you can't run mysqli_fetch_assoc on a row twice...once it's processed that row it won't process it again. You'd have get the second table into an array (e.g. using fetch_all), and then you can re-use the array as many times as you like. But it shouldn't be necessary if you think a bit more about how you could just use the first query's data on its own.
– ADyson
Nov 13 '18 at 12:26
2
The actual problem is that you have a GROUP BY clause but no aggregating functions. Nothing good ever came from this arrangement. Also, NEVER useSELECT *
– Strawberry
Nov 13 '18 at 12:32
it won't delete the line breaks if you format your output the same way your formatted the code :-)
– ADyson
Nov 13 '18 at 12:24
it won't delete the line breaks if you format your output the same way your formatted the code :-)
– ADyson
Nov 13 '18 at 12:24
By the way, you really don't need two SQL queries to get the output you need. Al the info is already in the first query. You might just want to add a secondary ordering based on the city name, so it's easier to process.
– ADyson
Nov 13 '18 at 12:25
By the way, you really don't need two SQL queries to get the output you need. Al the info is already in the first query. You might just want to add a secondary ordering based on the city name, so it's easier to process.
– ADyson
Nov 13 '18 at 12:25
the actual problem with your code though is that you can't run mysqli_fetch_assoc on a row twice...once it's processed that row it won't process it again. You'd have get the second table into an array (e.g. using fetch_all), and then you can re-use the array as many times as you like. But it shouldn't be necessary if you think a bit more about how you could just use the first query's data on its own.
– ADyson
Nov 13 '18 at 12:26
the actual problem with your code though is that you can't run mysqli_fetch_assoc on a row twice...once it's processed that row it won't process it again. You'd have get the second table into an array (e.g. using fetch_all), and then you can re-use the array as many times as you like. But it shouldn't be necessary if you think a bit more about how you could just use the first query's data on its own.
– ADyson
Nov 13 '18 at 12:26
2
2
The actual problem is that you have a GROUP BY clause but no aggregating functions. Nothing good ever came from this arrangement. Also, NEVER use
SELECT *
– Strawberry
Nov 13 '18 at 12:32
The actual problem is that you have a GROUP BY clause but no aggregating functions. Nothing good ever came from this arrangement. Also, NEVER use
SELECT *
– Strawberry
Nov 13 '18 at 12:32
add a comment |
1 Answer
1
active
oldest
votes
mysql_result
makes the result set available as an indexed array. OTOH mysqli_fetch_assoc
retrieves a single row from the result. While you could solve the problem by moving the cursor to the start of the recordset before the inner loop:
mysqli_result_data_seek ($mytable2, 0);
while($row2 = mysqli_fetch_assoc($mytable2)){
this merely compounds the silliness of running a second query to retrieve data you already know. Change the first query to
...ORDER by countryid, cityname";
lose the second query and the inner loop. Inject a new country header in the output each time the countryid changes.
Trying to follow the above instructions. Sorry to be a pain, but could one of you point me further in the right direction? My web server supplier tells me only mysqli will work from December 4th, I found out last week. I have 19 websites, 14 years work and 1.2 million lines of code to get through. I just need simple solutions and I am failing on syntax. Really pleased if you can help a little more, forever grateful.
– Garry Jones
Nov 13 '18 at 16:48
I have now spent a few hours on this and have tried lots of uploaded files after looking at websites and your answers trying to fathom out how to do this. I understand I do not have the skillset and am a little out of my depth. You say "Inject a new country header in the output each time the countryid changes." - How do I do that? Any help would be greatly appreciated.
– Garry Jones
Nov 14 '18 at 0:14
"I have 19 websites, 14 years work and 1.2 million lines of code to get through" - you should learn how to use the tools, but you are not going to meet your deadlines. Try adding a shim in an an auto-prepend: github.com/dotpointer/mysql-shim (note that you won't be able to test out the functionality on a system with both mysql and mysqli extensions installed). Next time it would be helpful to state in your question import constraints like this.
– symcbean
Nov 14 '18 at 10:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280864%2fmysqli-conversion-when-left-join-is-used%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
mysql_result
makes the result set available as an indexed array. OTOH mysqli_fetch_assoc
retrieves a single row from the result. While you could solve the problem by moving the cursor to the start of the recordset before the inner loop:
mysqli_result_data_seek ($mytable2, 0);
while($row2 = mysqli_fetch_assoc($mytable2)){
this merely compounds the silliness of running a second query to retrieve data you already know. Change the first query to
...ORDER by countryid, cityname";
lose the second query and the inner loop. Inject a new country header in the output each time the countryid changes.
Trying to follow the above instructions. Sorry to be a pain, but could one of you point me further in the right direction? My web server supplier tells me only mysqli will work from December 4th, I found out last week. I have 19 websites, 14 years work and 1.2 million lines of code to get through. I just need simple solutions and I am failing on syntax. Really pleased if you can help a little more, forever grateful.
– Garry Jones
Nov 13 '18 at 16:48
I have now spent a few hours on this and have tried lots of uploaded files after looking at websites and your answers trying to fathom out how to do this. I understand I do not have the skillset and am a little out of my depth. You say "Inject a new country header in the output each time the countryid changes." - How do I do that? Any help would be greatly appreciated.
– Garry Jones
Nov 14 '18 at 0:14
"I have 19 websites, 14 years work and 1.2 million lines of code to get through" - you should learn how to use the tools, but you are not going to meet your deadlines. Try adding a shim in an an auto-prepend: github.com/dotpointer/mysql-shim (note that you won't be able to test out the functionality on a system with both mysql and mysqli extensions installed). Next time it would be helpful to state in your question import constraints like this.
– symcbean
Nov 14 '18 at 10:36
add a comment |
mysql_result
makes the result set available as an indexed array. OTOH mysqli_fetch_assoc
retrieves a single row from the result. While you could solve the problem by moving the cursor to the start of the recordset before the inner loop:
mysqli_result_data_seek ($mytable2, 0);
while($row2 = mysqli_fetch_assoc($mytable2)){
this merely compounds the silliness of running a second query to retrieve data you already know. Change the first query to
...ORDER by countryid, cityname";
lose the second query and the inner loop. Inject a new country header in the output each time the countryid changes.
Trying to follow the above instructions. Sorry to be a pain, but could one of you point me further in the right direction? My web server supplier tells me only mysqli will work from December 4th, I found out last week. I have 19 websites, 14 years work and 1.2 million lines of code to get through. I just need simple solutions and I am failing on syntax. Really pleased if you can help a little more, forever grateful.
– Garry Jones
Nov 13 '18 at 16:48
I have now spent a few hours on this and have tried lots of uploaded files after looking at websites and your answers trying to fathom out how to do this. I understand I do not have the skillset and am a little out of my depth. You say "Inject a new country header in the output each time the countryid changes." - How do I do that? Any help would be greatly appreciated.
– Garry Jones
Nov 14 '18 at 0:14
"I have 19 websites, 14 years work and 1.2 million lines of code to get through" - you should learn how to use the tools, but you are not going to meet your deadlines. Try adding a shim in an an auto-prepend: github.com/dotpointer/mysql-shim (note that you won't be able to test out the functionality on a system with both mysql and mysqli extensions installed). Next time it would be helpful to state in your question import constraints like this.
– symcbean
Nov 14 '18 at 10:36
add a comment |
mysql_result
makes the result set available as an indexed array. OTOH mysqli_fetch_assoc
retrieves a single row from the result. While you could solve the problem by moving the cursor to the start of the recordset before the inner loop:
mysqli_result_data_seek ($mytable2, 0);
while($row2 = mysqli_fetch_assoc($mytable2)){
this merely compounds the silliness of running a second query to retrieve data you already know. Change the first query to
...ORDER by countryid, cityname";
lose the second query and the inner loop. Inject a new country header in the output each time the countryid changes.
mysql_result
makes the result set available as an indexed array. OTOH mysqli_fetch_assoc
retrieves a single row from the result. While you could solve the problem by moving the cursor to the start of the recordset before the inner loop:
mysqli_result_data_seek ($mytable2, 0);
while($row2 = mysqli_fetch_assoc($mytable2)){
this merely compounds the silliness of running a second query to retrieve data you already know. Change the first query to
...ORDER by countryid, cityname";
lose the second query and the inner loop. Inject a new country header in the output each time the countryid changes.
answered Nov 13 '18 at 12:53
symcbeansymcbean
40.9k44076
40.9k44076
Trying to follow the above instructions. Sorry to be a pain, but could one of you point me further in the right direction? My web server supplier tells me only mysqli will work from December 4th, I found out last week. I have 19 websites, 14 years work and 1.2 million lines of code to get through. I just need simple solutions and I am failing on syntax. Really pleased if you can help a little more, forever grateful.
– Garry Jones
Nov 13 '18 at 16:48
I have now spent a few hours on this and have tried lots of uploaded files after looking at websites and your answers trying to fathom out how to do this. I understand I do not have the skillset and am a little out of my depth. You say "Inject a new country header in the output each time the countryid changes." - How do I do that? Any help would be greatly appreciated.
– Garry Jones
Nov 14 '18 at 0:14
"I have 19 websites, 14 years work and 1.2 million lines of code to get through" - you should learn how to use the tools, but you are not going to meet your deadlines. Try adding a shim in an an auto-prepend: github.com/dotpointer/mysql-shim (note that you won't be able to test out the functionality on a system with both mysql and mysqli extensions installed). Next time it would be helpful to state in your question import constraints like this.
– symcbean
Nov 14 '18 at 10:36
add a comment |
Trying to follow the above instructions. Sorry to be a pain, but could one of you point me further in the right direction? My web server supplier tells me only mysqli will work from December 4th, I found out last week. I have 19 websites, 14 years work and 1.2 million lines of code to get through. I just need simple solutions and I am failing on syntax. Really pleased if you can help a little more, forever grateful.
– Garry Jones
Nov 13 '18 at 16:48
I have now spent a few hours on this and have tried lots of uploaded files after looking at websites and your answers trying to fathom out how to do this. I understand I do not have the skillset and am a little out of my depth. You say "Inject a new country header in the output each time the countryid changes." - How do I do that? Any help would be greatly appreciated.
– Garry Jones
Nov 14 '18 at 0:14
"I have 19 websites, 14 years work and 1.2 million lines of code to get through" - you should learn how to use the tools, but you are not going to meet your deadlines. Try adding a shim in an an auto-prepend: github.com/dotpointer/mysql-shim (note that you won't be able to test out the functionality on a system with both mysql and mysqli extensions installed). Next time it would be helpful to state in your question import constraints like this.
– symcbean
Nov 14 '18 at 10:36
Trying to follow the above instructions. Sorry to be a pain, but could one of you point me further in the right direction? My web server supplier tells me only mysqli will work from December 4th, I found out last week. I have 19 websites, 14 years work and 1.2 million lines of code to get through. I just need simple solutions and I am failing on syntax. Really pleased if you can help a little more, forever grateful.
– Garry Jones
Nov 13 '18 at 16:48
Trying to follow the above instructions. Sorry to be a pain, but could one of you point me further in the right direction? My web server supplier tells me only mysqli will work from December 4th, I found out last week. I have 19 websites, 14 years work and 1.2 million lines of code to get through. I just need simple solutions and I am failing on syntax. Really pleased if you can help a little more, forever grateful.
– Garry Jones
Nov 13 '18 at 16:48
I have now spent a few hours on this and have tried lots of uploaded files after looking at websites and your answers trying to fathom out how to do this. I understand I do not have the skillset and am a little out of my depth. You say "Inject a new country header in the output each time the countryid changes." - How do I do that? Any help would be greatly appreciated.
– Garry Jones
Nov 14 '18 at 0:14
I have now spent a few hours on this and have tried lots of uploaded files after looking at websites and your answers trying to fathom out how to do this. I understand I do not have the skillset and am a little out of my depth. You say "Inject a new country header in the output each time the countryid changes." - How do I do that? Any help would be greatly appreciated.
– Garry Jones
Nov 14 '18 at 0:14
"I have 19 websites, 14 years work and 1.2 million lines of code to get through" - you should learn how to use the tools, but you are not going to meet your deadlines. Try adding a shim in an an auto-prepend: github.com/dotpointer/mysql-shim (note that you won't be able to test out the functionality on a system with both mysql and mysqli extensions installed). Next time it would be helpful to state in your question import constraints like this.
– symcbean
Nov 14 '18 at 10:36
"I have 19 websites, 14 years work and 1.2 million lines of code to get through" - you should learn how to use the tools, but you are not going to meet your deadlines. Try adding a shim in an an auto-prepend: github.com/dotpointer/mysql-shim (note that you won't be able to test out the functionality on a system with both mysql and mysqli extensions installed). Next time it would be helpful to state in your question import constraints like this.
– symcbean
Nov 14 '18 at 10:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280864%2fmysqli-conversion-when-left-join-is-used%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
it won't delete the line breaks if you format your output the same way your formatted the code :-)
– ADyson
Nov 13 '18 at 12:24
By the way, you really don't need two SQL queries to get the output you need. Al the info is already in the first query. You might just want to add a secondary ordering based on the city name, so it's easier to process.
– ADyson
Nov 13 '18 at 12:25
the actual problem with your code though is that you can't run mysqli_fetch_assoc on a row twice...once it's processed that row it won't process it again. You'd have get the second table into an array (e.g. using fetch_all), and then you can re-use the array as many times as you like. But it shouldn't be necessary if you think a bit more about how you could just use the first query's data on its own.
– ADyson
Nov 13 '18 at 12:26
2
The actual problem is that you have a GROUP BY clause but no aggregating functions. Nothing good ever came from this arrangement. Also, NEVER use
SELECT *
– Strawberry
Nov 13 '18 at 12:32