Précédent   Forum des professionnels en informatique > Bases de données > MySQL > SQL Procédural
SQL Procédural Forum d'entraide sur les triggers, les procédures stockées et les fonctions en 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 10/04/2007, 17h00   #1
Invité régulier
 
Inscription : avril 2007
Messages : 8
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 8
Points : 7
Points : 7
Par défaut interroger une bdd via une page web

Salut a tous ,
Je suis nouveau sur ce forum , et la programmation n'est pas mon fort .
Voici mon probléme je souhaite interroger une BDD via une page web , je m'explique on arrive sur une page nommé " essai.htm " on nous demande de rentrer une référence a 7 chiffres cette page nous redirige vers une page nommé " search.php3 " qui s'occupe de se connecter a la base , d'executer la requete sql en fonction de la référence entré auparavant .

Code de la page search.php3
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<html>
<head>
<title>Stock par magasins</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<?php
$link = mysql_connect("localhost","root","");//connexion LOCAL
mysql_select_db("bata",$link);
$query = " select num_art,num_mag,type_grille,total_stock,stockpt1,stockpt2,stockpt3,stockpt4,stockpt5,stockpt6,stockpt7,stockpt8,stockpt9,stockpt10,stockpt11,stockpt12,stockpt13,stockpt14 from articles,magasins,stock,grille where
stock.magasin = magasins.num_mag AND stock.ref_art = articles.num_art AND articles.grille_art=grille.type_grille AND num_art = ".$_POST["num_art"];
 
//.$_POST["num_mag"];
//.$_POST["num_art"];
$result = mysql_query($query,$link);//ON interroge la base
$html = "<table width='30%' border='1'><tr>
<td width='20%'><b><font color=red>Articles</font></b></td>
<td width='20%'><b><font color=red>Magasins</font></b></td>
<td width='20%'><b><font color=red>grille</font></b></td>
<td width='20%'><b><font color=#FF0000>Stock total</font></b></td>
<td width='20%'><b><font color=red>stockpt1</font></b></td>
<td width='20%'><b><font color=red>Stockpt2</font></b></td>
<td width='20%'><b><font color=red>Stockpt3</font></b></td>
<td width='20%'><b><font color=red>Stockpt4</font></b></td>
<td width='20%'><b><font color=red>Stockpt5</font></b></td>
<td width='20%'><b><font color=red>Stockpt6</font></b></td>
<td width='20%'><b><font color=red>Stockpt7</font></b></td>
<td width='20%'><b><font color=red>Stockpt8</font></b></td>
<td width='20%'><b><font color=red>Stockpt9</font></b></td>
<td width='20%'><b><font color=red>Stockpt10</font></b></td>
<td width='20%'><b><font color=red>Stockpt11</font></b></td>
<td width='20%'><b><font color=red>Stockpt12</font></b></td>
<td width='20%'><b><font color=red>Stockpt13</font></b></td>
<td width='20%'><b><font color=red>Stockpt14</font></b></td>
</tr>";
while ($row = mysql_fetch_array($result)){
$html .= "<tr>
<td>".$row["num_art"]."</td>
<td>".$row["num_mag"]."</td>
<td>".$row["type_grille"]."</td>
<td>".$row["total_stock"]."</td>
<td>".$row["stockpt1"]."</td>
<td>".$row["stockpt2"]."</td>
<td>".$row["stockpt3"]."</td>
<td>".$row["stockpt4"]."</td>
<td>".$row["stockpt5"]."</td>
<td>".$row["stockpt6"]."</td>
<td>".$row["stockpt7"]."</td>
<td>".$row["stockpt8"]."</td>
<td>".$row["stockpt9"]."</td>
<td>".$row["stockpt10"]."</td>
<td>".$row["stockpt11"]."</td>
<td>".$row["stockpt12"]."</td>
<td>".$row["stockpt13"]."</td>
<td>".$row["stockpt14"]."</td>
</tr>";
}
$html .= "</table>";
echo $html; //ON affiche la variable $html
mysql_free_result($result);
mysql_close($link);//ON se d&#65533;connecte
?>
</body>
</html>

partie du code essai.htm

Code :
1
2
3
4
5
6
7
8
9
10
<div align="center"><form method="post" action="search.php3">
 
<br>
 
Entrez un num&#65533;ro d'article   : <input type="text" name="num_art" size="7" id="num_art" maxlength="7"><br>
 
 
                               <input type="submit" value="Rechercher" alt="Lancer la recherche!">
 
</form></div>


Voici ce que j'obtiens :
Code :
Articles Magasins grille Stock total stockpt1 Stockpt2 Stockpt3 Stockpt4 Stockpt5 Stockpt6 Stockpt7 Stockpt8 Stockpt9 Stockpt10 Stockpt11 Stockpt12 Stockpt13 Stockpt14 "; while ($row = mysql_fetch_array($result)){ $html .= " ".$row["num_art"]." ".$row["num_mag"]." ".$row["type_grille"]." ".$row["total_stock"]." ".$row["stockpt1"]." ".$row["stockpt2"]." ".$row["stockpt3"]." ".$row["stockpt4"]." ".$row["stockpt5"]." ".$row["stockpt6"]." ".$row["stockpt7"]." ".$row["stockpt8"]." ".$row["stockpt9"]." ".$row["stockpt10"]." ".$row["stockpt11"]." ".$row["stockpt12"]." ".$row["stockpt13"]." ".$row["stockpt14"]." "; } $html .= ""; echo $html; //On affiche la variable $html mysql_free_result($result); mysql_close($link);//on se d&#65533;connecte ?>

Je ne demande pas forcement de résoudre mon probléme mais des éléments de réponse qui puissent m'aider a comprendre .
Sans oublier je suis sur fedora core 6 et j'utilise PhpMyAdmin
Merci d'avance .
lafrite972 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/04/2007, 18h01   #2
Membre éclairé
 
Avatar de Space Cowboy
 
Inscription : avril 2005
Messages : 495
Détails du profil
Informations forums :
Inscription : avril 2005
Messages : 495
Points : 306
Points : 306
Je n'ai pas trop envies d'essaye ton code, mais si tu n'a pas donné ton problème ... juste le code, c'est à nous de trouver le problème ?
Space Cowboy est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/04/2007, 18h14   #3
Invité régulier
 
Inscription : avril 2007
Messages : 8
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 8
Points : 7
Points : 7
Ben si j'ai dis c'est quoi mon probléme , alors quand je test tout ca voici ce que j'obtiens :

Citation:
Articles Magasins grille Stock total stockpt1 Stockpt2 Stockpt3 Stockpt4 Stockpt5 Stockpt6 Stockpt7 Stockpt8 Stockpt9 Stockpt10 Stockpt11 Stockpt12 Stockpt13 Stockpt14 "; while ($row = mysql_fetch_array($result)){ $html .= " ".$row["num_art"]." ".$row["num_mag"]." ".$row["type_grille"]." ".$row["total_stock"]." ".$row["stockpt1"]." ".$row["stockpt2"]." ".$row["stockpt3"]." ".$row["stockpt4"]." ".$row["stockpt5"]." ".$row["stockpt6"]." ".$row["stockpt7"]." ".$row["stockpt8"]." ".$row["stockpt9"]." ".$row["stockpt10"]." ".$row["stockpt11"]." ".$row["stockpt12"]." ".$row["stockpt13"]." ".$row["stockpt14"]." "; } $html .= ""; echo $html; //On affiche la variable $html mysql_free_result($result); mysql_close($link);//on se d�connecte ?>
ou encore :
Code :
1
2
 
Articles Magasins grille Stock total stockpt1 Stockpt2 Stockpt3 Stockpt4 Stockpt5 Stockpt6 Stockpt7 Stockpt8 Stockpt9 Stockpt10 Stockpt11 Stockpt12 Stockpt13 Stockpt14 "; while ($row = mysql_fetch_array($result)){ $html .= " ".$row["num_art"]." ".$row["num_mag"]." ".$row["type_grille"]." ".$row["total_stock"]." ".$row["stockpt1"]." ".$row["stockpt2"]." ".$row["stockpt3"]." ".$row["stockpt4"]." ".$row["stockpt5"]." ".$row["stockpt6"]." ".$row["stockpt7"]." ".$row["stockpt8"]." ".$row["stockpt9"]." ".$row["stockpt10"]." ".$row["stockpt11"]." ".$row["stockpt12"]." ".$row["stockpt13"]." ".$row["stockpt14"]." "; } $html .= ""; echo $html; //On affiche la variable $html mysql_free_result($result); mysql_close($link);//on se d&#65533;connecte ?>
lafrite972 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/04/2007, 18h22   #4
Membre éclairé
 
Avatar de Space Cowboy
 
Inscription : avril 2005
Messages : 495
Détails du profil
Informations forums :
Inscription : avril 2005
Messages : 495
Points : 306
Points : 306
Autant pour moi.
http://fr2.php.net/manual/en/functio...etch-array.php

Code :
1
2
3
4
5
6
$sql = 'SELECT * FROM `panne` ORDER BY `date` DESC';
$res = mysql_query($sql);
while($data=@mysql_fetch_assoc($res))
{
echo $data['id'];
}
mysql-fetch-array => Numérique
mysql_fetch_assoc => Nom des champ

Moi j'utilise une classe pour ma connexion, c'est beaucoup plus simple.
Space Cowboy 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 10h02.


 
 
 
 
Partenaires

Hébergement Web