PHP - Dos problemas con Mysqli y mover el apuntador de un array asociativo

 
Vista:
sin imagen de perfil

Dos problemas con Mysqli y mover el apuntador de un array asociativo

Publicado por anonymous (20 intervenciones) el 16/05/2021 17:06:25
Hola quisiera que me indicarais como poner esto en mysqli por aquello de que hay que reformarse. Por otra parte estoy construyendo un sitemap y tengo que mover el apuntador y leer el array asociativo porque sino me repite direcciones que tengo en una bd pero no me funciona prev(), la solución creo que es simple pero ahora mismo no la veo ¿Me podeis ayudar?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
 
$bd_host = "XXX";
$bd_usuario = "XXX";
$bd_password = 'XXX.';
$bd_base = "XXX";
$con = mysql_connect($bd_host, $bd_usuario, $bd_password) or die();
mysql_select_db($bd_base, $con);
 
$sql = sprintf("SELECT * FROM Entradas WHERE Seccion='Relatos'");
$totalEnt = mysql_query($sql, $con);
$finalEnt = mysql_num_rows($totalEnt);
mysql_close($con);
 
if ($finalEnt > 0) {
    while ($Entradas = mysql_fetch_assoc($totalEnt)) {
        if ($Entradas['Direccion'] === prev($Entradas['Direccion'])) {echo"";}
        else {echo "".$Entradas['Direccion']."";}
    }
}
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Dos problemas con Mysqli y mover el apuntador de un array asociativo

Publicado por anonymous (20 intervenciones) el 17/05/2021 20:08:00
He buscado por internet un poco y he probado hacerlo de una manera por lo que he leído pero ahora no discrimina el array_unique()

1
2
3
4
5
6
7
8
9
10
11
12
13
$sql = sprintf("SELECT Direccion FROM Entradas WHERE Seccion='Relatos'");
$totalEnt = mysql_query($sql, $con);
$finalEnt = mysql_num_rows($totalEnt);
mysql_close($con);
 
if ($finalEnt > 0) {
while ($Entradas = mysql_fetch_assoc($totalEnt)) {
$resultados = array_unique($Entradas);
$resultados = implode(' ', $resultados);
if ($Entradas['Direccion'] !== $resultados) {echo $Entradas['Direccion'];}
else {echo "";}
}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Dos problemas con Mysqli y mover el apuntador de un array asociativo

Publicado por anonymous (20 intervenciones) el 23/05/2021 04:22:44
¿Nadie me puede ayudar?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Dos problemas con Mysqli y mover el apuntador de un array asociativo

Publicado por joel (1269 intervenciones) el 23/05/2021 10:50:49
Hola Pablo, creo que la solución pasa por que la consulta SQL solo te devuelva una "Direccion" unica, es decir, que no te devuelva las direcciones repetidas...

Para ello, en tu consulta sql puedes utilizar distinct... algo así:

1
$sql = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Relatos'");

De esta manera, todas las direcciones que te va a devolver son unicas.

Puedes probarlo?

https://www.mysqltutorial.org/mysql-distinct.aspx
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Dos problemas con Mysqli y mover el apuntador de un array asociativo

Publicado por anonymous (20 intervenciones) el 23/05/2021 20:31:19
Gracias mira que simple era y que de vueltas le he dado, ese tipo de consulta no la conocía. ¿Ahora me podéis indicar como se pone en Mysqli?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Dos problemas con Mysqli y mover el apuntador de un array asociativo

Publicado por joel (1269 intervenciones) el 24/05/2021 10:18:54
Es casi igual que en mysql... una manera podría ser:
1
2
$sql="SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Relatos'";
$totalEnt = mysqli_query($con, $sql);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Dos problemas con Mysqli y mover el apuntador de un array asociativo

Publicado por anonymous (20 intervenciones) el 24/05/2021 19:29:20
Ya en el tramo final me encontré con otro problema, me dice que está mal formado el XML y lo he repasado varias veces pero nada :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
      header("Content-Type: text/xml; charset=UTF-8");
 
      echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">";
 
	  echo "<url><loc>https://www.ratondebiblioteca.es/index.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Quienes%20somos.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Nuestro%20libros%20y%20musica.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista1-1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista1-2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista1-3.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista1-4.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista2-1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista2-2.php</loc><priority>0.5</priority><changefreq>always</changefreq></></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista2-3.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Revista3.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Librodevisitas.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasRelatos.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasRelatos1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasRelatos2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasPoemas.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasPoemas1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasPoemas2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasLibros.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasLibros1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasLibros2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasSonido%20y%20cine.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasSonido%20y%20cine1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasSonido%20y%20cine2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasEntrevistas.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasEntrevistas1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasEntrevistas2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasRevista.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasRevista1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasRevista2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasNoticias.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasNoticias1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasNoticias2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasVisiones.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasVisiones1.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/LibrodevisitasVisiones2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Nuestros%20premios.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Agenda.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Miembros.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Red%20Social.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Ficha%20modelo.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Ficha%20modelo2.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Legalidad.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Taquilla.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Amigos.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/AnunciosPorPalabras.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Musica.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/CompartirRed.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
	  echo "<url><loc>https://www.ratondebiblioteca.es/Arte.php</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
 
      $bd_host = "XXX";
      $bd_usuario = "XXX";
      $bd_password = 'XXX';
      $bd_base = "XXX";
      $con = mysql_connect($bd_host, $bd_usuario, $bd_password) or die();
             mysql_select_db($bd_base, $con);
 
      $sql = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Relatos'");
	  $sql1 = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Poemas'");
	  $sql2 = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Recomendamos'");
	  $sql3 = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Sonido y cine'");
	  $sql4 = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Entrevistas'");
	  $sql5 = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Noticias' AND Subseccion='L'");
	  $sql6 = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Noticias' AND Subseccion='M'");
	  $sql7 = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Noticias' AND Subseccion='C'");
	  $sql8 = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Noticias' AND Subseccion='F'");
	  $sql9 = sprintf("SELECT DISTINCT Direccion FROM Entradas WHERE Seccion='Noticias' AND Subseccion='O'");
	  $totalEnt = mysql_query($sql, $con);
	  $totalEnt1 = mysql_query($sql1, $con);
	  $totalEnt2 = mysql_query($sql2, $con);
	  $totalEnt3 = mysql_query($sql3, $con);
	  $totalEnt4 = mysql_query($sql4, $con);
	  $totalEnt5 = mysql_query($sql5, $con);
	  $totalEnt6 = mysql_query($sql6, $con);
	  $totalEnt7 = mysql_query($sql7, $con);
	  $totalEnt8 = mysql_query($sql8, $con);
	  $totalEnt9 = mysql_query($sql9, $con);
	  $finalEnt = mysql_num_rows($totalEnt);
	  $finalEnt1 = mysql_num_rows($totalEnt1);
	  $finalEnt2 = mysql_num_rows($totalEnt2);
	  $finalEnt3 = mysql_num_rows($totalEnt3);
	  $finalEnt4 = mysql_num_rows($totalEnt4);
	  $finalEnt5 = mysql_num_rows($totalEnt5);
	  $finalEnt6 = mysql_num_rows($totalEnt6);
	  $finalEnt7 = mysql_num_rows($totalEnt7);
	  $finalEnt8 = mysql_num_rows($totalEnt8);
	  $finalEnt9 = mysql_num_rows($totalEnt9);
	  mysql_close($con);
 
   if ($finalEnt > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt)) {
						                                                  echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                 }
		              }
 
   if ($finalEnt1 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt1)) {
						                                                   echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                  }
		              }
 
   if ($finalEnt2 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt2)) {
						                                                   echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                  }
		              }
 
   if ($finalEnt3 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt3)) {
						                                                   echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                  }
		              }
 
   if ($finalEnt4 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt4)) {
						                                                   echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                  }
		              }
 
   if ($finalEnt5 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt5)) {
						                                                   echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                  }
		              }
 
   if ($finalEnt6 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt6)) {
						                                                   echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                  }
		              }
   if ($finalEnt7 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt7)) {
						                                                   echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                  }
		              }
 
   if ($finalEnt8 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt8)) {
						                                                   echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                  }
		              }
 
   if ($finalEnt9 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt9)) {
						                                                   echo "<url><loc>".$Entradas['Direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                  }
		              }
 
      $bd_host = "XXX";
      $bd_usuario = "XXXX";
      $bd_password = 'XXX';
      $bd_base = "XXX";
      $con = mysql_connect($bd_host, $bd_usuario, $bd_password) or die();
             mysql_select_db($bd_base, $con);
 
      $sql10 = sprintf("SELECT DISTINCT direccion FROM Entradas ORDER BY nick");
	  $totalEnt10 = mysql_query($sql10, $con);
	  $finalEnt10 = mysql_num_rows($totalEnt10);
	  mysql_close($con);
 
   if ($finalEnt10 > 0) {
                        while ($Entradas = mysql_fetch_assoc($totalEnt10)) {
						                                                    echo "<url><loc>".$Entradas['direccion']."</loc><priority>0.5</priority><changefreq>always</changefreq></url>";
						                                                   }
		                }
 
   echo "</urlset>";
 ?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Dos problemas con Mysqli y mover el apuntador de un array asociativo

Publicado por anonymous (20 intervenciones) el 25/05/2021 03:53:02
Solucionado cierren hilo :)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar