when i pull out primary keys from my data-base they come out bracketed and i cant use them later in my code
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
import mysql.connector
config = {
'user': 'root',
'password': '*******',
'host': '127.0.0.1',
'database': 'mydb',
'raise_on_warnings': True
}
pupilids=("SELECT idpupil FROM pupil Where Hm_idhm = 'GJM'")
cursor.execute(pupilids)
v=cursor.fetchall()
v=str(v)
this is a part of my code from a much larger prodject but in essence i need to take this list of values that come when i executed this and put it into another query one by one.
list:
[(1525,), (1565,), (1588,)]
but when i put it into the query
global pupilids
global B
print(pupilids[0])
Pupil_name = ("SELECT Name, house, hm_idhm from Pupil Where idpupil ='"+str(pupilids[0])+"'")
cursor.execute(Pupil_name)
v=cursor.fetchall()
print(v)
showinfo("Window", v )
nothing comes up because of the brackets in the list. is there any way i could fix this or am i screwed. any help would be greatly apriciated and if you need any more info i can supply
for refrence when i run it in a sql shell it produces this:
+---------+
| idpupil |
+---------+
| 1525 |
| 1565 |
| 1588 |
+---------+
python mysql mysql-python
add a comment |
import mysql.connector
config = {
'user': 'root',
'password': '*******',
'host': '127.0.0.1',
'database': 'mydb',
'raise_on_warnings': True
}
pupilids=("SELECT idpupil FROM pupil Where Hm_idhm = 'GJM'")
cursor.execute(pupilids)
v=cursor.fetchall()
v=str(v)
this is a part of my code from a much larger prodject but in essence i need to take this list of values that come when i executed this and put it into another query one by one.
list:
[(1525,), (1565,), (1588,)]
but when i put it into the query
global pupilids
global B
print(pupilids[0])
Pupil_name = ("SELECT Name, house, hm_idhm from Pupil Where idpupil ='"+str(pupilids[0])+"'")
cursor.execute(Pupil_name)
v=cursor.fetchall()
print(v)
showinfo("Window", v )
nothing comes up because of the brackets in the list. is there any way i could fix this or am i screwed. any help would be greatly apriciated and if you need any more info i can supply
for refrence when i run it in a sql shell it produces this:
+---------+
| idpupil |
+---------+
| 1525 |
| 1565 |
| 1588 |
+---------+
python mysql mysql-python
If you run your querySELECT idpupil FROM pupil Where Hm_idhm = 'GJM'
on a standalone MySQL client program rather than from inside python, what do you get? Please edit your question to tell us.
– O. Jones
Jan 3 at 15:40
sorry took me while to figure out how to do
– Zach Creagh-Coen
Jan 3 at 16:17
What do you see if you print thePupil_name
text string containing your query? You want it to saySELECT Name, house, hm_idhm from Pupil Where idpupil ='1525'
, I believe. But it should actually saySELECT Name, house, hm_idhm from Pupil Where idpupil =1525
because you don't need'
quotes around numbers.
– O. Jones
Jan 3 at 17:34
I actually figured it out in a similar way I just added one more variable and it was fine I just need to specify when I’m using the list but thank you for the help
– Zach Creagh-Coen
Jan 3 at 17:36
add a comment |
import mysql.connector
config = {
'user': 'root',
'password': '*******',
'host': '127.0.0.1',
'database': 'mydb',
'raise_on_warnings': True
}
pupilids=("SELECT idpupil FROM pupil Where Hm_idhm = 'GJM'")
cursor.execute(pupilids)
v=cursor.fetchall()
v=str(v)
this is a part of my code from a much larger prodject but in essence i need to take this list of values that come when i executed this and put it into another query one by one.
list:
[(1525,), (1565,), (1588,)]
but when i put it into the query
global pupilids
global B
print(pupilids[0])
Pupil_name = ("SELECT Name, house, hm_idhm from Pupil Where idpupil ='"+str(pupilids[0])+"'")
cursor.execute(Pupil_name)
v=cursor.fetchall()
print(v)
showinfo("Window", v )
nothing comes up because of the brackets in the list. is there any way i could fix this or am i screwed. any help would be greatly apriciated and if you need any more info i can supply
for refrence when i run it in a sql shell it produces this:
+---------+
| idpupil |
+---------+
| 1525 |
| 1565 |
| 1588 |
+---------+
python mysql mysql-python
import mysql.connector
config = {
'user': 'root',
'password': '*******',
'host': '127.0.0.1',
'database': 'mydb',
'raise_on_warnings': True
}
pupilids=("SELECT idpupil FROM pupil Where Hm_idhm = 'GJM'")
cursor.execute(pupilids)
v=cursor.fetchall()
v=str(v)
this is a part of my code from a much larger prodject but in essence i need to take this list of values that come when i executed this and put it into another query one by one.
list:
[(1525,), (1565,), (1588,)]
but when i put it into the query
global pupilids
global B
print(pupilids[0])
Pupil_name = ("SELECT Name, house, hm_idhm from Pupil Where idpupil ='"+str(pupilids[0])+"'")
cursor.execute(Pupil_name)
v=cursor.fetchall()
print(v)
showinfo("Window", v )
nothing comes up because of the brackets in the list. is there any way i could fix this or am i screwed. any help would be greatly apriciated and if you need any more info i can supply
for refrence when i run it in a sql shell it produces this:
+---------+
| idpupil |
+---------+
| 1525 |
| 1565 |
| 1588 |
+---------+
python mysql mysql-python
python mysql mysql-python
edited Jan 3 at 16:17
Zach Creagh-Coen
asked Jan 3 at 15:10
Zach Creagh-CoenZach Creagh-Coen
33
33
If you run your querySELECT idpupil FROM pupil Where Hm_idhm = 'GJM'
on a standalone MySQL client program rather than from inside python, what do you get? Please edit your question to tell us.
– O. Jones
Jan 3 at 15:40
sorry took me while to figure out how to do
– Zach Creagh-Coen
Jan 3 at 16:17
What do you see if you print thePupil_name
text string containing your query? You want it to saySELECT Name, house, hm_idhm from Pupil Where idpupil ='1525'
, I believe. But it should actually saySELECT Name, house, hm_idhm from Pupil Where idpupil =1525
because you don't need'
quotes around numbers.
– O. Jones
Jan 3 at 17:34
I actually figured it out in a similar way I just added one more variable and it was fine I just need to specify when I’m using the list but thank you for the help
– Zach Creagh-Coen
Jan 3 at 17:36
add a comment |
If you run your querySELECT idpupil FROM pupil Where Hm_idhm = 'GJM'
on a standalone MySQL client program rather than from inside python, what do you get? Please edit your question to tell us.
– O. Jones
Jan 3 at 15:40
sorry took me while to figure out how to do
– Zach Creagh-Coen
Jan 3 at 16:17
What do you see if you print thePupil_name
text string containing your query? You want it to saySELECT Name, house, hm_idhm from Pupil Where idpupil ='1525'
, I believe. But it should actually saySELECT Name, house, hm_idhm from Pupil Where idpupil =1525
because you don't need'
quotes around numbers.
– O. Jones
Jan 3 at 17:34
I actually figured it out in a similar way I just added one more variable and it was fine I just need to specify when I’m using the list but thank you for the help
– Zach Creagh-Coen
Jan 3 at 17:36
If you run your query
SELECT idpupil FROM pupil Where Hm_idhm = 'GJM'
on a standalone MySQL client program rather than from inside python, what do you get? Please edit your question to tell us.– O. Jones
Jan 3 at 15:40
If you run your query
SELECT idpupil FROM pupil Where Hm_idhm = 'GJM'
on a standalone MySQL client program rather than from inside python, what do you get? Please edit your question to tell us.– O. Jones
Jan 3 at 15:40
sorry took me while to figure out how to do
– Zach Creagh-Coen
Jan 3 at 16:17
sorry took me while to figure out how to do
– Zach Creagh-Coen
Jan 3 at 16:17
What do you see if you print the
Pupil_name
text string containing your query? You want it to say SELECT Name, house, hm_idhm from Pupil Where idpupil ='1525'
, I believe. But it should actually say SELECT Name, house, hm_idhm from Pupil Where idpupil =1525
because you don't need '
quotes around numbers.– O. Jones
Jan 3 at 17:34
What do you see if you print the
Pupil_name
text string containing your query? You want it to say SELECT Name, house, hm_idhm from Pupil Where idpupil ='1525'
, I believe. But it should actually say SELECT Name, house, hm_idhm from Pupil Where idpupil =1525
because you don't need '
quotes around numbers.– O. Jones
Jan 3 at 17:34
I actually figured it out in a similar way I just added one more variable and it was fine I just need to specify when I’m using the list but thank you for the help
– Zach Creagh-Coen
Jan 3 at 17:36
I actually figured it out in a similar way I just added one more variable and it was fine I just need to specify when I’m using the list but thank you for the help
– Zach Creagh-Coen
Jan 3 at 17:36
add a comment |
0
active
oldest
votes
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%2f54024954%2fwhen-i-pull-out-primary-keys-from-my-data-base-they-come-out-bracketed-and-i-can%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f54024954%2fwhen-i-pull-out-primary-keys-from-my-data-base-they-come-out-bracketed-and-i-can%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
If you run your query
SELECT idpupil FROM pupil Where Hm_idhm = 'GJM'
on a standalone MySQL client program rather than from inside python, what do you get? Please edit your question to tell us.– O. Jones
Jan 3 at 15:40
sorry took me while to figure out how to do
– Zach Creagh-Coen
Jan 3 at 16:17
What do you see if you print the
Pupil_name
text string containing your query? You want it to saySELECT Name, house, hm_idhm from Pupil Where idpupil ='1525'
, I believe. But it should actually saySELECT Name, house, hm_idhm from Pupil Where idpupil =1525
because you don't need'
quotes around numbers.– O. Jones
Jan 3 at 17:34
I actually figured it out in a similar way I just added one more variable and it was fine I just need to specify when I’m using the list but thank you for the help
– Zach Creagh-Coen
Jan 3 at 17:36