Jump to content

Recommended Posts

Hello everyone,

i'm Osiris and i'm stuck with this PHP/HTML code, i'm fairly new at this so this might be a dumb question.

i have a database, but i want to output all data into a table from the database using HTML codes.

i had it so far that i could outpust the info in just plain text but it doesn't output in the HTML table.

Can anyone see what i did wrong?

This is my PHP code its in the body section

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT `Name`, `Color`, `Type`, `Subtype`, `Power`, `Toughness`, `Manacost`, `Rarity`, `Expansion`, `Foil`, `Stock` FROM `mtgtabel`';

mysql_select_db('mtgstock');
$retval = mysql_query( $sql, $conn );
if(! $retval )
	{
	die('Could not get data: ' . mysql_error());
	}
	echo '<table class=mytable>';
	echo "<tr><th >Name</th><th >Color</th><th >Type</th><th >Sub Type</th><th >Power</th><th >Toughness</th><th >Converted mana cost</th><th >Rarity</th><th >Expansion</th><th >Foil</th><th >Stock</th></tr>";
	while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
		{
			echo "<tr><td>";
			echo $row['Name']
			echo "</td><td>";
			echo $row['Color'];
			echo "</td><td>";
			echo $row['Type'];
			echo "</td><td>";
			echo $row['Subtype'];
			echo "</td><td>";
			echo $row['Power'];
			echo "</td><td>";
			echo $row['Toughness'];
			echo "</td><td>";
			echo $row['Manacost'];
			echo "</td><td>";
			echo $row['Rarity'];
			echo "</td><td>";
			echo $row['Expansion'];
			echo "</td><td>";
			echo $row['Foil'];
			echo "</td><td>";
			echo $row['Stock'];
			echo "</td></tr>";
		}
		echo "</table>";
mysql_close($conn);
?>

Thanks in advance!

Your (html) code being output by your PHP code looks ok to me. The data returned by your query should be displayed in the HTML table.

 

What are you seeing instead?

 

Note you should stop using the mysql_ functions. These functions are deprecated meaning they are no longer supported and could be removed from future versions of PHP. You should be using MySQLi or PDO

Ow yea i did  not change the html file to php. :@

But now i'm gettin this error:

Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in D:\xampp\htdocs\mtgstock\index.php on line 66

this is the full file

<!DOCTYPE html>
<html>
<head>
<title>MTG Card List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="screen">
@import "filtergrid.css";
body{ 
	margin:15px; padding:15px; border:1px solid #666;
	font-family:Arial, Helvetica, sans-serif; font-size:88%; 
}
h2{ margin-top: 50px; }
caption{ margin:10px 0 0 5px; padding:10px; text-align:left; }
pre{ font-size:13px; margin:5px; padding:5px; background-color:#f4f4f4; border:1px solid #ccc;  }
.mytable{
	width:100%; font-size:12px;
	border:1px solid #ccc;
}
th{ background-color:#003366; color:#FFF; padding:2px; border:1px solid #ccc; }
td{ padding:2px; border-bottom:1px solid #ccc; border-right:1px solid #ccc; }
body p {
	font-size: 50%;
	color: #000;
}
a:link {
	color: #000;
}
a:visited {
	color: #000;
}
</style>
<script language="javascript" type="text/javascript" src="actb.js"></script>
<script language="javascript" type="text/javascript" src="tablefilter.js"></script>
</head>
<body>


<form action="password.php" method="POST">
<b>Username:</b> <input type="text" name="username">
<b>Password:</b> <input type="text" name="password">
<input type="submit">
</form>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT `Name`, `Color`, `Type`, `Subtype`, `Power`, `Toughness`, `Manacost`, `Rarity`, `Expansion`, `Foil`, `Stock` FROM `mtgtabel`';

mysql_select_db('mtgstock');
$retval = mysql_query( $sql, $conn );
if(! $retval )
	{
	die('Could not get data: ' . mysql_error());
	}
	echo '<table class=mytable>';
	echo "<tr><th >Name</th><th >Color</th><th >Type</th><th >Sub Type</th><th >Power</th><th >Toughness</th><th >Converted mana cost</th><th >Rarity</th><th >Expansion</th><th >Foil</th><th >Stock</th></tr>";
	while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
		{
			echo "<tr><td>";
			echo $row['Name']
			echo "</td><td>";
			echo $row['Color'];
			echo "</td><td>";
			echo $row['Type'];
			echo "</td><td>";
			echo $row['Subtype'];
			echo "</td><td>";
			echo $row['Power'];
			echo "</td><td>";
			echo $row['Toughness'];
			echo "</td><td>";
			echo $row['Manacost'];
			echo "</td><td>";
			echo $row['Rarity'];
			echo "</td><td>";
			echo $row['Expansion'];
			echo "</td><td>";
			echo $row['Foil'];
			echo "</td><td>";
			echo $row['Stock'];
			echo "</td></tr>";
		}
		echo "</table>";
mysql_close($conn);
?>
<script language="javascript" type="text/javascript">
	var recapFilters = {
		sort_select: true,
		loader: true,
    col_1: "select",
    col_2: "select",
    col_3: "select",
    col_7: "select",
    col_8: "select", 
    col_9: "select",
	col_10: "false",
		on_change: true,
		display_all_text: "Show all",
		rows_counter: true,
		btn_reset: true,
		alternate_rows: true,
		btn_reset_text: "Clear",
		col_width: ["150px","150px",null,null]
	}
	setFilterGrid("recap",recapFilters);
</script>
<script language="javascript" type="text/javascript">
  var table_Props =  {
              paging: true,
              paging_length: 3,
              rows_counter: true,
              btn_reset: true,
              loader: true,
              loader_text: "Filtering data..."
            };
  setFilterGrid( "table",table_Props );
</script>
</body>
</html>

>Thanks for responding and helping me out so quickly btw!

Edited by OsirisElKeleni

Oh i do have one more question, i have like filtering stuff at the top of the table but when i use it it just stays loading is this cuz this is a localhost?

 

http://imgur.com/V3wIe4d

Edited by OsirisElKeleni

This new problem you have has nothing to do with your PHP code or whether you are running the code locally

 

The filtering is handled by the third party javascript code you are using. Maybe you have not handled it correctly? if not check for javascript errors in your browsers console (F12 > Console Tab). If there are javascript errors then start a new thread in the Javascript Forum.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.