Jump to content

Re-adability of tables


dave_55

Recommended Posts

Hi, can anyone help me. I want my table to display everything under the headings Date, HomeAwayGame, Home Team, Away Team and not like it does at the moment -  Does anyone know how to do this???

 

Date: 2007-09-08

HomeAwayGame: Home

HomeTeam: Lincoln

AwayTeam: Nottingham Moderns

 

Date: 2007-09-15

HomeAwayGame: Away

HomeTeam: Sleaford

AwayTeam: Lincoln

 

My Code is -

 

<title>2nd Team Fixtures</title>

 

<?php

$database = "localhost"; //login to the server

$username = "dave"; //username login

$password = "*****"; //password login

 

//connection to the database

$dbhandle = mysql_connect($hostname, $username, $password)

or die("Unable to connect to Lincoln Database");

echo "Connected to Lincoln Database<br><br>";

 

//select a database to work with

$selected = mysql_select_db("lincolnrugby",$dbhandle)

  or die("Could not select lincoln rugby");

 

$result = mysql_query("SELECT * FROM 2ndfixtures"); //execute the SQL query and return records

 

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // Loop through all the rows

   // Set some variables to the $row array

   $Date = $row['Date'];

   $HomeAwayGame = $row['HomeAwayGame'];

   $HomeTeam = $row['HomeTeam'];

   $AwayTeam = $row['AwayTeam'];

   

  // Display the information

   echo "

  Date: $Date <br>

  HomeAwayGame: $HomeAwayGame <br>

  HomeTeam: $HomeTeam <br>

  AwayTeam: $AwayTeam <br><br>";

}

 

//close the connection

mysql_close($dbhandle);

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/98712-re-adability-of-tables/
Share on other sites

This should do the trick...

<title>2nd Team Fixtures</title>

<?php
   $database = "localhost";      //login to the server
   $username = "dave";      //username login
   $password = "*****";      //password login

   //connection to the database
   $dbhandle = mysql_connect($hostname, $username, $password)
   or die("Unable to connect to Lincoln Database");
   echo "Connected to Lincoln Database";
   
   //select a database to work with
   $selected = mysql_select_db("lincolnrugby",$dbhandle)
     or die("Could not select lincoln rugby");
   
   $result = mysql_query("SELECT * FROM 2ndfixtures");   //execute the SQL query and return records
?>
<table>
<tr>
  <td>Date</td>
  <td>Home/Away Game</td>
  <td>Home Team</td>
  <td>Away Team</td>
</tr>
<?php
   // Loop through all the rows      
   while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
{       
      // Display the information
      echo " <tr>\n";
      echo "  <td>".$row['Date']."</td>\n";
      echo "  <td>".$row['HomeAwayGame']."</td>\n";
      echo "  <td>".$row['HomeTeam']."</td>\n";
      echo "  <td>".$row['AwayTeam']."</td>\n";
      echo " </tr>\n";
}   

//close off the table
echo "</table>\n";

//close the connection
mysql_close($dbhandle);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.