Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] creacion de Variables dentro de un While php con variables definidas

Estas en el tema de creacion de Variables dentro de un While php con variables definidas en el foro de PHP en Foros del Web. Hola amigos, tengo un codigo que es el siguiente: Código PHP: $link=Conectarse(); $sql="select * from lotes"; $result=mysql_query($sql,$link); $points1="145,258,195,249,198,264,191,269,149,275"; $points2="142,240,163,236,192,232,195,249,145,258"; $points3="138,222,159,218,188,214,191,231,141,240"; $points4="135,205,156,201,185,197,188,214,138,223"; $points5="134,205,131,191,182,182,184,193,184,196"; $points6="132,192,129,178,180,169,182,180,182,183"; $points7="130,179,127,165,176,156,178,167,178,170"; $points8="127,165,124,153,175,144,177,154,177,156"; $points9="124,153,121,141,172,132,174,142,174,144"; $points10="121,140,118,128,169,119,171,129,171,132"; while ($row=mysql_fetch_array($result)){ ...
  #1 (permalink)  
Antiguo 04/09/2015, 12:32
 
Fecha de Ingreso: octubre-2008
Mensajes: 25
Antigüedad: 15 años, 5 meses
Puntos: 0
Mensaje creacion de Variables dentro de un While php con variables definidas

Hola amigos, tengo un codigo que es el siguiente:

Código PHP:
$link=Conectarse();
$sql="select * from lotes";
$result=mysql_query($sql,$link);
$points1="145,258,195,249,198,264,191,269,149,275";
$points2="142,240,163,236,192,232,195,249,145,258";
$points3="138,222,159,218,188,214,191,231,141,240";
$points4="135,205,156,201,185,197,188,214,138,223";
$points5="134,205,131,191,182,182,184,193,184,196";
$points6="132,192,129,178,180,169,182,180,182,183";
$points7="130,179,127,165,176,156,178,167,178,170";
$points8="127,165,124,153,175,144,177,154,177,156";
$points9="124,153,121,141,172,132,174,142,174,144";
$points10="121,140,118,128,169,119,171,129,171,132";
while ($row=mysql_fetch_array($result)){
$$puntos="$"."points".$row['lote'];
echo $$puntos;
?>
<a xlink:href="#"><polygon class='<?php echo $class;?>' id=<?php echo $row['lote'];?> points='<?php echo $puntos ;?>' /></a>
<?php
}
?>
<b>Notice</b>: Undefined variable: puntos in <b>C:\www\privadacuspide\mapa.php</b> on line <b>115</b><br />
$points4<a xlink:href="#"><polygon class='Libre' id=4 points='<br />
<b>Notice</b>: Undefined variable: puntos in <b>C:\www\privadacuspide\mapa.php</b> on line <b>117</b><br />
$points4' /></a>

la variable $puntos debe mostrar $points1,2,3 etc... para poder tomar las coordenadas establecidas

Gracias por su ayuda
  #2 (permalink)  
Antiguo 04/09/2015, 12:42
Avatar de MaNuX0218  
Fecha de Ingreso: marzo-2014
Mensajes: 787
Antigüedad: 10 años, 1 mes
Puntos: 67
Respuesta: creacion de Variables dentro de un While php con variables definidas

Estas utilizando el doble $ por lo que te dará el resultado de la segunda variable.

Y sobre que no está definida la variable $puntos, asignala al principio vacia.

Código PHP:
Ver original
  1. $puntos = "";
  2. $link=Conectarse();
  3. $sql="select * from lotes";
  4. $result=mysql_query($sql,$link);
  5. $points1="145,258,195,249,198,264,191,269,149,275";
  6. $points2="142,240,163,236,192,232,195,249,145,258";
  7. $points3="138,222,159,218,188,214,191,231,141,240";
  8. $points4="135,205,156,201,185,197,188,214,138,223";
  9. $points5="134,205,131,191,182,182,184,193,184,196";
  10. $points6="132,192,129,178,180,169,182,180,182,183";
  11. $points7="130,179,127,165,176,156,178,167,178,170";
  12. $points8="127,165,124,153,175,144,177,154,177,156";
  13. $points9="124,153,121,141,172,132,174,142,174,144";
  14. $points10="121,140,118,128,169,119,171,129,171,132";
  15. while ($row=mysql_fetch_array($result)){
  16. $puntos="$"."points".$row['lote'];
  17. echo $puntos;

Dime como te fue. Saludos.
__________________
No te preocupes si tu código no funciona bien. Si todo lo hiciera, no tendrías trabajo.
  #3 (permalink)  
Antiguo 04/09/2015, 13:09
 
Fecha de Ingreso: octubre-2008
Mensajes: 25
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: creacion de Variables dentro de un While php con variables definidas

<polygon class='Libre' id=1 points='$points1' /></a>

me sigue dando literalmente la variable, y no los datos que contiene. ese es mi problema real
  #4 (permalink)  
Antiguo 04/09/2015, 13:13
Avatar de MaNuX0218  
Fecha de Ingreso: marzo-2014
Mensajes: 787
Antigüedad: 10 años, 1 mes
Puntos: 67
Respuesta: creacion de Variables dentro de un While php con variables definidas

El resultado esperado es el siguiente?

<a ...><polygon class="..." id=".." points="points1" /></a>

Si no, dime cual sería el resultado esperado.

Saludos.
__________________
No te preocupes si tu código no funciona bien. Si todo lo hiciera, no tendrías trabajo.
  #5 (permalink)  
Antiguo 04/09/2015, 14:06
 
Fecha de Ingreso: enero-2015
Ubicación: Cordoba, Andalucía
Mensajes: 111
Antigüedad: 9 años, 3 meses
Puntos: 15
Respuesta: creacion de Variables dentro de un While php con variables definidas

Código PHP:
Ver original
  1. $puntos = "";
  2. $link=Conectarse();
  3. $sql="select * from lotes";
  4. $result=mysql_query($sql,$link);
  5. $points[1]="145,258,195,249,198,264,191,269,149,275";
  6. $points[2]="142,240,163,236,192,232,195,249,145,258";
  7. $points[3]="138,222,159,218,188,214,191,231,141,240";
  8. $points[4]="135,205,156,201,185,197,188,214,138,223";
  9. $points[5]="134,205,131,191,182,182,184,193,184,196";
  10. $points[6]="132,192,129,178,180,169,182,180,182,183";
  11. $points[7]="130,179,127,165,176,156,178,167,178,170";
  12. $points[8]="127,165,124,153,175,144,177,154,177,156";
  13. $points[9]="124,153,121,141,172,132,174,142,174,144";
  14. $points[10]="121,140,118,128,169,119,171,129,171,132";
  15. while ($row=mysql_fetch_array($result)){
  16. $puntos=$points[ $row['lote'] ];
  17. echo $puntos;
  #6 (permalink)  
Antiguo 04/09/2015, 15:27
 
Fecha de Ingreso: octubre-2008
Mensajes: 25
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: creacion de Variables dentro de un While php con variables definidas

quedo Perfecto el codigo

Código PHP:
Ver original
  1. <?php
  2. function Conectarse()
  3. {
  4.    if (!($link=mysql_connect("localhost","usuario","password")))
  5.    {
  6.       echo "Error conectando a la base de datos.";
  7.       exit();
  8.    }
  9.    if (!mysql_select_db("dbase"))
  10.    {
  11.       echo "Error seleccionando la base de datos.";
  12.       exit();
  13.    }
  14.    return $link;
  15. }
  16. $link=Conectarse();
  17. $puntos = "";
  18. $sql="select * from lotes";
  19. $result=mysql_query($sql,$link);
  20. $libre="fill:#0080C0;stroke:black;stroke-width:0.5; opacity:0.3;";
  21. $apartado="fill:yellow;stroke:black;stroke-width:1; opacity:0.3;";
  22. $vendido="fill:red;stroke:black;stroke-width:1; opacity:0.3;";
  23. $class="Libre";
  24. $points[1]="145,258,195,249,198,264,191,269,149,275";
  25. $points[2]="142,240,163,236,192,232,195,249,145,258";
  26. $points[3]="138,222,159,218,188,214,191,231,141,240";
  27. $points[4]="135,205,156,201,185,197,188,214,138,223";
  28. $points[5]="134,205,131,191,182,182,184,193,184,196";
  29. $points[6]="132,192,129,178,180,169,182,180,182,183";
  30. $points[7]="130,179,127,165,176,156,178,167,178,170";
  31. $points[8]="127,165,124,153,175,144,177,154,177,156";
  32. $points[9]="124,153,121,141,172,132,174,142,174,144";
  33. $points[10]="121,140,118,128,169,119,171,129,171,132";
  34. $points[11]="118,128,115,115,166,107,168,117,168,120";
  35. $points[12]="115,116,107,76,167,93,166,100,167,107";
  36. $points[13]="109,76,138,52,188,87,176,88,168,95";
  37. $points[14]="185,120,197,105,191,89,221,111,191,150";
  38. $points[15]="194,159,192,152,221,112,236,123,203,168";
  39. $points[16]="203,167,237,124,251,134,218,178";
  40. $points[17]="218,178,252,134,265,145,232,188";
  41. $points[18]="233,188,266,145,282,155,248,200";
  42. $points[19]="249,200,282,156,295,166,264,210";
  43. $points[20]="264,210,296,167,311,177,278,220";
  44. $points[21]="278,220,310,177,326,188,294,231";
  45. $points[22]="293,232,326,188,341,198,309,242";
  46. $points[23]="309,243,342,199,354,208,320,251";
  47. $points[24]="320,252,354,208,367,216,334,260";
  48. $points[25]="334,261,367,216,378,225,346,269";
  49. $points[26]="345,269,378,225,390,234,356,278";
  50. $points[27]="357,277,390,233,402,242,369,285";
  51. $points[28]="369,285,402,242,416,252,392,286";
  52. $points[29]="392,286,417,252,431,263,415,285";
  53. $points[30]="522,354,506,330,511,323,513,321,558,354";
  54. $points[31]="487,353,486,321,496,332,505,330,521,353";
  55. $points[32]="468,353,467,305,472,309,487,321,487,353";
  56. $points[33]="454,354,454,300,462,301,465,304,467,353";
  57. $points[34]="440,302,454,302,454,355,441,355";
  58. $points[35]="427,302,440,302,441,355,427,355";
  59. $points[36]="414,302,427,302,427,355,414,355";
  60. $points[37]="401,302,414,302,414,355,401,355";
  61. $points[38]="389,302,401,302,401,355,389,355";
  62. $points[39]="376,301,390,301,390,355,376,355";
  63. $points[40]="358,301,377,301,377,355,358,355";
  64. $points[41]="340,301,358,301,358,355,340,355";
  65. $points[42]="321,301,340,301,340,355,321,355";
  66. $points[43]="302,301,321,301,321,355,302,355";
  67. $points[44]="284,301,302,301,302,355,284,355";
  68. $points[45]="266,300,284,300,284,355,266,355";
  69. $points[46]="247,300,266,300,266,355,247,355";
  70. $points[47]="228,300,247,300,247,355,228,355";
  71. $points[48]="209,300,228,300,228,355,210,355";
  72. $points[49]="193,300,209,300,210,355,194,355";
  73. $points[50]="180,300,194,298,193,353,198,366,179,366";
  74. $points[51]="165,305,179,301,179,355,178,366,166,365";
  75. $points[52]="151,310,165,306,165,360,165,366,152,366";
  76. ?>
  77. <style>
  78.  polygon:hover {  fill:#804040; opacity:0.5; }
  79.  circle:hover {  fill:#804040; opacity:0.5; }
  80.  polygon.Libre{
  81.  fill:#0080C0;stroke:black;stroke-width:0.5; opacity:0.3;
  82.   }
  83.  polygon.Libre:hover{ fill:#5B060F;stroke:black;stroke-width:0.5; opacity:0.3; }
  84.  rect.Libre{
  85.  fill:#0080C0;stroke:black;stroke-width:0.5; opacity:0.3;
  86.   }
  87.  rect.Libre:hover{ fill:#5B060F;stroke:black;stroke-width:0.5; opacity:0.3; }
  88.  polygon.Apartado{
  89.  fill:yellow;stroke:black;stroke-width:1; opacity:0.3;
  90.   }
  91.  polygon.Apartado:hover{ fill:#5B060F;stroke:black;stroke-width:1; opacity:0.3; }
  92.  rect.Apartado{
  93.  fill:yellow;stroke:black;stroke-width:1; opacity:0.3;
  94.   }
  95.  rect.Apartado:hover{ fill:#5B060F;stroke:black;stroke-width:1; opacity:0.3; }
  96.  polygon.Vendido{
  97.  fill:red;stroke:black;stroke-width:1; opacity:0.3;
  98.   }
  99.  polygon.Vendido:hover{ fill:#5B060F;stroke:black;stroke-width:1; opacity:0.3; }
  100.  rect.Vendido{
  101.  fill:red;stroke:black;stroke-width:1; opacity:0.3;
  102.   }
  103.  rect.Vendido:hover{ fill:#5B060F;stroke:black;stroke-width:1; opacity:0.3; }
  104.  
  105. </style>
  106. <html>
  107. <div id="mapa" style="position: absolute; left: 350px; top: 80px;z-index: 1; background-color:#FFFFFF;"><center><img src="sembrado.png" width="625" height="510" alt="" border="0"></center></div>
  108. <div id="svgmapa" style="position: absolute; left: 350px; top: 80px;z-index: 2">
  109. <svg height="800" width="600">
  110. <a xlink:href="#" xlink:title="AREAS VERDES"><polygon points="219,284,319,285,325,279,322,272,216,193,208,193,201,198" stroke="black" stroke-linejoin="round" stroke-width="2" fill="#349A4B" style="opacity:0.8;"/></a>
  111. <a xlink:href="#" xlink:title="AREA DE JUEGOS INFANTILES"><circle cx="227" cy="227" r="11" stroke="black" stroke-width="2" fill="#FF0080" style="opacity:0.6;" /></a>
  112. <a xlink:href="#" xlink:title="AREA DE GIMNASIO MIXTO"><polygon points="258,269,265,277,274,269,267,261" stroke=" black" stroke-width="2" fill="#205CCC" style="opacity:0.8;"/></a>
  113. <?php
  114. while ($row=mysql_fetch_array($result)){
  115. $puntos=$points[ $row['lote'] ];
  116. ?>
  117. <a xlink:href="#" xlink:title='Lote <?php echo $row['lote'];?> Frente: <?php echo $row['frente'];?>m Fondo: <?php echo $row['fondo'];?>m Superficie: <?php echo$row['m2'];?>m2'><polygon class='<?php echo $class;?>' id=<?php echo $row['lote'];?> points='<?php print($puntos);?>' /></a>
  118. <?php
  119. }
  120. ?>
  121.  
  122. </svg>
  123. </div>

Etiquetas: variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:41.