Display script output in html page.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dave.hawksworth
Forum Newbie
Posts: 11
Joined: Thu Feb 18, 2010 8:45 am

Display script output in html page.

Post by dave.hawksworth »

I have a php script which outputs a table as a result of an sql query. I would like to display the result in an html page in a specific position alongside two forms.
The output will always be a standard matrix in terms of rows and columns.
I can create the html page and the php script could someone please advise how to intigrate the two?
Thanks
Dave
php script.

<?php
$Day = $_POST['Day'];
$Year =$_POST['Year'];
$Month =$_POST['Month'];
print "Day: {$_POST['Day']}<br />";
print "Year:{$_POST['Year']}<br/>";
print "Month:{$_POST['Month']}<br/>";

;


$username="user";
$password="pwd";
$database="my_db";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");


$query="SELECT * FROM courttimes1 Where Day2='$Day' AND Year1='$Year' AND Month1='$Month'";
if($result=mysql_query($query))
{
if($num=mysql_numrows($result) > 0)
{

}
else
{
echo "No Rows Returned";
}
}
else
{
echo "Query Error";
echo $query;
echo mysql_error();
}

$result=mysql_query($query);

$num=mysql_numrows($result);



echo "<b><center>Database Output</center></b><br><br>";



echo "<table border='1'>
<tr>
<th>Day1</th>
<th>FullDate</th>
<th>Court1 Time</th>
<th>Player1</th>
<th>Player2</th>
<th>Court2 Time</th>
<th>Player3</th>
<th>Player4</th>




</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Day1'] . "</td>";
echo "<td>" . $row['FullDate'] . "</td>";
echo "<td>" . $row['Court1 Time'] . "</td>";
echo "<td>" . $row['Player1'] . "</td>";
echo "<td>" . $row['Player2'] . "</td>";
echo "<td>" . $row['Court2 Time'] . "</td>";
echo "<td>" . $row['Player3'] . "</td>";
echo "<td>" . $row['Player4'] . "</td>";
echo "</tr>";
}
echo "</table>";







?>
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

Re: Display script output in html page.

Post by lshaw »

Please post code in the code tags next time
I have added comments where it looks like an error below, just for the first few. Please explaian why these are not errors and put your code into code tags

Code: Select all

 
$Day = $_POST['Day'];
$Year =$_POST['Year'];
$Month =$_POST['Month'];
print "Day: {$_POST['Day']}<br />";
print "Year:{$_POST['Year']}<br/>";
print "Month:{$_POST['Month']}<br/>";
 
;  //unexpeted ; ?
 
 
$username="user";
$password="pwd";
$database="my_db";
 
mysql_connect(localhost,$username,$password); //asssumed costant localhost
@mysql_select_db($database) or die( "Unable to select database");
 
 
$query="SELECT * FROM courttimes1 Where Day2='$Day' AND Year1='$Year' AND Month1='$Month'";
if($result=mysql_query($query))
{
if($num=mysql_numrows($result) > 0) //function mysql_num_rows() expects one paramter to be ...
{
 
}
 
Post Reply