Mysql PHP help ASAP please

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pd_tch
Forum Newbie
Posts: 1
Joined: Thu Oct 25, 2007 12:19 am

Mysql PHP help ASAP please

Post by pd_tch »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

$conn = connect();
			$rollnumber_sql = "SELECT * FROM `studentplus`.`students` WHERE `rollnumber` = '$rollnumber';";
			$rm_res = mysql_query($rollnumber_sql, $conn) or die(mysql_error());
			echo $rm_res;
			$rm = mysql_fetch_array($rm_res);
			print_r($rm);
			$student_id = $rm['id'];
			
		
			
			
			$subject_sql = "SELECT * FROM `studentplus`.`subjects` WHERE `subject` = '$subject';";
			$sub_res = mysql_query($subject_sql, $conn) or die(mysql_error());
			$sub = mysql_fetch_array($sub_res);
			$subject_id = $sub['id'];

I have this database with 2 tables
1. students
2. subjects

both the tables have primary key as 'id'

i want to extract the primary key of the rows corresponding to the rollnumber and the subject name from these tables

ive written the above code but it doesnt seem to work

what might be the problem please help me


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

What is the relation between the two tables? Does the students table have a subject_id or the subject table have a student_id?
(#10850)
Post Reply