Irish SEO,  Marketing & Webmaster Discussion

 

Help needed with php table layout

This is a discussion on Help needed with php table layout within the Coding Help forums, part of the Webmaster Discussion category; Hi all, I’m trying to learn php for a project to make an online schedule for the trainers in our ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Webmaster Discussion > Coding Help

Register Forum Rules FAQDonate Calendar Search Today's Posts Mark Forums Read



Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-09-2007, 07:44 PM
Coder
 
Join Date: Feb 2007
Location: Dublin
Posts: 30
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Thanks: 0
Thanked 0 Times in 0 Posts
Graham will become famous soon enough
Default Help needed with php table layout

Hi all,

I’m trying to learn php for a project to make an online schedule for the trainers in our department.
It will replace a MS Excel workbook and must be able to display the each of the trainer’s names in the first row and underneath each trainer’s name related schedule data should be displayed in a column for each trainer in the following format

|Maria | Graham |
|Date | Date |
|Comments | Comments |
|Date | Date |
|Comments | Comments |


I have two MySQL tables that contain the data that are linked by the trainers, the structure of the tables are as follows

The Trainers Table

+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| ID | int(10) | NO | PRI | NULL | auto_increment |
| Fname | char(10) | NO | | NULL | |
| Lname | char(10) | NO | | NULL | |
+-------+----------+------+-----+---------+----------------+

The Schedule Table

+----------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+-------+
| Sdate | date | NO | | NULL | |
| Trainer | int(10) unsigned | NO | | NULL | |
| Comments | varchar(35) | YES | | NULL | |
+----------+------------------+------+-----+---------+-------+

I’ve tried to work this out but I can’t get the page to display correctly and I was wondering if anyone here could have a look at my code and give me some pointers on where I’m going wrong.

Thanks in advance,

Graham.


Here is my php code

PHP Code:
  <?php
   
  
$db = new mysqli('localhost''**''**''test');
   
  
/* check connection */
  
if (mysqli_connect_errno()) {
      
      echo 
'Sorry cant connect to the database';
      exit();
  }
  else
   
   echo 
'connected';
   
  
$query="SELECT id FROM trainer";
   
  
$result=$db->query($query);
   
  
$query2="SELECT s.Sdate, s.Comments from Scheule s, trainer t where s.trainer = t.id ORDER BY Sdate"
   
  
$result2=$db->query($query2);
   
  echo 
'<p>Number of records:';
  echo 
$result->num_rows;
  echo 
'</p>';
   
  echo 
'<p>Number of records:';
  echo 
$result2->num_rows;
  echo 
'</p>';
   
  if (
$result->num_rows)
   
   {
   
              echo 
'<table border="2">';
              echo 
'<tr>';
              while (
$row $result->fetch_assoc())
              {
              echo 
'<td>';
              echo 
$row['id'];
              echo 
'</td>';
              }
              echo 
'</tr>';
  if (
$result2->num_rows)
  {
              echo 
'<tr>';
              while (
$row2 $result2->fetch_assoc())
              {
              echo 
'<td>';
              echo 
$row2['Sdate'];
              echo 
'<br/>';
              echo 
$row2['Comments'];
              echo 
'</td>';
              echo 
'</tr>';
              }
              echo 
'</table>';
  }
   
  }
   
  
$result->free();
   
  
$db->close();
   
  
?>
__________________
There are two types of people in this world the closed minded ignorant and the open minded learner. Be the latter
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 12-09-2007, 07:56 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,325
Nominated 7 Times in 5 Posts
Nominated TOTW/F/M Award(s): 2
Thanks: 0
Thanked 1 Time in 1 Post
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

wasn't that meant to be ........from Schedule............
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Car Parts & Accessories Car Parts
:. Cars Ireland Cars Ireland
:. I Have 2 Find It Directory SEF Directory
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 12-09-2007, 08:09 PM
Forbairt's Avatar
respect my AW-THOR-IT-AYY
 
Join Date: Jun 2007
Location: My Office, Dublin
Posts: 2,282
Nominated 2 Times in 1 Post
Nominated TOTW/F/M Award(s): 1
Thanks: 2
Thanked 5 Times in 5 Posts
Forbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enough
Send a message via AIM to Forbairt Send a message via MSN to Forbairt Send a message via Yahoo to Forbairt Send a message via Skype™ to Forbairt
Default

tip one ...

copy the database to another database for playing with ...

open up a mysql window and run the commands from the command line ... they give back a lot of info ...

for example .. id and ID .. could be two different things
Trainer .. and trainer ... depending on the setup
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 13-09-2007, 01:46 PM
Coder
 
Join Date: Feb 2007
Location: Dublin
Posts: 30
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Thanks: 0
Thanked 0 Times in 0 Posts
Graham will become famous soon enough
Default

Hi all,

As regard the schedule table I know I typed in incorrectly when setting it up but it is actually called scheule but it is just a test DB to see if I can get things up and running before I set up the project DB. As regard trainer/ Trainer I just typed in the name of the talbe in leading caps out of habit for the post they are all in lower cae in the DB. Sorry if these mistakes are causing ye problems and thanks for the help.

Graham
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 13-09-2007, 01:51 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,325
Nominated 7 Times in 5 Posts
Nominated TOTW/F/M Award(s): 2
Thanks: 0
Thanked 1 Time in 1 Post
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

did u at least get it sorted?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 14-09-2007, 12:06 PM
Coder
 
Join Date: Feb 2007
Location: Dublin
Posts: 30
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Thanks: 0
Thanked 0 Times in 0 Posts
Graham will become famous soon enough
Default

Hi Louie,

No it still won't display correctly for me have to admit I'm a bit over my head here.

I was even trying to get the data out in seperate tables but I can't get it into the format I need it keeps giving me a table for each record in the related tables i.e. four tables for the first trainer and one for the second trainer.

Head banging time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 14-09-2007, 12:17 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,325
Nominated 7 Times in 5 Posts
Nominated TOTW/F/M Award(s): 2
Thanks: 0
Thanked 1 Time in 1 Post
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

lets look at it this way.

you have a master_tbl and a sub_tbl related to the master_tbl by an id.

now all you have to do is

1. query the master_tbl, get all the data available put the master_id into a variable

2. using while... loop, query the sub_tbl filtering by master_id, for any data related to it and if any display it.

3. close loop, and record set

4. close connection
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
layout, needed, php, table

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
PHP, OOPS! data typing Mike Coding Help 2 24-08-2007 02:44 PM
php mysql repeat region Keewee6 Coding Help 7 14-08-2007 05:50 PM
Table layout vs CSS layout ... dbee Coding Help 21 12-07-2007 11:57 AM
WTF - Some PHP Obfuscation. daviddoran General Chat 8 20-02-2007 05:45 PM
PHP on windows louie Coding Help 20 22-02-2006 06:25 PM


Sponsored links

Pepperjam Network
Paid On Results www.zanox.com Get Chitika Premium


All times are GMT +1. The time now is 12:53 PM.


Powered by: vBulletin Version 3.8.4, Copyright ©2000 - 2010, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64