Foršais džekiņš ([info]petro) rakstīja [info]koderi kopienā,
@ 2008-05-20 15:52:00

Previous Entry  Add to memories!  Tell a Friend!  Next Entry
PHP
[Error: Irreparable invalid markup ('<td <?>') in entry. Owner must fix manually. Raw contents below.]

Dots:
Ir lapa kuru man vajadzētu pielabot.
Zināšanas par PHP man ir minimālas, tā teikt "absolute beginner",
esošā koda fragments:
<code>
<?
$query = "SELECT * FROM cont_big WHERE cat = '".$cat."'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$content_big = stripslashes($row['content']);
?>
<table>
<tr>
<td <?=$content_big;?></td>
</tr>
</table>
<? } ?>
</code>
nu lūk un šis mainigais "content_big" attiecīgi satur HTML tekstu no MySQL datubāzes.

Jautājums: Vai ir kādīgi iespējams, lai tas "content_big" saturētu izpildāmu PHP kodu?


(Lasīt komentārus) - (Ierakstīt jaunu komentāru)


[info]begemots
2008-05-20 17:58 (saite)
vispārīgi runājot, ir 2 lietas, cik sapratu no php eval() apraksta (neesmu php lietojis pāris gadus, varbūt neatceros, tālāk meklēt pašam slinkums):

There are some factors to keep in mind when using eval(). Remember that the string passed must be valid PHP code, including things like terminating statements with a semicolon so the parser doesn't die on the line after the eval(), and properly escaping things in code_str . To mix HTML output and PHP code you can use a closing PHP tag to leave PHP mode.


Tas nozīmē, ka eval() normāli apstrādās tikai valīdu PHP vai HTML, kas SEKO aizverošam PHP tagam; piemēram, šie būs pareizi $content_big saturi:

1) echo "BOO";
2) echo "BOO"; ?>
3) ?>
//iespējams (3) vajag vēl ";" pirms "?>"

Bet šie nebūs:

1) echo "BOO" // trūkst beigu semikola
2) // nav valīda PHP!

Tā lūk. Tā kā ja ir pliks HTML un pliks PHP kaut kur tur maisīti, tad nederēs.

(Atbildēt uz šo) (Diskusija)


[info]begemots
2008-05-20 17:59 (saite)
sorry, nozaga man stūriekavas. piemēri ir šādi:

pareizi $content_big saturi:

1) echo "BOO";
2) echo "BOO"; ?>
3) ?> <html_kods><boo></boo>
//iespējams (3) vajag vēl ";" pirms "?>"

nepareizi:

1) echo "BOO" // trūkst beigu semikola
2) <html_kods><boo></boo> // nav valīda PHP!

(Atbildēt uz šo) (Iepriekšējais) (Diskusija)


[info]petro
2008-05-20 18:14 (saite)
[Error: Irreparable invalid markup ('<td [...] <?>') in entry. Owner must fix manually. Raw contents below.]

$content_big saturs izskatās apmeram tāds:

<code>

<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td align="center" bgcolor="#339900" style="padding:3px 3px 3px 3px; font-weight: bold;">Šādi tādi texti</td>
</tr>
</table>

<?php
$query = "SELECT * FROM top10_date";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
?>
<strong><?php=$row['date']?></strong><br>
<br>
</div>

<form name='form1' method='post' action=''>
<table width="480" cellpadding="3" cellspacing="0" border="1" bordercolor="#999999">
<tr>
<td width="23" height="19" valign="top">&nbsp;</td>
<td width="23" height="19" valign="top">Some_TXT</td>
<td width="40">Some_TXT</td>
<td width="53">Some_TXT</td>
<td colspan="2" valign="top"><center>Some_TXT</center></td>
</tr>

<?php
$query = "SELECT * FROM top10_real WHERE top_nr NOT LIKE '%x%' ORDER BY top_nr ASC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
if ($row['pagw'] == "J") {
$bgcolor = "#FF9900";
$txtb = "style=\"font-weight:bold\"";
} else {
$bgcolor = "";
$txtb = "";
}
?>

<tr>
<td width="23" height="19" valign="top"><input name="vote" type="radio" value="<?=$row['top10r_id']?>"></td>
<td bgcolor="#999999" ><strong><?=$row['top_nr']?></strong></td>
<td bgcolor="<?=$bgcolor?>" <?=$txtb?>><?=$row['pagw']?></td>
<td bgcolor="<?=$bgcolor?>" <?=$txtb?>><?=$row['weeks']?></td>
<td width="150" align="center" bgcolor="<?=$bgcolor?>" <?=$txtb?>><?=$row['artist']?></td>
<td width="172" align="center" bgcolor="<?=$bgcolor?>" <?=$txtb?>><?=$row['song']?></td>
</tr>
<?
}
?>

</table>
</form>


</code>

pats to neesmu rakstījis, bet būtu noderējis pa fikso savietot.

(Atbildēt uz šo) (Iepriekšējais)


[info]petro
2008-05-20 18:20 (saite)
Un vispar pietiek čakarāt bobi. Darbalaiks jau pirms stundas beidzās un par šito man, izskatās ka tāpat neviens nemaksās. Vnk. butu bijis patīkami dabūt "paldies" no kolēģiem, kuru darbs atvieglotos.

(Atbildēt uz šo) (Iepriekšējais)


(Lasīt komentārus) -

Neesi iežurnalējies. Iežurnalēties?