Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,238 members, 7,818,801 topics. Date: Monday, 06 May 2024 at 04:20 AM

Post your PHP Problems Here - Webmasters (4) - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Post your PHP Problems Here (63351 Views)

Thread For All Your Blogging Related Problems Here / Get And Request For Your Php Problems Here / Connecting To Your Gmail Account From Your Php Application. (2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (20) (Reply) (Go Down)

Re: Post your PHP Problems Here by dcitizen1: 4:20pm On Oct 13, 2013
If the table contain the following subjects and grade by various student from science, commercial and art , how will i display the result of a student only dat offer science subject and grade. Hope u get me

Example,

Table contain the following field

English: A1

Math

Crk

Accounting:

Physics

And i want to query result for a science student without including the subject for commercial and art student. How will i go by it? Pls, i need ur help
Re: Post your PHP Problems Here by adewasco2k(m): 5:17pm On Oct 13, 2013
^when dealing with database, don't look at it like your normal spreadsheet.

Try normalizing your tables.

There are many ways you can achieve what you seek.

You can have a table holding students details with a column which will signify if a student is a science student, commercial or art also a column for student_id

So on your result table

You should have all results in this format.

Student_id, subjects, mark

So if you a result of a science student, you should not be concern about art, because the student will only have results for subjects he is offering.

So all you have to do is,

SELECT subject, mark FROM results_table WHERE student_id=$x

Now the variable $x hold the student Id from the student details table.

So with such aproach I dnt see you having problems if a student is science student or not.

You might even go further to have a table for subjects, so you have subject_id, subject_name.

So on your result you have a foreign key subject_id. Which will be referencing the subject_id on the subject table.

This looks simple to me, but still I dnt think you are giving key details of what you are doing and what you want to achieve
Re: Post your PHP Problems Here by dcitizen1: 6:12pm On Oct 13, 2013
@ adewasco2k

have u seen a waec broadsheet. It contains result of students dat offer science, commercial and art based subject togther.

I need a clue on how to extract the result of each student without including other subject
. It is not compulsory for all science student or commercial or art to offer the same subject.

. I need a guide pls. i donot need separate table for science, commercial and art students result
Re: Post your PHP Problems Here by adewasco2k(m): 9:05pm On Oct 13, 2013
d citizen:
@ adewasco2k

have u seen a waec broadsheet. It contains result of students dat offer science, commercial and art based subject togther.

I need a clue on how to extract the result of each student without including other subject
. It is not compulsory for all science student or commercial or art to offer the same subject.

. I need a guide pls. i donot need separate table for science, commercial and art students result

That is why I keep seeking more details, I think I understand what you want now.

If I understand you well, you want if for example a science student is to check his result, only science subjects should appear irrespective if he sat for the paper?

That's still simple enough, this are no maggic, you have to signify it. Somewhere on the table.

As I suggested, you should have a table for subjects

So you can have subject_table with columns, subject_id, subject_name, subject_category.

So you can have for example:

Subject_id | subject_name | subject_category. |
1 | physic | 1 |
2 | mathematics | 2 |
3 | commerce | 3 |
4 | government. | 4 |
5 | english | 2 |
6 | lit english | 4 |
I am sorry I am on mobile can't say much but what I am trying to do it set all the subjects into different categories: general, like english and math, art subjects, commercial subjects, science subjects

So when you want to query your database just use LEFT JOIN on the subject where subject.subject_category IN (2, 1 ) for a science student.

Since 2 is for general subject and 1 for sciences.

This is just an eye opener to how you can achieve that, please try to do something then post then we can help from there.
Re: Post your PHP Problems Here by sunday478(m): 11:26pm On Oct 13, 2013
Re: Post your PHP Problems Here by dcitizen1: 7:33am On Oct 14, 2013
@ adewasco2k,

How will i display the subjects and respective grade of each student.

Let me give u a hint of the broadsheet

Id name reg eng mth phy chem govt leng
1 ab 02 a1 b2 c4 b1 nil nil

2 kb 05 b2 c2 nil nil b3 nil

3 ch 07 a1 c1 nil nil b2 a1

I want the table of this result to be query using the reg to display as follow:

Ab

Eng: a1


Mth: b2

Phy: c4
Chem: b1
Re: Post your PHP Problems Here by adewasco2k(m): 7:52am On Oct 14, 2013
^now I know your problem, like I have said before, database is not like excel, you will not get good result from your present design.

But if you insist to carry on with it then use,

SELECT name, eng, math, etc. (List all subjects) FROM results WHERE reg=1 AND (eng, math, etc (list all subjects again)!=NULL

mind you, you will get a column of name, eng, math .....

If you want to have it list you said having all the subjects in a column and not roll then your best bet is PiVOT but as I have said your approach is wrong.

With what I did above you will still achieve your aim, after getting the result in that format, you will use php to arrange it like you want.

If less work on my table today, will code it for you.

Have a wonderful monday
Re: Post your PHP Problems Here by Nobody: 11:47am On Oct 14, 2013
Elvisten10: A demo of this can be found on www.xmx me.com/search.php?string=bank . Remember to change the $url in search.php from www.xmx me.com to www.yourwebsite.com and the $webPage in search.php also from payment.php to the static page you want to search for example index.html.

Thanks Bro.. I'll test run it when am on PC.. That's thoughtful of u..
Re: Post your PHP Problems Here by dcitizen1: 1:24pm On Oct 14, 2013
@ adewasco2k,

Thank you so much but i will like u to send me a format for the table and php based on what i required to my email: francisakwari@hotmail.com. Thanks once again. I look forward to ur response.
Re: Post your PHP Problems Here by Elvisten10(m): 4:55pm On Oct 14, 2013
d citizen:
@ adewasco2k,

Thank you so much but i will like u to send me a format for the table and php based on what i required to my email: francisakwari@hotmail.com. Thanks once again. I look forward to ur response.
I think you should learn mysql or learn more on database, thats the best help you can get. Your view of a database is not just it, you might have some tough time working with adewasco2k solution. @adewasco2k, if possible post the code here, it will help others that might be interested in such now or in the future *grins*.
Re: Post your PHP Problems Here by Elvisten10(m): 4:57pm On Oct 14, 2013
Djangocode:

Thanks Bro.. I'll test run it when am on PC.. That's thoughtful of u..
ok, inform me when you are done and maybe a link to the site.
Re: Post your PHP Problems Here by Nobody: 6:00pm On Oct 14, 2013
Elvisten10: ok, inform me when you are done and maybe a link to the site.

Am Running On Localhost though..(Wamp Things)..

Will get back to u..
Re: Post your PHP Problems Here by adewasco2k(m): 11:46pm On Oct 14, 2013
^^I did it, major work was just on the database design, had to even to 'over normalization' to show him how it works working with such.

I will share results tomorrow morning when connected via PC.
Re: Post your PHP Problems Here by Elvisten10(m): 10:27am On Oct 15, 2013
Djangocode:

Am Running On Localhost though..(Wamp Things)..

Will get back to u..
ok
Re: Post your PHP Problems Here by adewasco2k(m): 12:29pm On Oct 15, 2013
This is so long, i hope you get it, just trying to show you all you might need to know and i didnt do any php, just the database stuff, that is what you first need to get right.

I will take it step by step.

STEP 1 created a database "resultChecker"
CREATE DATABASE resultChecker;


STEP 2 creating tables in the database

i. create table in the database 'categories'

CREATE TABLE IF NOT EXISTS `categories` 
(
`catID` int(11) NOT NULL AUTO_INCREMENT,
`desc` varchar(200) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;


We need to add some dummy contents to work with:

INSERT INTO `categories` 
(`catID`, `desc`)
VALUES
(1, 'general'),
(2, 'commercial'),
(3, 'arts'),
(4, 'sciences');




ii. created table in database 'subjects'

CREATE TABLE IF NOT EXISTS `subjects`
(
`stubjectID` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`cat_id` int(11) NOT NULL,
KEY `categories` (`cat_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;


add foreign keys, may be you should read about foreign keys

ALTER TABLE `subjects`
ADD CONSTRAINT `subjects_ibfk_1`
FOREIGN KEY (`cat_id`) REFERENCES `categories` (`catID`) ON DELETE CASCADE ON UPDATE CASCADE;


to add dummy content:

INSERT INTO `subjects` (`stubjectID`, `name`, `cat_id`) 
VALUES
(1, 'english language', 1),
(2, 'mathematics', 1),
(3, 'chemistry', 4),
(4, 'physics', 4),
(5, 'commerce', 2),
(6, 'geographic', 2),
(7, 'government', 3),
(8, 'Literature in English', 3);




iii.created a table in database 'students'


CREATE TABLE IF NOT EXISTS `students` 
(
`studentID` int(11) NOT NULL AUTO_INCREMENT,
`sname` varchar(250) NOT NULL,
`cat_id` int(11) NOT NULL,
`reg_no` varchar(20) NOT NULL,
`year` year(4) NOT NULL,
`center` varchar(200) NOT NULL,
KEY `cat_id` (`cat_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;


add foreign key:

ALTER TABLE `students`
ADD CONSTRAINT `students_ibfk_1`
FOREIGN KEY (`cat_id`) REFERENCES `categories` (`catID`) ON DELETE CASCADE ON UPDATE CASCADE;


add dummy content:

INSERT INTO `students` (`studentID`, `sname`, `cat_id`, `reg_no`, `year`, `center`) 
VALUES
(1, 'Dale Samuel Daniel', 4, '4012344FG', 2013, 'Ajah, Lagos'),
(2, 'Jane Django', 2, '4012347HG', 2013, 'Ikeja, Lagos'),
(3, 'Seun Kamorudeen lol', 3, '4012387DF', 2013, 'Ota, Ogun');




iv. created a table called 'results'

CREATE TABLE IF NOT EXISTS `results` 
(
`student_id` int(11) NOT NULL,
`subject_id` int(11) NOT NULL,
`grade` varchar(2) NOT NULL,
KEY `student_id` (`student_id`),
KEY `subject_id` (`subject_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


add foreign key:

ALTER TABLE `results`
ADD CONSTRAINT `results_ibfk_4`
FOREIGN KEY (`subject_id`) REFERENCES `subjects` (`stubjectID`) ON DELETE CASCADE ON UPDATE CASCADE,

ADD CONSTRAINT `results_ibfk_3`
FOREIGN KEY (`student_id`) REFERENCES `students` (`studentID`) ON DELETE CASCADE ON UPDATE CASCADE;


to add contents:

INSERT INTO `results` (`student_id`, `subject_id`, `grade`) 
VALUES
(1, 1, 'C4'),
(1, 2, 'C6'),
(1, 3, 'E8'),
(1, 4, 'F9'),
(2, 1, 'F9'),
(2, 2, 'E8'),
(2, 6, 'C4'),
(2, 5, 'C5'),
(3, 1, 'C4'),
(3, 2, 'F9'),
(3, 7, 'E8'),
(3, 8, 'D7');




This shows the relationship between the tables:


with all these all you need to do is query your tables to get all you want.

example 1 to get the results of student with studentID of 2 which is 'Jane Django'

SELECT subjects.name, results.grade FROM subjects, results
WHERE subjects.stubjectID=results.subject_id
AND results.student_id=2


result:


example 2 to get the result of a student with a name seun who is the art student here

SELECT subjects.name, results.grade FROM subjects, results WHERE subjects.stubjectID=results.subject_id
AND results.student_id=(SELECT students.studentID FROM students WHERE students.sname LIKE ('%seun%'))


results:


example 3 to get the details of a student like year of exam, exam center and registration number using his name to find it or his reg no

SELECT * FROM students WHERE sname LIKE('%seun%')


or

SELECT * FROM students WHERE reg_no='4012387DF'


results


example 4: you can equally get the list of subjects that the student offers and the corresponding grades even if the student didnt write the exam.

//for example if a science student didnt write chemistry exam the result will be like

english  | C6
math | E8
chemistry| NULL
physics | F9


here i have delete the physic result of the science student, see how i will query the table now using LEFT JOIN:

SELECT subjects.name, results.grade FROM subjects 
LEFT JOIN results ON subjects.stubjectID=results.subject_id
AND results.student_id=1
WHERE subjects.cat_id IN((SELECT cat_id FROM students WHERE studentID=1),1)


result:


so now you have your database all you have to do is add more details to the table as you wish i just did it simple to make it clearer.

cheers

1 Like

Re: Post your PHP Problems Here by adewasco2k(m): 12:45pm On Oct 15, 2013
^ anything that you dont understand just ask, will explain further
my assumptions which may or may not be correct

1. science students offers chemistry and physic
2. art students offers government and literature in english
3. commercial students offers commerce and geography
4. english and mathematucs is a general subject
Re: Post your PHP Problems Here by sunday478(m): 10:34am On Oct 16, 2013
adewasco2k: ^ anything that you dont understand just ask, will explain further
my assumptions which may or may not be correct

1. science students offers chemistry and physic
2. art students offers government and literature in english
3. commercial students offers commerce and geography
4. english and mathematucs is a general subject
^^ this question may reveal how mediocre I am but I want to know. At ur previos post of those code and pics, is it that u are using a software or is it the codes that that brought the Edit, copy ETC. I want to learn how to work with Dbase.
Re: Post your PHP Problems Here by adewasco2k(m): 10:55am On Oct 16, 2013
sunday478:
^^ this question may reveal how mediocre I am but I want to know. At ur previos post of those code and pics, is it that u are using a software or is it the codes that that brought the Edit, copy ETC. I want to learn how to work with Dbase.

Just as I said, I did it on MySQL database alone, so that is just the interface of MySQL database.

Install XAMPP it has MySQL, filezilla, apache and other cool stuffs.

When working on such projects 70% of concentration should be on the database, if you get the database right then you can always manipulate it any how to send data to the view part of the project.

Like in the above example I made all the guy need to do is put those data into an array then use foreach() function to display them
Re: Post your PHP Problems Here by dcitizen1: 7:17pm On Oct 16, 2013
Thanks adewasco2k,

I get ur hint dat u have given to me but i will try and learn more on mysql database.

I need more help. I want you to guide me in creating a php code for a registration form dat extend to two page or more pages with next on each page and with submit button on last page. But i want the data to be submitted to a table in the data base register. Need ur insight pls.
Re: Post your PHP Problems Here by adewasco2k(m): 9:15pm On Oct 16, 2013
d citizen:
Thanks adewasco2k,

I get ur hint dat u have given to me but i will try and learn more on mysql database.

I need more help. I want you to guide me in creating a php code for a registration form dat extend to two page or more pages with next on each page and with submit button on last page. But i want the data to be submitted to a table in the data base register. Need ur insight pls.

You don't need to worry too much on that just use jquery UI's Tab that will work the magic
Re: Post your PHP Problems Here by Elvisten10(m): 9:25pm On Oct 16, 2013
d citizen:
Thanks adewasco2k,

I get ur hint dat u have given to me but i will try and learn more on mysql database.

I need more help. I want you to guide me in creating a php code for a registration form dat extend to two page or more pages with next on each page and with submit button on last page. But i want the data to be submitted to a table in the data base register. Need ur insight pls.
ok then, am not a html guy.
Re: Post your PHP Problems Here by adewasco2k(m): 9:53pm On Oct 16, 2013
^@Elvis what I think is is try to achieve is let say page 1 carries name, age and date of birth page 2 carries class, height and page 3 carries parent's name, occupation then on page 3 you click submit and all data typed in on page 1,2,3 now stored on the database with a single SQL statement.

That can be achieve like this, they are viewed as pages but actually they are not, the three categories of form will be in three different div's with next button on page1 and page2 and submit on page3

On first view div2 and div 3 are hidden only div 1 shown, when you click on next button on div 1, div 1 becomes hidden and div2 visible when you click on next button on div2 the final div3 shows and all others hidden now there is a submit button when clicked the POST/GET holds all typed data on div1,div2 and div3 so now you can submit it.
Re: Post your PHP Problems Here by dcitizen1: 1:06am On Oct 17, 2013
@ adewasco2kYes, dat is exactly what i intend to achieve. I will like you to help me out
Re: Post your PHP Problems Here by sunday478(m): 12:51pm On Oct 17, 2013
adewasco2k:

Just as I said, I did it on MySQL database alone, so that is just the interface of MySQL database.

Install XAMPP it has MySQL, filezilla, apache and other cool stuffs.

When working on such projects 70% of concentration should be on the database, if you get the database right then you can always manipulate it any how to send data to the view part of the project.

Like in the above example I made all the guy need to do is put those data into an array then use foreach() function to display them
my boss, btween Wam and XAMPP which should I downlaod. Because someone suggest wamp and u suggested xampp.
Re: Post your PHP Problems Here by Nobody: 2:38pm On Oct 17, 2013
sunday478: my boss, btween Wam and XAMPP which should I downlaod. Because someone suggest wamp and u suggested xampp.

U can use wamp or xampp.. They are all the same thing.. I use wamp.. When u download and install, Change ur browser homepage to http://localhost.

When u start the wamp server, wait for the icon to turn green.. Then click on it and select "Start all Services".. After that, open yo browser and type localhost on the address bar if u have not set the homepage to localhost already..

Yo PhP files should be saved in the C - wamp - www folder..

Assuming u create a script like

<?php
$wand = Success;
echo $wand;
?>

Save this as wand.php or anything u like and copy the file to the www folder inside the wamp installation directory..

Then go to the browser and type http://localhost/wand.php and u'll see Success on the page..

Hope u Understand..
Re: Post your PHP Problems Here by sunday478(m): 3:57pm On Oct 17, 2013
^^Yeah, I understand. Just the wampXamp stuff now. Am yet to download it.
Re: Post your PHP Problems Here by adewasco2k(m): 7:50pm On Oct 17, 2013
^you can go for any, they will all deliver what you want, I have both on my pc but I make use of xampp
Re: Post your PHP Problems Here by sunday478(m): 2:18pm On Oct 18, 2013
adewasco2k: ^you can go for any, they will all deliver what you want, I have both on my pc but I make use of xampp
ok, thanks
Re: Post your PHP Problems Here by bowofolu(m): 3:11pm On Oct 18, 2013
I have problems making upload scripts. Can you help me on that.

I don't have a good knowledge of php. How do i learn php.
Re: Post your PHP Problems Here by dexed(m): 6:44pm On Oct 18, 2013
d citizen:
Jst what the detailed page to display the result of each student in this format

Name: xyz

Year: 2009

class : ss

Result

Physics: A1

Chemistry : B2
mathematic:

English:

Biology:

After query is done tru filter search detail with name and year. I need hint , pls
You need to create the following tables,
1. Students
2. Results
The students table will contain these columns:
id [ int(9) ] auto increment not null
firstname [ varchar(30) ] not null
lastname [ varchar(30) ] not null
middlename [ varchar(30) ]
school [ varchar(255) ]
department [ enum('science','commercial','arts') ]
*and any other necessary info(columns) regarding a student using ur app

Results table:
id [ int(9) ] auto increment not null
studentid [ int(9) ] not null
exam [ enum('gce','waec','sat','blablabla') default(waec) ]
course [ varchar(30) ]
year [ int(4) ]
grade [ varchar(15) default(pending) ]

You can query the tables like so:
<?php
//initialise n connect to your database or load db class
//Supposing we have our name from a form sent by post
$fname=$_POST['fname'];
$lname=$_POST['lname'];
//filter the variables to check if they r the xpected 4mat

$stud_result_q="SELECT re.*
FROM results re
LEFT JOIN students st on re.studentid=st.id
WHERE st.firstname='$fname'
AND st.lastname='$lname'";
/*Run the query on ur database and use mysql_fetch_assoc or equiv db class method, you can use a while loop to process the results
you can also refine the sql for year, passed courses, pending courses etc.*/

?>

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (20) (Reply)

Add More Than One Website Url To Your Twitter Account. / Top Google Searches By Nigerians 2015;Arsenal,Buhari,Diezani Arrest tops d list. / Mark Zuckerberg Eating Pounded Yam And Eforiro (Photo)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 103
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.