Page 1 sur 1

aide pour requete en tableau

Posté : 03 nov. 2008, 03:23
par boulon
Bonjour, je viens encore soliciter votre aide,

voila mon probleme j'ai une requete qui me revoit des informations d'une de mes tables pour l'afficher sur mon site. Il me les affiches en largeur, jusque là tout va bien. mais le souci c'es ça

Image

il fait beugé la page et les resultats dépase, comment faire comprendre a la requete qu'il m'affiche X nombres par ligne, comme sur ce screen(que j'ai retouché pour faire voir le resutat final)

Image

voila mon script si ça peu aidé
<?php 
echo '
<table cellpadding=0 cellspacing=0 width="">
  <tr>
    <td><table width="" border="1" align=center cellpadding=0 cellspacing=0>
      <tr align=center>
        <td height="25" colspan=2><center><b>Sur Lui</b></center></td>
      </tr>
      <tr valign=top>
        <td width=""><table width="" height="" border="1">
          <tr>';
$info2 =  mysql_query("SELECT * FROM items WHERE owner_id='".$_GET['charId']."' and loc='PAPERDOLL' ");
while ($info=mysql_fetch_array($info2)) {
echo '
<td><b><center><img src="images/items/'.$info['item_id'].'.gif"></center></b></td>
';
}
echo'</tr></table></table></table><br>';
echo '<table cellpadding=0 cellspacing=0 width="">
  <tr>
    <td><table width="" border="1" align=center cellpadding=0 cellspacing=0>
      <tr align=center>
        <td height="25" colspan=2><center><b>Dans L\'inventaire</b></center></td>
      </tr>
      <tr valign=top>
        <td width="85"><table width="" height="" border="1">
          <tr>';
$info2 =  mysql_query("SELECT * FROM items WHERE owner_id='".$_GET['charId']."' and loc='INVENTORY' ");
while ($info=mysql_fetch_array($info2)) {
echo '
<td><b><center><img src="images/items/'.$info['item_id'].'.gif"></center></b></td>
';
}
echo'</tr></table></table></table><br>';
echo '
<table cellpadding=0 cellspacing=0 width="">
  <tr>
    <td><table width="" border="1" align=center cellpadding=0 cellspacing=0>
      <tr align=center>
        <td height="25" colspan=2><center><b>WareHouse</b></center></td>
      </tr>
      <tr valign=top>
        <td width="80"><table width="" height="" border="1">
          <tr>';
$info2 =  mysql_query("SELECT * FROM items WHERE owner_id='".$_GET['charId']."' and loc='WAREHOUSE' ");
while ($info=mysql_fetch_array($info2)) {
echo '
<td><b><center><img src="images/items/'.$info['item_id'].'.gif"></center></b></td>
';
}
echo'</tr></table></table></table>';

Merci de m'aider s'il vous plai

Cordialement Boulon D Monkey

Posté : 03 nov. 2008, 08:50
par yaug
En fait, ce n'est pas la requête en elle même que tu dois impacter mais uniquement son traitement.

Typiquement, on peut faire comme ceci :
<?php
$nb_par_ligne = 10;
$str = '<table>';

$info2 = array(
	array('item_id' => '1'), 
	array('item_id' => '2'), 
	array('item_id' => '3'), 
	array('item_id' => '4'), 
	array('item_id' => '5'), 
	array('item_id' => '6'), 
	array('item_id' => '7'), 
	array('item_id' => '8'), 
	array('item_id' => '9'), 
	array('item_id' => '10'), 
	array('item_id' => '11'), 
	array('item_id' => '12')
);
$cpt = 1;

//On construit ton tableau
foreach($info2 as $data){
		if($cpt % $nb_par_ligne == 1) $str .= '<tr>';
		$str .= '<td><img src="images/items/'.$info['item_id'].'.gif"></td> ';
		if($cpt % $nb_par_ligne == 0) $str .= '</tr>';
		$cpt++;
}

//On le complète si une ligne à moins de 10 éléments
$colspan = $nb_par_ligne - ($cpt - 1)%$nb_par_ligne	;
if($colspan > 0 && $colspan != 10) $str.= '<td colspan='.$colspan.'>&nbsp;</td>';

$str .= '</table>';
echo $str;
?>

Posté : 03 nov. 2008, 09:21
par boulon
comment je rajoute ca dans mon code doi-je tout modiffier ou juste rajouter le bout de ton code je rapel que je suis debutant..

merci de m'eclairer sur la marche a suivre

si tu pouvai me metre le code final ca m' arangerai. merci :P

P.S probleme resolut LOl merci de m'avoir mis sur la voie...

cordialment boulon