Page 1 of 1

[56K WARN] Unique Display MYSQL Data

Posted: Sat Aug 20, 2005 4:34 pm
by skyxliner
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.

Image
^ this is what I have so far that actually displays data from the database

Image
^ this is what i'd like it to look like

This is the code that I have of right now

Code: Select all

<?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";
?>
I'm having problem displaying it so that each ID person is displaying their full scheldule routinely one after another


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sat Aug 20, 2005 4:48 pm
by feyd
because of the volume of extra data, I'd perform two seperate queries. One gets the people, the next get's all the period information associated with those people. Cache the results from the period information into an array. I'd use a nested loop, the outside runs over the people as they are returnedm while the inside counts to eight, pulling out associated the period for that person as it goes.

Posted: Sat Aug 20, 2005 7:55 pm
by skyxliner
thanks for taking your time to reply to me,

your reply sounded kind of complicated because i'm just begining to learn mysql and php. but I will google them out and try to learn to try them out....

otherwise could you possibily explain how the ECHO is used correctly to utilize html in php files?

cause i understand you begin html by echo "<br>\n"

but i don't understand if you have to repeat this step for EVERY new line of html or can you quote an entire block of html or how specificly does the ECHO use.

cause i think thats one of the problems i had with trying to figure out the layout.

Posted: Sat Aug 20, 2005 8:52 pm
by feyd
you can realize as much or as little HTML as you wish using echo, provided you create a syntactic string.

Posted: Mon Aug 22, 2005 2:52 am
by skyxliner
for the array, what type of array would i be using.

I'm having trouble getting the array to setup and print correctly

am i trying to use a associative array?

Code: Select all

$period1 = array("subject"=> "$subject1", "teacher"=> "$teacher1", "room"=> "$room1");
$period2 = array("subject"=> "$subject2", "teacher"=> "$teacher2", "room"=> "$room2");

print "Period 1:" . $period1["subject"] . $period1["teacher"] . $period1["room"] . "<br>";
print "Period 2:" . $period2["subject"] . $period2["teacher"] . $period2["room"] . "<br>";
is this kind like it but umm inputing the right tables and loops

how do i display data that is printed once instead of a row of data....

i'm just having a headache over this =/