Page 1 of 1

Tables/Database/Php

Posted: Thu Mar 06, 2003 12:37 am
by ecks
not sure if this is where to post this but here it goes...

ok i have a page here that i want all of the things on it to be held in a database that way it is eaiser to edit and add to...

i currently have a sample going which is here and i need some help.

i have two tables in my data base...
one called games_divisions and other games_schedule

in the games_divisions table i have....
divID int(10) UNSIGNED No auto_increment
name varchar(128) Yes NULL

and in games_schedule i have....
divID int(10) UNSIGNED No auto_increment
name varchar(128) Yes NULL
date varchar(128) Yes NULL
field varchar(128) Yes NULL
game varchar(128) Yes NULL
time varchar(128) Yes NULL

i want to use this code to be able to have it come out in that table form...

here is my code:

Code: Select all

<?
  $dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database.');
mysql_select_db ("databasename");
  $query = "select * from games_schedule where name = "".$group.""";
  $result = mysql_query($query);
	
?>	

<div align="center">
  <table border="1" cellpadding=3 cellspacing=3>
<TR>
<TD  colspan=6 Align=center><b><? echo $group ?></b></td>
</tr>
    <tr>
      <td bgcolor="#808080">Time/Field</td>
   <?
    $num_divs = mysql_num_rows($result);
	for($i=0; $i <5; $i++)
  	&#123;
                $currentDiv = mysql_fetch_array($result);
	  	echo "<td bgcolor=#808080 align=center>".$currentDiv&#1111;"date"]."</td>";
	&#125;
   ?>
   </tr>
<tr>
   <?

  $query = "select * from games_schedule where name = "".$group.""";
  $result = mysql_query($query);

    $num_divs = mysql_num_rows($result);

	  	echo "<td>".$currentDiv&#1111;"time"]."</td>";
 
for($i=0; $i <5; $i++)
 &#123;
    $currentDiv = mysql_fetch_array($result);
      echo "<td>".$currentDiv&#1111;"game"]."</td>";
 &#125;
 
   ?>
</tr>
    
<tr>
   <?
	  echo "<td>".$currentDiv&#1111;"time"]."</td>";
 
for($i=0; $i <5; $i++)
 &#123;
    $currentDiv = mysql_fetch_array($result);
      echo "<td>".$currentDiv&#1111;"game"]."</td>";
 &#125;
 
   ?>
</tr>
  </table>
</div>
if there is a better way to set this up that would be appricated...

Thanks

~Ecks

Posted: Thu Mar 06, 2003 4:56 pm
by Jade
Hey,

If this works for you why do you need something else? One suggestion on the script though, why not try to put the whole tablerow in a while loop and just have it repeat what you want for each person in a new table row. Would be easier than having a bunch of tiny while loops. Just a thought,


Jade

Posted: Thu Mar 06, 2003 7:34 pm
by ecks
it doesnt work for me... everything works but the time field...

Posted: Fri Mar 07, 2003 2:59 pm
by Jade
I think you're making this so much more complicated then it has to be. I'm assuming that you've already posted $group. Try this script, it should work:

<?

//connect to database

$dbh=mysql_connect ("localhost", "username", "password")
or die ('I cannot connect to the database.'); '

mysql_select_db ("databasename");

?>

<div align="center">
<table border="1" cellpadding=3 cellspacing=3>
<?php

//while loop that will select all you need

$count = 0;

$result = mysql_query("SELECT date FROM games_schedule WHERE name='$group'")
or die ("cannot select viewers id");

$date = mysql_result($result,$count,"date");

while ($date != "")
{

//gather the rest of what you need

$result = mysql_query("SELECT date FROM games_schedule WHERE name='$group'")
or die ("cannot select viewers id");

$date = mysql_result($result,$count,"date");

$result = mysql_query("SELECT game FROM games_schedule WHERE name='$group'")
or die ("cannot select viewers id");

$game = mysql_result($result,$count,"game");


$result = mysql_query("SELECT time FROM games_schedule WHERE name='$group'")
or die ("cannot select viewers id");

$time = mysql_result($result,$count,"time");
?>
<TR>
<TD colspan=6 Align=center><b><? echo $group ?></b></td>
</tr>
<tr>
<td bgcolor="#808080">Time/Field</td>
<td>
<?php
echo $date;
?>
</td>
</tr>
<tr>
<td>
<?php
echo $time;
?>
</td>
<td>
<?php
echo $game;
?>
</td>
</tr>
<?php
//end while loop

$count++;

$result = mysql_query("SELECT date FROM games_schedule WHERE name='$group'")
or die ("cannot select viewers id");

$date = mysql_result($result,$count,"date");

}
?>
</table>
</div>


You're script is making things complicated. Try to think simple, the answer is always something simple.

Jade

Posted: Sat Mar 08, 2003 1:15 am
by ecks
THANKS

errors:

it did say
Parse error: parse error, unexpected T_VARIABLE in /****/****/public_html/schedules.php on line 30

but i changed
name='$group'")
to
name=$group")

and it got rid of it.. now it says,

Parse error: parse error, unexpected $ in /****/****/public_html/schedules.php on line 82

line 82 = </div>

Posted: Sat Mar 08, 2003 5:18 pm
by Jade
Get rid of the <div align=center> and then the </div> on line 82. If you still want the table centered try <center></center> if that doesn't work see if the script will run if you removed those tags all toghther.

Jade

Posted: Sun Mar 09, 2003 4:23 am
by ecks
man i feel bad, nope that did work either, even with taking out all the tags.

Posted: Sun Mar 09, 2003 4:06 pm
by Jade
still getting the same error...or a different one?