Jump to content
bubbles

php code in while

Recommended Posts

Posted (edited)

Vreau sa fac generez in while coduri PHP fara ca ele sa fie rulate.

<?php

$x=1;

while($x<=5)

{

echo"<td><code><?php if (in_array(".$x.", $numere_tura_1)) {echo "<span class=\"num\">".$x."</span>";} ?></code></td>";

$x++;

}

?>

Unde gresesc ? Merci.

Practiv vreau sa-mi afiseze :

<td><?php if (in_array(1, $numere_tura_1)) {echo "<span class=\"num\">1</span>";} ?></td>

<td><?php if (in_array(2, $numere_tura_1)) {echo "<span class=\"num\">2</span>";} ?></td>

<td><?php if (in_array(3, $numere_tura_1)) {echo "<span class=\"num\">3</span>";} ?></td>

<td><?php if (in_array(4, $numere_tura_1)) {echo "<span class=\"num\">4</span>";} ?></td>

<td><?php if (in_array(5, $numere_tura_1)) {echo "<span class=\"num\">5</span>";} ?></td>

Edited by bubbles
Posted (edited)

În primul rând nu cred c? în?elege nimeni ce vrei s? spui, în al 2-lea rând variabila $numere_tura_1 nu este definit?.

LE: în loc de < pui <

Edited by EAdrian
Posted (edited)

@EAdrian - variabila $numere_tura_1 este definita, dar nu am postat-o, pe mine ma intereseaza doar partea asta :

<?php if (in_array($x, $numere_tura_1)) {echo "<span class=\"num\">$x</span>";} ?>

Pe care vreau sa o generez(html) de cate ori vreau, insa variabila x sa fie consecutiva.

@eusimplu - am incercat, insa nu-mi mai afiseaza $x atunci.

Gresesc undeva la concatenare cred.

@aggroxx - care e scopul postarii tale ?

Edited by bubbles
Posted (edited)

echo htmlentities("<td><code><?php if (in_array(".$x.", ".$numere_tura_1.")) {echo \"<span class=\"num\">".$x."</span>\";} ?></code></td>");

sau

echo "<td><code><?php if (in_array(".$x.", ".$numere_tura_1.")) {echo \"<span class=\"num\">".$x."</span>\";} ?></code></td>";

daca vrei sa functioneze <td><code> </code></td> :

echo "<td><code>".htmlentities("<?php if (in_array(".$x.", ".$numere_tura_1.")) {echo \"<span class=\"num\">".$x."</span>\";} ?>")."</code></td>";

(cred k asta vroiai )

Edited by pedala1
  • Upvote 1
Posted (edited)
@EAdrian - variabila $numere_tura_1 este definita, dar nu am postat-o, pe mine ma intereseaza doar partea asta :

Când postezi o problem?, posteaz-o complet.. c? noi nu suntem nevoi?i s?-?i refacem ?ie codul

http://pastebin.com/hC9v2A7n

Output:


<td><code><?php if (in_array(1), $numere_tura_1)){ echo "1" } ?></td></code>
<td><code><?php if (in_array(2), $numere_tura_1)){ echo "2" } ?></td></code>
<td><code><?php if (in_array(3), $numere_tura_1)){ echo "3" } ?></td></code>
<td><code><?php if (in_array(4), $numere_tura_1)){ echo "4" } ?></td></code>
<td><code><?php if (in_array(5), $numere_tura_1)){ echo "5" } ?></td></code>

Better solution: https://rstforums.com/forum/76312-php-code-while.rst#post491408

Edited by EAdrian
Posted

Merci, am rezolvat.

@EAdrian - nu inteleg "s?-?i refacem ?ie codul", am explicat clar ca nu stiam sa generez cod php intr-un while fara ca el sa se ruleze si sa fie doar afisat ca si HTML.

In fine, va multumesc.

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.   Paste as plain text instead

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