[SOLVED] Extract Record

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

[SOLVED] Extract Record

Post by S_henry »

Let say i have 2 columns for class and student in my table. For example the records is stored in the table like this:

Class | Student
--------------------------------------
A John, Adam, Mike, Henry, Ralf
B Harry, Robert, Kevin, Alex

The column type of class is varchar, student is mediumtext. The problem is how can i list down all the student base on their class? I mean if i choose class A, it will list down all student name (John,...,Ralf) in 5 rows, not in a row. At this moment, i only can display all the name in 1 row. I don't know how to separate all the name. Can anybody help me pls?
Last edited by S_henry on Wed May 18, 2005 2:21 am, edited 1 time in total.
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

do this

Code: Select all

--------------------
Class | StudentName
--------------------
    A | John
    A | Adam
    A | Mike
    A | Henry
    A | Ralf 
    B | Harry
    B | Robert
    B | Kevin
    B | Alex 
--------------------
and everytime you want to extract their names according to their classes:

Code: Select all

// class A
$query = "select * from students where class='A'";
// class B
$query = "select * from students where class='B'";
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Post by S_henry »

At first i also want to do like that. But it definitely can't because if i do like that, the records in the table will exceed the limit. The record that i can store inside the table shouldn't be more than 1000 records. So anybody got any idea to solve this problem pls?
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

S_henry wrote:At first i also want to do like that. But it definitely can't because if i do like that, the records in the table will exceed the limit. ...
why do you have that limit?
why less than 1000?
what database are you using?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

bit of a bummer that limit
I'm assuming you have 2 columns in your table one is class the other is student.

if the data in the student column is stored with ,(commas) between them then when you pull the data out you could always do and explode and get the students into an array or mutli dimensional array.

Code: Select all

$studentArr = explode("," , $row['student']);
once in the array you should be able to do what ever you want with it.
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Post by S_henry »

Actually i'm using MySql database. When i stored the date into the table, the table only can store the data until 1000 records. After that, i can't insert new record anymore. In my opinion, maybe this is the limit in MySql database. Am i right? So i'll try to do as phpScott suggest. I'll be back if still got any problem again. Thanx guys..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

1000 is a very, very, very small limit if it does exist.
Are you sure you cannot post past 1000?
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Post by S_henry »

For me also it is very very small limit. But it does happen at my pc. So i've used phpScott's suggestion to solve the problem and it works.

Code: Select all

$studentArr = explode("," , $row['student']);
Thanx guys. :D
Post Reply