Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 04/10/2011, 18h40   #1
Membre du Club
 
Inscription : janvier 2010
Messages : 317
Détails du profil
Informations forums :
Inscription : janvier 2010
Messages : 317
Points : 62
Points : 62
Par défaut Affichage hors while

Bonjour.

J'ai un problème d'affichage avec "<?php echo $nombre; ?> " que je suis obligé de placer en dehors de While. Comment, je peux afficher sans utiliser une session? J'ai testé dans une session, ça fonctionne mais ça demande un rafraichissement supplémentaire.

Je dois afficher ceci <?php echo $nombre; ?>.

Code :
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
 
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
  </head>
  <body>
  <center><img src="logo.jpg"></center><br>
	<form action="register.php" method="POST">
	http://<input type="text" name="longurl" />
	<input type="text" name="shorturl" />.sd.dom.com
	<input name="submit" type="submit" />
	<input type="hidden" name="token" value="<?php echo $token; ?>" />
	</form>
	<br>
	Inscriptions : 
	<strong>
  <?php echo $nombre; ?> 
  </strong>
	<br><br>
  </body>
</html>
 
<?php
$query = "SELECT * FROM `sd` ORDER BY `sd`.`shorturl` DESC";
 
if ($result = $mysqli->query($query)) {
 
  while ($row = $result->fetch_assoc()) {
    echo '- '.htmlspecialchars($row["shorturl"], ENT_QUOTES).' redirect to: http://'.htmlspecialchars($row["longurl"], ENT_QUOTES).'<br>';
  }
 
  $numbre=$result->num_rows;
 
  $result->close();
}
 
$mysqli->close();
?>
dancom5 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2011, 19h10   #2
Membre éclairé
 
Avatar de firehist
 
Homme Benjamin Longearet
Intégrateur Web Freelance
Inscription : février 2008
Messages : 153
Détails du profil
Informations personnelles :
Nom : Homme Benjamin Longearet
Âge : 24
Localisation : France

Informations professionnelles :
Activité : Intégrateur Web Freelance
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : février 2008
Messages : 153
Points : 357
Points : 357
Envoyer un message via Skype™ à firehist
Bonsoir,

Place ton script PHP avant le
Code :
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
<?php
$query = "SELECT * FROM `sd` ORDER BY `sd`.`shorturl` DESC";
 
if ($result = $mysqli->query($query)) {
 
  while ($row = $result->fetch_assoc()) {
    echo '- '.htmlspecialchars($row["shorturl"], ENT_QUOTES).' redirect to: http://'.htmlspecialchars($row["longurl"], ENT_QUOTES).'<br>';
  }
 
  $nombre=$result->num_rows;
 
  $result->close();
}
 
$mysqli->close();
?>
 
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
  </head>
  <body>
  <center><img src="logo.jpg"></center><br>
	<form action="register.php" method="POST">
	http://<input type="text" name="longurl" />
	<input type="text" name="shorturl" />.sd.dom.com
	<input name="submit" type="submit" />
	<input type="hidden" name="token" value="<?php echo $token; ?>" />
	</form>
	<br>
	Inscriptions : 
	<strong>
  <?php echo $nombre; ?> 
  </strong>
	<br><br>
  </body>
</html>
Bon dév'
__________________
Ingénieur Web Freelance - Firehist Studio
Profil Viadeo Benjamin Longearet
Geekos.fr : Blog technique sur les technologies du Web
---
Citation:
De l'innovation nait la solution et inversement
firehist est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2011, 19h21   #3
Membre du Club
 
Inscription : janvier 2010
Messages : 317
Détails du profil
Informations forums :
Inscription : janvier 2010
Messages : 317
Points : 62
Points : 62
J'ai vraiment besoin que le nombre soit affiché plus haut proche du formulaire. Autrement, je devrai le laisser après le listage après While. A moins qu'il existe une commande PHP que je ne connais pas.

Citation:
Envoyé par firehist Voir le message
Bonsoir,

Place ton script PHP avant le
Code :
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
<?php
$query = "SELECT * FROM `sd` ORDER BY `sd`.`shorturl` DESC";
 
if ($result = $mysqli->query($query)) {
 
  while ($row = $result->fetch_assoc()) {
    echo '- '.htmlspecialchars($row["shorturl"], ENT_QUOTES).' redirect to: http://'.htmlspecialchars($row["longurl"], ENT_QUOTES).'<br>';
  }
 
  $nombre=$result->num_rows;
 
  $result->close();
}
 
$mysqli->close();
?>
 
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
  </head>
  <body>
  <center><img src="logo.jpg"></center><br>
	<form action="register.php" method="POST">
	http://<input type="text" name="longurl" />
	<input type="text" name="shorturl" />.sd.dom.com
	<input name="submit" type="submit" />
	<input type="hidden" name="token" value="<?php echo $token; ?>" />
	</form>
	<br>
	Inscriptions : 
	<strong>
  <?php echo $nombre; ?> 
  </strong>
	<br><br>
  </body>
</html>
Bon dév'
dancom5 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2011, 19h31   #4
Membre Expert
 
Inscription : septembre 2010
Messages : 1 244
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 1 244
Points : 1 566
Points : 1 566
Citation:
Envoyé par dancom5 Voir le message
J'ai vraiment besoin que le nombre soit affiché plus haut proche du formulaire. Autrement, je devrai le laisser après le listage après While. A moins qu'il existe une commande PHP que je ne connais pas.
C'est pas clair. Ecris-nous plutôt le code html que tu souhaites générer.
__________________
- Réalisations
- Interface graphique : génération en javascript d'objets défilants, texte et/ou images, mode horizontal ou vertical.
ABCIWEB est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2011, 19h53   #5
Membre du Club
 
Inscription : janvier 2010
Messages : 317
Détails du profil
Informations forums :
Inscription : janvier 2010
Messages : 317
Points : 62
Points : 62
Le chiffre 16, je dois le mettre avant le listage qui est en bleu.
Ce qui est en bleu est :

Je voudrais qu'il se proche d'ici.

Code :
1
2
3
  while ($row = $result->fetch_assoc()) {
		echo '<a href="http://'.htmlspecialchars($row["longurl"], ENT_QUOTES).'" target="_blank"><strong>'.htmlspecialchars($row["shorturl"], ENT_QUOTES).'</strong></a> · ';
  }
L'affichage se trouve ici.

pièce jointe

Citation:
Envoyé par ABCIWEB Voir le message
C'est pas clair. Ecris-nous plutôt le code html que tu souhaites générer.
Images attachées
Type de fichier : jpg domain.jpg (17,3 Ko, 3 affichages)
dancom5 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2011, 21h23   #6
Membre éclairé
 
Avatar de firehist
 
Homme Benjamin Longearet
Intégrateur Web Freelance
Inscription : février 2008
Messages : 153
Détails du profil
Informations personnelles :
Nom : Homme Benjamin Longearet
Âge : 24
Localisation : France

Informations professionnelles :
Activité : Intégrateur Web Freelance
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : février 2008
Messages : 153
Points : 357
Points : 357
Envoyer un message via Skype™ à firehist
Alors ne met pas de "echo" dans ton while mais construit une variable.

Code :
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
<?php
$query = "SELECT * FROM `sd` ORDER BY `sd`.`shorturl` DESC";
$list = "";
 
if ($result = $mysqli->query($query)) {
 
  while ($row = $result->fetch_assoc()) {
    $list .= '- '.htmlspecialchars($row["shorturl"], ENT_QUOTES).' redirect to: http://'.htmlspecialchars($row["longurl"], ENT_QUOTES).'<br>';
  }
 
  $nombre=$result->num_rows;
 
  $result->close();
}
 
$mysqli->close();
?>
 
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
  </head>
  <body>
  <center><img src="logo.jpg"></center><br>
	<form action="register.php" method="POST">
	http://<input type="text" name="longurl" />
	<input type="text" name="shorturl" />.sd.dom.com
	<input name="submit" type="submit" />
	<input type="hidden" name="token" value="<?php echo $token; ?>" />
	</form>
	<br>
	Inscriptions : 
	<strong>
  <?php echo $nombre; ?> 
  </strong>
	<br><br>
	<?php echo $list; ?>
  </body>
</html>
Bonne soirée et bon dév'
__________________
Ingénieur Web Freelance - Firehist Studio
Profil Viadeo Benjamin Longearet
Geekos.fr : Blog technique sur les technologies du Web
---
Citation:
De l'innovation nait la solution et inversement
firehist est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2011, 21h58   #7
Membre du Club
 
Inscription : janvier 2010
Messages : 317
Détails du profil
Informations forums :
Inscription : janvier 2010
Messages : 317
Points : 62
Points : 62
Merci, ça fonctionne bien. bonne soirée à vous aussi!

Citation:
Envoyé par firehist Voir le message
Alors ne met pas de "echo" dans ton while mais construit une variable.

Bonne soirée et bon dév'
dancom5 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h16.


 
 
 
 
Partenaires

Hébergement Web