Creating a PHP interface that hits a mySQL backend

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
MikeX
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2008 8:50 am

Creating a PHP interface that hits a mySQL backend

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Creating a PHP interface that hits a mySQL backend

Post by alex.barylski »

I would suggest learning XHTML and PHP. :P

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.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Re: Creating a PHP interface that hits a mySQL backend

Post 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}};
Post Reply