Page 1 of 1
Creating a PHP interface that hits a mySQL backend
Posted: Thu Mar 13, 2008 8:51 am
by MikeX
I have a database that contains names, places, and several other fields.
ID - University Name - Group Name - Website - Email
Now I would like to have a way so that I can choose 'University Name' and have it display all the groups that are a part of that university. Or vice versa. What would you suggest for this?
Thats part 1.
Part 2 coming soon.
Thank you for all your help, I really appreciate it.
Re: Creating a PHP interface that hits a mySQL backend
Posted: Thu Mar 13, 2008 10:54 am
by alex.barylski
I would suggest learning XHTML and PHP.
Honestly, thats a pretty simple request, so I am not sure what your looking for:
Code: Select all
<?php
$uniname = $_GET['uniname'];
$sql = 'SELECT * FROM table WHERE uniname = "'.$uniname.'"
// TODO: Feed above SQL to mysql_query
?>
Code: Select all
<html> <body> <select name="uniname"> <option value="UND">UND</option> <option value="MIT">MIT</option> <option value="McGill">McGill</option> </select> </body></html>
That is the gist of it anyways -- although you'd be better off using PKID's instead of university names when indexing a single record.
Re: Creating a PHP interface that hits a mySQL backend
Posted: Fri Mar 14, 2008 2:26 am
by aaronhall
If groups has a many-to-one relationship to universities, your schema should look something like
Code: Select all
CREATE TABLE universities (
id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE groups (
id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
universityID int(11) UNSIGNED NOT NULL,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
);
SELECT * FROM `groups` WHERE universityID = {{some university id}};