Problema con php no despliega la variable

Hola Buenas Noches :
Alguien que me pueda ayudar, es muy sencillo pero no veo el error

Tengo este rutina ( la simplifique )

<?php $sql="hola"; $row= 0; while($row < 10) { ?>
        <tr>        
        <td> $sql </td>    
        </tr>
<?php $row=$row+1; } ?>

El resultado es : $sql $sql $sql $sql $sql $sql $sql $sql $sql $sql

yo quiero que sea : holaholaholaholaholaholaholaholaholahola

Algo tan sencillo y no lo puedo hacer

Que tengo que cambiar ???

Gracias y saludos

JAG

Hi @jagdesarrollos!

You should consider printing the $sql variable, not just write it. Also, because print() is a PHP function, you must have it enclosed within the PHP <?php / ?> tags. Your code should be like this:

<?php

$sql = "hola";
$row = 0;

while($row < 10)
{
   print($sql);

   $row = $row + 1;
}

?>

Gracias por la respuesta pero no es lo que busco con el PRINT, yo quiero desplegar algo en el centro de la pantalla, voy a amplear el codigo a ver si me explico.

Por alguna razon no pude poner el codigo original y le agregue el caracter # para poder ponerlo porque me borraba parte de el.

Obviamente no va el caracter #

Lo que necesito es que en la tabla repita la palabra hola.

<#table align=CENTER border=1 cellpadding=4 cellspacing=0>
<#tr>
<#th style=‘background-color: rgb(204, 204, 255);’ colspan=5> Consulta
<#tr>
<#th> Descripcion
<#/tr>

<?php $sql="hola"; $row= 0; while($row < 10) { ?>
        <#tr>        
        <#td> $sql <#/td>    
        <#/tr>
<?php $row=$row+1; } ?>

<#/table>

gracias de nuevo, saludos
JAG

Please see the code as in two parts: HTML and PHP. Do not mix them. PHP executes only what’s inside PHP tags <?php / ?>

Try to keep the code more clearer as well.

PHP is used to generate dynamic content. HTML simply outputs what’s in the document. Your code should be like this:

<table align = CENTER border = 1 cellpadding = 4 cellspacing = 0>
  <tr>
    <th style = 'background-color: rgb (204, 204, 255);' Colspan = 5>Consultation</th>
    <th>Description</th>
  </tr>

<?php

$sql = "hello";
$row = 0;

while($row < 10)
{
  print("<tr>");
  print("<td> $sql </td>");
  print("</tr>");

  $row = $row + 1;
}

?>
</table>

Gracias por tu respuesta, quisiera de favor vieras este código, ya lo modifique y me comentan que si funciona,

ahora en el servidor www.000webhost.com no funciona.

Yo no soy experto en esto y me costaría mucho trabajo modificar todo lo hecho.

<table align=CENTER border=1 cellpadding=4 cellspacing=0>
    <tr>
        <th style='background-color: rgb(204, 204, 255);' colspan=5> Consulta
    </tr>
    <tr>
        <th> Descripcion
    </tr>

    <?php

     $sql="hola";
     $row= 0;

     while($row < 10)
     {
         ?>
         <tr>
                 <td> <? =$sql ?> </td>
         </tr>

         <?php
         $row=$row+1;
     }
     ?>
</table>

Quisiera por favor y perdonando la molestia que me dijeras por que no funciona, tal vez no sea lo optimo pero debería funcionar.

Oh el problema es la mezcla de codigo.

Todo me funcionaba bien antes del 1 de mayo en tu mismo servidor , yo tenia mi cuenta jagonzalez.54 y la mude a jagdesarrollos y no funciona nada…

la liga del programa es : https://jagdesarrollos.000webhostapp.com/quirofano/aaaaa.php

Gracias por tu respuesta
JAG

Why are you adding <? / ?> tags? You don’t need them.

Also, I see you have removed the </th>


 while($row < 10)
 {
     ?>
     <tr>
             <td> <? =$sql ?> </td>
     </tr>
  <?php
    $row=$row+1;
}

This piece of code is not going to work because:

  1. 000webhost no longer supports small enclosing tags <? / ?>. There are ways to add support for them however I do not recommend it.

  2. </tr> and all the other tags must be outputted. PHP works separately from HTML, and only within <?php / ?> tags.

Please follow the code I have provided earlier because that’s the correct one. Also, I strongly advise you to read some documentation about HTML and PHP (BitDegree link), how they work together, but most important, what is PHP (PHP.NET link) and how it works. :wink:

gracias…

Buscando mas, me di cuenta de algo.
Si tengo este codigo :

<table align = CENTER border = 1 cellpadding = 4 cellspacing = 0>
<tr>
  <th style = 'background-color: rgb (204, 204, 255);' Colspan = 5>Consultation </th>
</tr>
<tr>
  <th>Description</th>
</tr>

<?php

$sql = "hello";
$row = 0;

while($row < 10)
{
    print("<tr>");
    print("<td> $sql </td>");
    print("</tr>");

   $row = $row + 1;
}

?>
</table>

y lo guardo en ejemplo.php si funciona
pero si es ejemplo.html no funciona

siempre pensé que era igual
estoy equivocado ? o porque no funciona ?
pueden comentarme sobre esto ?

Gracia y saludos
JAG

y lo guardo en ejemplo.php si funciona
pero si es ejemplo.html no funciona

This happens because .html are just documents, while .php are PHP scripts.

By default .html files are not treated like PHP scripts by the server, while .php files are.

Buen dia.

De nuevo yo, estoy algo decepcionado de mi trabajo. Aprendí solo y si, tal vez revolví conceptos.

Aprendí a prueba y error codificando en www.000webhost y fui avanzando, lo que hice involucrando MYSQL , PHP y HTML para mi era un logro porque de alguna manera funcionaba todo antes del 1° de mayo. A raíz del cambio y usar otra cuenta en el nuevo esquema dejo de funcionar.

Realmente no se que hacer pues para mi prácticamente es cambiar casi todo, solo estoy desogandome .

Saludos y gracias.
JAG

PD Si quieres dar por concluido esta bien.

@jagdesarrollos Is your issue solved?
I didn’t get, What you wrote above?
can you explain your issue a bit??

Gracias akhilkumar332 por contestar

No entiendo bien tu pregunta, si te refieres al anterior mensaje, esta relacionado con todo lo anterior en este mismo.

La duda principal que tengo es porque si todo funcionaba en mi cuenta jagonzalez.54 antes del 1° de mayo y al llegar la fecha salio un mensaje que hiciéramos una nueva cuenta jagdesarrollos subí los archivos, bases de datos y no funciona nada.

Tu compañero NGiNX que bien me ha asesorado y se lo agradezco me siguiere cambios que para mi es volver a empezar prácticamente modificando codigo

La pregunta principal es : Porque antes funcionaba como lo tenia y ahora no ?

Entiendo que tenia conceptos equivocados, esta bien, pero funcionaba.

El cambio para mi no fue muy transparente.

Gracias y Saludos
JAG

La pregunta principal es : Porque antes funcionaba como lo tenia y ahora no ?

We have changed a few things on the new servers. All for compatibility, security and performance issues.

It was a good idea to tell us that your website was migrated. I would’ve suggested you to change the PHP version as well: 000webhost cPanel > Settings > General > Change PHP version > 5.6

Maybe this would’ve solved most of the issues… :slight_smile:

Gracias de nuevo.

En la cuenta anterior jagonzalez.54 que todavía puedo entrar dice que esta el PHP 5.2.*

En la nueva cuenta jagdesarrollos en la configuración de PHP dice ahorita PHP 5.6 y no funciona casi nada por no decir nada y aun cuando lo cambie a PHP 5.2 que la tienen como opción tampoco funciona.

Debe haber otra razón.

JAG

It depends on how you have coded the website. I also see that you have used short PHP tags <? / ?> which I do not recommend because they are deprecated. You can still add support for them though… Please follow this tutorial to do so:

Also, have you been using SSI in your documents/files?


When I try to login in your website I get

ProxySQL Error: Access denied for user ‘’@‘2a02:4780:bad:f00d::7’ (using password: NO)

This means you must update the databases credentials in your config files as well. Please make sure they are the same as the ones from 000webhost cPanel > Manage databases

Hola :

Antes de nada de nuevo gracias .

ya hice el archivo .htaccess y me di “login” de nuevo.

Esta consulta funcionaba así como esta en jagonzalez.54 si tu tienes acceso a mi cuenta verías que es verdad.

En https://jagdesarrollos.000webhostapp.com/quirofano/consdoctor.html

Marca todos esos errores

Saludos
JAG

I have fixed the issue :wink:

You have PHP code in your HTML files as well. That’s why I had to configure from .htaccess to add PHP support for HTML files as well.

Woooooow

Gracias, Gracias …

JAG

You’re welcome! :blush: