Mixing PHP with HTML Tags

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
predolim
Forum Newbie
Posts: 5
Joined: Fri Jan 30, 2004 11:16 am
Location: São Paulo - Brazil

Mixing PHP with HTML Tags

Post by predolim »

Hi.

I´m having serious problems with mixing PHP and HTML TAGS.

I´m writing a php/mysql code where mysql db brings all the data to build a dymanic table with mysql data already inserted.

My doubts are:

1) How could use CSS with PHP?


2) Is there any ways to use PHP tags insdie HTML page, inputing PHP tags inside HTML tags as TD TR or even TABLE?

I thank you all in advance for that.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Example :

Code: Select all

<html>
<head>
<title><?php echo $title ?></title>
<link rel="stylesheet" type="text/css" href="/styles/default.css">
</head>
<body>
<table>
    <tr>
        <td><?php echo $firstName ?></td>
    </tr>
</table>
</body>
</html>
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

i recomend you to read some basic php tutorial:

http://www.linuxforum.com/phpmanual/introduction.html
http://www.php.net/tut.php

you only have to echo what you want...
predolim
Forum Newbie
Posts: 5
Joined: Fri Jan 30, 2004 11:16 am
Location: São Paulo - Brazil

Post by predolim »

AVATAr wrote:i recomend you to read some basic php tutorial:

http://www.linuxforum.com/phpmanual/introduction.html
http://www.php.net/tut.php

you only have to echo what you want...
I´m trying to do this:

<?php
include "conexao.php";
$sql="select id_not, titulo, texto, link FROM noticias ORDER BY id_not DESC LIMIT 0, 4";
$resultado=mysql_query($sql);
$num_linhas=mysql_num_rows($resultado);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>..:: Terra Networks & Solutions do Brasil ::..</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="tabela.css" rel="stylesheet" type="text/css">
<script src="matrix.js" type="text/javascript" runat="server"></script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/detail_2.gif')">
<table width="762" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="1" bgcolor="#000000"rowspan="100"><img src="images/spacer.gif" width="1" height="1"></td>
<td width="760" valign="top"> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td height="135" colspan="3" align="center">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shoc ... n=6,0,29,0" width="760" height="135">
<param name="movie" value="top.swf">
<param name="quality" value="high">
<param name="menu" value="false">
<embed src="top.swf" width="760" height="135" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed></object>
</td>
</tr>
<tr>
<td width="171" align="center" valign="top" background="images/esq.gif">
<?php
echo "<table width='168'>";
echo "<tr>";
echo "<td width='168'>";
for ($i=0;$i<$num_linhas;$i++)
{
$dados = mysql_fetch_array($resultado);
echo "<br>";
echo "<font face='Tahoma' size='1' color='#000000' align='justify'>";
echo $dados["titulo"];
echo "<br>";
echo "<img src="images/header.gif" width="171" height="31" border="0">";
echo "<br>";
echo "<a href=".$dados['link']." target='meio'>";
echo $dados["texto"];
echo "</font>";
echo "<br>";
echo "<br>";
}
echo "</td>";
echo "</tr>";
echo "</tr>";
echo "</table>";
?>

</td>
<td width="418" valign="top"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5">&nbsp;</td>
</tr>
<tr>
<td colspan="5"><img src="images/planos_01.jpg" width="209" height="100"><img src="images/planos_02.jpg" width="209" height="100"></td>
</tr>
<tr>
<td rowspan="2"><img src="images/planos.gif" width="184" height="35"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td background="images/butsplanosbg.gif"><img src="images/abre.gif" width="44" height="24"></td>
<td background="images/butsplanosbg.gif"> <div align="center"><img src="images/butsplanos_01.gif" width="50" height="24"></div></td>
<td background="images/butsplanosbg.gif"> <div align="center"><img src="images/butsplanos_02.gif" width="50" height="24"></div></td>
<td background="images/butsplanosbg.gif"> <div align="center"><img src="images/butsplanos_03.gif" width="50" height="24"></div></td>
</tr>
<tr>
<td width="198"class="feature"><font size="2">ajksvhdajklasdvhla</font></td>
<td class="butdetails" id="CT1_TGLink" onClick="javascript:toggleL('CT1_TGContent','CT1_TGLink')">
<img alt="Veja mais detalhes" src="images/detail.gif" width="44" style="cursor:help;" height="20" border="0"></td>
<td class="details" width="65"> <div align="center">10</div></td>
<td class="details" width="65"> <div align="center">20</div></td>
<td class="canto" width="65"> <div align="center">30</div></td>
</tr>
<tr>
<td colspan="5"> <div id="CT1_TGContent" style="background-color:#FFFFFF" class="TG_hidden">
<div align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="description"><span>&ccedil;asdkbnalksdnaklsd<br>
&ccedil;asdkbnalksdnaklsd<br>
&ccedil;asdkbnalksdnaklsd</span></td>
</tr>
</table>

but i´m having problems...
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

que problemas?
predolim
Forum Newbie
Posts: 5
Joined: Fri Jan 30, 2004 11:16 am
Location: São Paulo - Brazil

Post by predolim »

ótimo, vc fala português..

Na verdade é isso que quero fazer:

Teria como eu usar o CSS dentro do PHP, tipo, nas tabelas criadas dinamicamente, teria como eu usar classes pra manipular o que fosse impresso na tela?

Eu tô tentando fazer isso aqui e não dá certo...

No ínício do código eu faço a conexão com BD
----------------------------------------------------------------
<?php
include "conexao.php";
$sql="select id_not, titulo, texto, link FROM noticias ORDER BY id_not DESC LIMIT 0, 4";
$resultado=mysql_query($sql);
$num_linhas=mysql_num_rows($resultado);
?>

----------------------------------------------------------------

Mais abaixo, junto do HTML eu uso isso aqui
---------------------------------------------------------------
<?php
echo "<table width='168'>";
echo "<tr>";
echo "<td width='168'>";
for ($i=0;$i<$num_linhas;$i++)
{
$dados = mysql_fetch_array($resultado);
echo "<br>";
echo "<font face='Tahoma' size='1' color='#000000' align='justify'>";
echo $dados["titulo"];
echo "<br>";
echo "<img src=\"images/header.gif\" width=\"171\" height=\"31\" border=\"0\">";
echo "<br>";
echo "<a href=".$dados['link']." target='meio'>";
echo $dados["texto"];
echo "</font>";
echo "<br>";
echo "<br>";
}
echo "</td>";
echo "</tr>";
echo "</tr>";
echo "</table>";
?>

Tá certo isso??? É ai no segundo bloco que preciso usar o CSS...qdo forem criadas as tabelas dinâmicas eu preciso inserir o CSS nelas...
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

No hablamos mucho espanol.

Did I say that right? Prolly not!
predolim
Forum Newbie
Posts: 5
Joined: Fri Jan 30, 2004 11:16 am
Location: São Paulo - Brazil

Post by predolim »

Sorry, its portuguese.

I want to do this:

I need to use CSS on PHP dynamic tables

Begining the PHP code
----------------------------------------------------------------
<?php
include "conexao.php";
$sql="select id_not, titulo, texto, link FROM noticias ORDER BY id_not DESC LIMIT 0, 4";
$resultado=mysql_query($sql);
$num_linhas=mysql_num_rows($resultado);
?>

----------------------------------------------------------------

Above, with HTML mixed i have this..
---------------------------------------------------------------
<?php
echo "<table width='168'>";
echo "<tr>";
echo "<td width='168'>";
for ($i=0;$i<$num_linhas;$i++)
{
$dados = mysql_fetch_array($resultado);
echo "<br>";
echo "<font face='Tahoma' size='1' color='#000000' align='justify'>";
echo $dados["titulo"];
echo "<br>";
echo "<img src=\"images/header.gif\" width=\"171\" height=\"31\" border=\"0\">";
echo "<br>";
echo "<a href=".$dados['link']." target='meio'>";
echo $dados["texto"];
echo "</font>";
echo "<br>";
echo "<br>";
}
echo "</td>";
echo "</tr>";
echo "</tr>";
echo "</table>";
?>

Is that right? Could i put CSS on that?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

no hablo portugues.. pero somos vecinos (uruguay - español) .. ;)

Solamente tiene que insertar el css.. el css es como html.. simplemente inserta los tags apropiados en los echo.

que queres hacer con css?

---

traduction:

i dont speak portuguese buy we are neightbors (uruguay - spanish)
you only need to insert css tags as html tags. Simply insert the appropiate css tags in the "echos"

what to you want to do with css exactly?
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

PHP can write any text you want. HTML, CSS, raw data, whatever. So it seems like your real problem is with client-side CSS.
Post Reply