/    Sign up×
Community /Pin to ProfileBookmark

help with a sql query

I have two tables in my sql database:

Student Table
+—+——-+———–+

|IDl | Name | Status |
+—+——-+———–+

| 1 | Name1 | Active |
| 2 | Name2 | Inactive |

| 3 | Name3 | Pending |

| 4 | Name4 | Dont Know |

| 5 | Name5 | Active |
+—+——-+———–+

and

Info Table
+—+——-+———–+

|ID | GPA | Major |
+—+——-+———–+

| 1 | 3 | CS |
| 2 | 2 | CBE |

| 3 | 3 | CS |

| 4 | 4 | BMS |

| 5 | 2 | CompE |
+—+——-+———–+

so I wan’t to print the name of the people who’s major is CS based on their ID. So in my php code I did this:

$major = mysql_query(“Select ID from Info where Major = ‘CS'”);
$arr = mysql_fetch_array($major);

so $arr now holds the ID of everyone whose major is CS.

Now I want to get their names, but I don’t know how to go through all the ID’s in the $arr.

$names = mysql_query(“Select name from Student where ID = $arr”;

is there a way to do this without changing the tables? thanks.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@pwinfreyApr 26.2011 — [CODE]SELECT s.*, i.* FROM student s, info i WHERE s.id = i.id AND i.major = 'CS';[/CODE]
Copy linkTweet thisAlerts:
@salmanshafiqApr 27.2011 — @pwinfrey has written the perfect query ?
×

Success!

Help @Jabba spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...