Jump to content
xisto Community
sxyloverboy

Loading Mysql Data Into A Table

Recommended Posts

Hey i have a little problem with my php script. i dont really know how to make it work ^^;

I want to have this exact table: [link] '

 

I made mysql table that has one column for id(auto-increment, primary key), and then it has row and collumn and text. row means which row in the html table and collumn wich collum. (obviously :))

 

here is the mysql table screenshoted from phpMyAdmin:

Posted Image

r means row and c collumn :D

 

anyways somehow i want to load all those datas into the html table....how do i do this? lol.

i tried a few things with a while funciton and some things but my browser always crashed when i opened the page....^^;

 

 

and now you might be asking why do i want to do all this if i can just have a html table? well the answere is that i want to be able to edit the table better. so if you can also tell me how to do this next thing it would be great.

 

i want to have that table but each table cell should have a text area of a form. and then it loads the info from mysql into it and then you can press save if you changed it and then it updates all of the mysql things. the important thing here is that it loads the data that it already has or when it updates all the fields it would just insert blank stuff except where you changed it yourself.

 

i hope you can all understand this and help me with my problem :)

Share this post


Link to post
Share on other sites

Looks to me like you should be looking for a Calendar or Scheduling script which shoud have an Admin section to add/modify/delete entries by date and time. There are already plenty of them available that are written for using with php and mysql. Why re-invent the wheel?Try Hotscripts and the SourceForge sites.

Share this post


Link to post
Share on other sites

Ingenius. Thanks a lot ill look for a claneder thing. Never thought about that. But now for the actual learning effect. How would be a simple way to do this. Well a bit simple anyways. theres nothing simple about php :) im sure all the prefeabricated calender scripts are highly sophisticated and impossible to learn from if you want to learn how to do somehting.

Share this post


Link to post
Share on other sites

A set of nested loops would do it.Look under the php script sub-forum and check out previously posted scripts. I think there have been a couple written for ittsami. Use a SELECT to pull the information sorted by row and column. Use the outer loop to fill the row and the Inner loop to fill each column in that row. An IF statement in the script to check if the cell is empty, etc. Shouldn't be too hard.

Share this post


Link to post
Share on other sites

Like what you say about the learning effect :)

 

I think I understand what you are looking for, have a little try with mysql_fetch_array(), you just have to structure things a little... good explanation at tizag.com.

 

 

Hope that's what you're looking for :)

Share this post


Link to post
Share on other sites

you are making a calendar right?

so if you make a row per month and a table for every year, and make the HTML table just wide enough to get seven days, all you need to do is make the table so that you have ID in one col year in another, month in another, date in a fourth and events in the last.

Then the php script should be simple enough - so long as you define width before looping, you should be fine.
If you have the variables stored in the URL as GET strings, you can have different years, months and days.

<?php//script for one month extraction// Connect to MySQL$table = $_GET['year'];$month = $_GET['month'];echo '<p align="center"> \n '.ucfirst($month).'$nbsp'.$table.'</p> \n \n';echo '<table width="whateverwidthyouneed" border="1"> \n ';echo '<tr> \n ';$result = mysql_query("SELECT * FROM $table WHERE month = $month") or die(mysql_error());while($row = mysql_fetch_array( $result )) {		echo '<td> \n';		echo '<table> \n ';		echo '<tr> \n ';		echo '</td> \n ';		echo $row['date'].' \n ';		echo '</td> \n ';		echo '</tr> \n ';		echo '<tr> \n ';		echo '<td> \n ';		echo $row['event'].' \n ';		echo '</td> \n';		echo '</tr> \n ';		echo '</table> \n ';		echo '</td> \n';}?>

That should do it for the 'month' part....
The only thing is that the page has to be wide enough so that even in 800*600 screen resolution, people can have seven boxes in a row.

Hope that helped :)
Good luck!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.