Jump to content


Photo

php in html


  • Please log in to reply
4 replies to this topic

#1 jagguy

jagguy
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 02 October 2006 - 12:10 PM

How do I embed php in html as this deosn't work, but it does work in a php script with no html in the same directory.


</head>
<body bgcolor="#ffffff"><?php $dbhost ="" 'localhost';

$conn = mysql_connect($dbhost,'root','') ;


$dbname = 'petstore';
mysql_select_db($dbname);


$query="select * from species"; 
$rt=mysql_query($query);

while($nt=mysql_fetch_array($rt))
{
echo "$nt[id] $nt[species] <br>";    
}


?> 

 

</body>
</html>


#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 02 October 2006 - 12:10 PM

... and why doesn't that work? are you naming the page a .php file? what error are you getting?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 02 October 2006 - 12:17 PM

<?php $dbhost ="" 'localhost';

should be:
<?php $dbhost ='localhost';


#4 jagguy

jagguy
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 03 October 2006 - 04:21 AM

Hi

Ok I had an error on the php code I have been told, so now it works thanks.

I suppose the question is how can you format the values I get from mysql on the webpage. Csn I use css on them somehow or do i need to use php only.

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 03 October 2006 - 12:32 PM

you can use CSS, javascript or any other client side technology on them after they've been retrieved via PHP. keep in mind that the browser only sees what PHP feeds it, so when you generate your markup, just output classes and IDs as you want them to be for your CSS layout.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users