/    Sign up×
Community /Pin to ProfileBookmark

Unique Display MYSQL Data

Background: ok so i would like to collect data from students of their information and also their class scheldules.

Problem: I managed to display everything perfectly. The only problem is displaying the scheldules in a decent viewable way. If anyone knows a better way to display class scheldules please let me know.

[img]http://img374.imageshack.us/img374/7537/current3cs.jpg[/img]
^ this is what I have so far that actually displays data from the database

[img]http://img374.imageshack.us/img374/1967/ideal9bi.jpg[/img]
^ this is what i’d like it to look like

This is the code that I have of right now

[code]<?PHP
$query = “SELECT * FROM _app ORDER BY id “;
$result = mysql_query($query) or die (“Query failed”);
//let’s get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);

?>

<?PHP
echo “<TABLE BORDER=”1″ cellpadding=”3″ >n”;

echo “<TR bgcolor=”lightgreen”><TD>ID:</TD><TD>IP Address:</TD><TD>Date:</TD><TD>Name:</TD><TD>Birthday:</TD><TD>Class Of:</TD><TD>Shirt Size:</TD><TD>GPA:</TD><TD>Periods:</TD><TD>Subject:</TD><TD>Teacher:</TD><TD>Room:</TD></TR>n”;

for($i = 0; $i < $numofrows; $i++) {

$row = mysql_fetch_array($result); //get a row from our result set

if($i % 2) { //this means if there is a remainder

echo “<TR bgcolor=”lightblue”>n”;

} else { //if there isn’t a remainder we will do the else

echo “<TR bgcolor=”white”>n”;

}

echo “<TD>”.$row[‘id’].”</TD><TD>”.$row[‘ip’].”</TD><TD>”.$row[‘date’].”</TD><TD>”.$row[‘fname’].” “.$row[‘lname’].”</TD><TD>”.$row[‘bday’].”</TD><TD>”.$row[‘class’].”</TD><TD>”.$row[‘shirt’].”</TD><TD>”.$row[‘gpa’].”</TD><TD>”.$row[‘sdfsfd’].”</TD></Tr>n”;

echo “</TR>n”;
}

//now let’s close the table and be done with it
echo “</TABLE>n”;
?> [/code]

I’m having problem displaying it so that each ID person is displaying their full scheldule routinely one after another

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@cyber1Aug 21.2005 — skyxliner-

The following code will build your table;

I'll let you figure out how to populate it with the real data.

-Bill

[code=php]<?PHP
#$query = "SELECT * FROM _app ORDER BY id ";
#$result = mysql_query($query) or die ("Query failed");
#//let's get the number of rows in our result so we can use it in a for loop
#$numofrows = mysql_num_rows($result);
$numofrows = 2;
$additional_cells = 8;


print "<table border="1" cellpadding="3" >n";
print <<<HTML
<tr bgcolor="lightgreen">
<td>ID:</td>
<td>IP Address:</td>
<td>Date:</td>
<td>Name:</td>
<td>Birthday:</td>
<td>Class Of:</td>
<td>Shirt Size:</td>
<td>GPA:</td>
<td>Periods:</td>
<td>Subject:</td>
<td>Teacher:</td>
<td>Room:</td>n</tr>

HTML;

for($i = 0; $i < $numofrows; $i++) {
print "<tr bgcolor="white">
<td align="left" valign="top" rowspan="$additional_cells">id i=$i".$row['id']."</td>
<td align="left" valign="top" rowspan="$additional_cells">ip i=$i".$row['ip']."</td>
<td align="left" valign="top" rowspan="$additional_cells">date i=$i".$row['date']."</td>
<td align="left" valign="top" rowspan="$additional_cells">fname i=$i".$row['fname']." ".$row['lname']."</td>
<td align="left" valign="top" rowspan="$additional_cells">bday i=$i".$row['bday']."</td>
<td align="left" valign="top" rowspan="$additional_cells">class i=$i".$row['class']."</td>
<td align="left" valign="top" rowspan="$additional_cells">shirt i=$i".$row['shirt']."</td>
<td align="left" valign="top" rowspan="$additional_cells"> gpa i=$i".$row['gpa']."</td></td>n</tr>n";


for($x = 0; $x < $additional_cells-1; $x++) {
print "<tr>
<td> $x</td>
<td> 'Subject'</td>
<td> 'Teacher'</td>
<td> 'Room'</td>n</tr>n";
}
}
print "</table>n";
?>
[/code]
Copy linkTweet thisAlerts:
@skyxlinerauthorAug 21.2005 — its not retreiving any of the data though..not sure why..

gpa i=$i" seems to be causing the problem?



--------

edited: got it to display, needed to add the $row variable

one question... gpa i=$i <-- what is the point of that?
Copy linkTweet thisAlerts:
@cyber1Aug 21.2005 — its not retreiving any of the data though..not sure why..

gpa i=$i" seems to be causing the problem?



--------

edited: got it to display, needed to add the $row variable

one question... gpa i=$i <-- what is the point of that?[/QUOTE]



All those are simply markers to make sure the table was built correctly.

Being I don't know what your database looks like, all I can do is show you how to build the table.

You'll have to populate it with the row data.

-Bill
Copy linkTweet thisAlerts:
@skyxlinerauthorAug 21.2005 — yeah i just removed them and it worked perfectly,

the thing is that it doesn't update the scheldule correctly because my databasing is entered by subject1,teacher1,room1, subject2,ect...

it just makes all the subjects the same as of right now...

i think what i'm looking for is to create another output in a differen't format?

http://www.weberdev.com/ViewArticle-371.html seems to be right but the link to their tutorial isn't workin rite now =/
Copy linkTweet thisAlerts:
@cyber1Aug 22.2005 — yeah i just removed them and it worked perfectly,

the thing is that it doesn't update the scheldule correctly because my databasing is entered by subject1,teacher1,room1, subject2,ect...

it just makes all the subjects the same as of right now...

i think what i'm looking for is to create another output in a differen't format?

http://www.weberdev.com/ViewArticle-371.html seems to be right but the link to their tutorial isn't workin rite now =/[/QUOTE]



Why not have 2 tables in your mysql DB?

The first one would contain the personal data and then the second would contain the the periods,subjects, teacher and room and the ID field would be the lookup up key.

So as you go through the first 'for loop' of building the HTML table you would then look up in the second mysql table the data for the ID in the second 'for loop'.

-Bill
Copy linkTweet thisAlerts:
@skyxlinerauthorAug 23.2005 — yeah i've been trying to try arrays and nested for loops...

but then for the loop on the "inside" right. isn't it hard to display like one variable at a time and then loop the entire scheldule for each student...

because from what i've been doing, its been turning out like

Subject 1

math

math

math

math

math

its like stuck on one variable down the list instead of finding other variables like, subject1, subject2
Copy linkTweet thisAlerts:
@cyber1Aug 23.2005 — Could you post your code you've got so far?

DB structure and some sample data?

This should not be that difficult to do.

-bill
Copy linkTweet thisAlerts:
@skyxlinerauthorAug 23.2005 — hi everyone, I was finally able to figure it out with the good help of someone else for pointing something out that was so obvious. basiclly I just inserted a new table for each one. I'm posting the code incase anyone is interested in this learning experience that i also had =P

[code=php]<?PHP
//selecting queries
$query = "SELECT * FROM _app ORDER BY id ";
$result = mysql_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);



?>


<?PHP
echo "<TABLE BORDER="1" cellpadding="3" >n";

//creating top labels of the display table
// bgcolor is the top label background color
echo "<TR bgcolor="lightgreen"><TD>ID:</TD><TD>IP Address:</TD><TD>Date:</TD><TD>Name:</TD><TD>Birthday:</TD><TD>Class Of:</TD><TD>Shirt Size:</TD><TD>GPA:</TD><TD>Periods:</TD><TD>Subject:</TD><TD>Teacher:</TD><TD>Room:</TD></TR>n";

/* what this does is provide an alternating color rows
* I found this on some online tutorial so credit to them.
*/

for($i = 0; $i < $numofrows; $i++) {

$row = mysql_fetch_array($result); //get a row from our result set

if($i % 2) { //this means if there is a remainder

//color choice 1 to alternate
echo "<TR bgcolor="lightblue">n";

} else { //if there isn't a remainder we will do the else

//color choice 2 to alternate
echo "<TR bgcolor="white">n";

}

//Start off with the basic student info. Pulling normal data from the database in rows
echo "<TD>" . $row['id'] ."</TD><TD>" . $row['ip'] .
"</TD><TD>" . $row['date'] . "</TD><TD>" . $row['fname'] . " ". $row['lname'] . "</TD><TD>" . $row['bday'] ."</TD><TD>" .
$row['class'] . "</TD><TD>" . $row['shirt'] . "</TD><TD>" . $row['gpa'] .
"</TD>" ;

/* Now we can display the Class info. We'll use a nested table for now.
* You can try something else if you want. Here's where the single-table
* design becomes a pain. I've written the code for a single period. You'll
* have to cut and paste this an additional seven times to get all your
* class information for 8 periods, since you have to
* iterate through all your "teacherX", "subjectX", "roomX", etc. fields.
* Don't forget to change the number in the field name to match the Period.
*/

echo "<TD><table border="0">" ;

/* Here's the stuff you'll have to copy for each period. */
echo "<TR><TD>1</TD></TR>" ;
echo "<TR><TD>2</TD></TR>" ;
echo "<TR><TD>3</TD></TR>" ;
echo "<TR><TD>4</TD></TR>" ;
echo "<TR><TD>5</TD></TR>" ;
echo "<TR><TD>6</TD></TR>" ;
echo "<TR><TD>7</TD></TR>" ;
echo "<TR><TD>8</TD></TR>" ;

/* End of period data.

/* Now end this inner "period" table. */
echo "</table>n" ;

echo "<TD><table border="0">" ;

/* Here's the stuff you'll have to copy for each subject. */
echo "<TR><TD>" . $row['subject1'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['subject2'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['subject3'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['subject4'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['subject5'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['subject6'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['subject7'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['subject8'] . "</TD></TR>" ;

/* End of subject data.

/* Now end this inner "subject" table. */
echo "</table>n" ;

echo "<TD><table border="0">" ;

/* Here's the stuff you'll have to copy for each teacher. */
echo "<TR><TD>" . $row['teacher1'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['teacher2'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['teacher3'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['teacher4'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['teacher5'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['teacher6'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['teacher7'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['teacher8'] . "</TD></TR>" ;


/* End of teacher data.

/* Now end this inner "teacher" table. */
echo "</table>n" ;

echo "<TD><table border="0">" ;

/* Here's the stuff you'll have to copy for each room. */
echo "<TR><TD>" . $row['room1'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['room2'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['room3'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['room4'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['room5'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['room6'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['room7'] . "</TD></TR>" ;
echo "<TR><TD>" . $row['room8'] . "</TD></TR>" ;

/* End of room data.

/* Now end this inner "room" table. */
echo "</table>n" ;

/* Now end our row, which is all the info for a single student. */
echo "</TD></TR>n";
}

//now let's close the table and be done with it
echo "</TABLE>n";
?> [/code]


[URL=http://img377.imageshack.us/img377/9646/untitled7ac.jpg]http://img377.imageshack.us/img377/9646/untitled7ac.jpg[/URL]
×

Success!

Help @skyxliner spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...