begin process at 2012 05 28 13:22:44
  Trouver un code source :
 
dans
 
Accueil > Forum > 

PHP

 > 

Base de données

 > 

MySQL

 > 

afficher nombre d'enregsitrement dans une table


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

afficher nombre d'enregsitrement dans une table

jeudi 8 février 2007 à 20:31:01 | afficher nombre d'enregsitrement dans une table

euro11

salut
cette page perment d'afficher le nombred'enregistrement d'une table,
donc j'ai fait:

 $res = mysql_query("SELECT * FROM reference",$con);
 $nb_enreg = mysql_num_rows($res);


mais sans résultat

-----------------------------------

<?
require("connexion.php");

$table="reference";

 

 

//_____________________________________________________________________________________

 

//_____________________________________________________________________________________


$rs=mysql_query("select * from reference",$log);


$txt1=@mysql_result($rs,0,"txt1");
$img1=@mysql_result($rs,0,"img1");

 


$rs2=mysql_query("select * from reference order by id desc limit 2",$log);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " [ Lien ]">
<html xmlns=" [ Lien ]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>


<SCRIPT TYPE="text/javascript">
<!--

function newImage(arg) {
 if (document.images) {
  rslt = new Image();
  rslt.src = arg;
  return rslt;
 }
}

function changeImages() {
 if (document.images && (preloadFlag == true)) {
  for (var i=0; i<changeImages.arguments.length; i+=2) {
   document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
  }
 }
}

var preloadFlag = false;
function preloadImages() {
 if (document.images) {
  home_over = newImage("images/home-over.gif");
  qui_over = newImage("images/qui-over.gif");
  form_over = newImage("images/form-over.gif");
  contact_over = newImage("images/contact-over.gif");
  sub2_body_mind_spirit_over = newImage("images/sub2-body-mind-spirit_over.gif");
  sub2_business___economics_over = newImage("images/sub2-business-%26-economics_o.gif");
  sub2_computers_over = newImage("images/sub2-computers_over.gif");
  sub2_family___relationships_over = newImage("images/sub2-family-%26-relationships.gif");
  sub2_health___fitness_over = newImage("images/sub2-health-%26-fitness_over.gif");
  sub2_history_over = newImage("images/sub2-history_over.gif");
  sub2_reference_over = newImage("images/sub2-reference_over.gif");
  sub2_religion_over = newImage("images/sub2-religion_over.gif");
  sub2_self_form_over = newImage("images/sub2-self-form_over.gif");
  sub2_sex_over = newImage("images/sub2-sex_over.gif");
  sub2_fiction_over = newImage("images/sub2-fiction_over.gif");
  sub2_adventure_over = newImage("images/sub2-adventure_over.gif");
  sub2_crime_over = newImage("images/sub2-crime_over.gif");
  sub2_erotica_over = newImage("images/sub2-erotica_over.gif");
  sub2_fantasy_over = newImage("images/sub2-fantasy_over.gif");
  sub2_historical_over = newImage("images/sub2-historical_over.gif");
  sub2_romance_over = newImage("images/sub2-romance_over.gif");
  sub2_science_fiction_over = newImage("images/sub2-science-fiction_over.gif");
  sub2_thrillers_over = newImage("images/sub2-thrillers_over.gif");
  sub2_non_fiction_over = newImage("images/sub2-non-fiction_over.gif");
  preloadFlag = true;
 }
}

// -->
</SCRIPT>

 

 

<style type="text/css">
<!--
.Style4 {
 font-size: 12px;
 font-weight: bold;
 color: #0142CF;
}
.Style8 {color: #0066FF}
.Style11 {color: #999999}
-->
</style>
</head>

<link href="css/styles.css" rel="stylesheet" type="text/css">

 

<body BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 ONLOAD="preloadImages();">

 

 

 

<table width="921" height="186" border="0" align="center" cellspacing="0">
  <tr>
    <td colspan="4"></td>
    <td width="7" ></td>
    <td width="0"></td>
    <td height="2" colspan="5"></td>
  </tr>
  <tr>
    <td width="7"></td>
    <td width="7"></td>
    <td width="8">&nbsp;</td>
    <td width="195"><img src="images/p1.gif" alt="" width=195 height=141 /></td>
    <td width="7" bgcolor="#FFFFFF" ></td>
    <td width="0" bgcolor="#FFFFFF"></td>
    <td height="124" colspan="4" bgcolor="#FFFFFF" align="center"><img src="images/logo2.png" width="385" height="141" alt=""></td>
    <td height="124" bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
  <tr>
    <td height="13"></td>
    <td height="13"></td>
    <td height="13"></td>
    <td height="13" bgcolor="#EFEFEF"></td>
    <td height="13" bgcolor="#EFEFEF"></td>
    <td height="13" bgcolor="#EFEFEF"></td>
    <td height="13" colspan="4" bgcolor="#EFEFEF"><span class="Style4">
      <marquee direction="left" scrollamount="6">
      Investir en immobilier vaut mieux qu'une perle dans un collier   (Proverbe Marocain)
      </marquee>
    </span></td>
    <td height="13" bgcolor="#FFFFFF"></td>
  </tr>
 
  <tr>
    <td colspan="4"></td>
    <td width="7" ></td>
    <td width="0"></td>
    <td width="158" height="23"><A HREF="index.php"
    ONMOUSEOVER="window.status='home'; changeImages('home', 'images/home-over.gif'); return true;"
    ONMOUSEOUT="window.status=''; changeImages('home', 'images/home.gif'); return true;">
    <IMG NAME="home" SRC="images/home.gif" WIDTH=158 HEIGHT=23 BORDER=0 ALT="accueil">
   </A></td>
    <td width="158"><A HREF="qui-sommes.php"
    ONMOUSEOVER="window.status='qui'; changeImages('qui', 'images/qui-over.gif'); return true;"
    ONMOUSEOUT="window.status=''; changeImages('qui', 'images/qui.gif'); return true;">
    <IMG NAME="qui" SRC="images/qui.gif" WIDTH=158 HEIGHT=23 BORDER=0 ALT="qui">
    </A></td>
    <td width="158"><A HREF="offre.php"
    ONMOUSEOVER="window.status='form'; changeImages('form', 'images/form-over.gif'); return true;"
    ONMOUSEOUT="window.status=''; changeImages('form', 'images/form.gif'); return true;">
    <IMG NAME="form" SRC="images/form.gif" WIDTH=158 HEIGHT=23 BORDER=0 ALT="form">
    
    </A></td>
    <td width="158"><A HREF="contact.php"
    ONMOUSEOVER="window.status='contact'; changeImages('contact', 'images/contact-over.gif'); return true;"
    ONMOUSEOUT="window.status=''; changeImages('contact', 'images/contact.gif'); return true;">
    <IMG NAME="contact" SRC="images/contact.gif" WIDTH=158 HEIGHT=23 BORDER=0 ALT="contact">
    
    </A></td>
    <td width="43" bgcolor="#FFFFFF"></td>
  </tr>
  <tr>
    <td colspan="11"></td>
  </tr>
</table>
<table width="891" border="0" align="center">
  <tr>
    <td width="215" height="167" valign="top"><table width="213" border="0" cellspacing="0">
      <tr>
        <td height="7" colspan="2"></td>
    <td width="201" colspan="9"><img src="images/vente.jpg" width="201" height="20" alt="" /></td>
  </tr>
  <tr>
    <td height="14" colspan="2"></td>
    <td colspan="9" bgcolor="#F2FAE4"></td>
  </tr>
  <tr>
    <td height="26" colspan="2"></td>
    <td height="26" colspan="9" bgcolor="#F2FAE4"><img
                                src="images/c1.gif"
                                border="0" width="3" height="5" /> <a
                                href="appart.php" class="Style8">APPARTEMENTS</a></td>
  </tr>
  <tr>
    <td height="3" colspan="2"></td>
    <td colspan="9" bgcolor="#F2FAE4"><img src="images/c2.gif"  height="1" alt="" /></td>
  </tr>
  <tr>
    <td height="26" colspan="2"></td>
    <td height="26" colspan="9" bgcolor="#F2FAE4"><img
                                src="images/c1.gif"
                                border="0" width="3" height="5" /> <a
                                href="villas.php" class="Style8">VILLAS</a></td>
  </tr>
  <tr>
    <td height="3" colspan="2"></td>
    <td colspan="9" bgcolor="#F2FAE4"><img src="images/c2.gif"  height="1" alt="" /></td>
  </tr>
  <tr>
    <td height="26" colspan="2"></td>
    <td height="26" colspan="9" bgcolor="#F2FAE4"><img
                                src="images/c1.gif"
                                border="0" width="3" height="5" /> <a
                                href="terrains.php" class="Style8">TERRAINS</a></td>
  </tr>
  <tr>
    <td height="3" colspan="2"></td>
    <td height="3" colspan="9" bgcolor="#F2FAE4"><img src="images/c2.gif"  height="1" alt="" /></td>
  </tr>
  <tr>
    <td height="26" colspan="2"></td>
    <td height="26" colspan="9" bgcolor="#F2FAE4"><img
                                src="images/c1.gif"
                                border="0" width="3" height="5" /> <a
                                href="fermes.php" class="Style8">FERMES</a></td>
  </tr>
  <tr>
    <td height="3" colspan="2"></td>
    <td height="3" colspan="9" bgcolor="#F2FAE4"><img src="images/c2.gif"  height="1" alt="" /></td>
  </tr>
  <tr>
    <td height="26" colspan="2"></td>
    <td height="26" colspan="9" bgcolor="#F2FAE4"><img
                                src="images/c1.gif"
                                border="0" width="3" height="5" /> <a
                                href="maisons.php" class="Style8">MAISONS</a></td>
  </tr>
  <tr>
    <td height="3" colspan="2"></td>
    <td height="3" colspan="9" bgcolor="#F2FAE4"><img src="images/c2.gif"  height="1" alt="" /></td>
  </tr>
  <tr>
    <td height="26" colspan="2"></td>
    <td height="26" colspan="9" bgcolor="#F2FAE4"><img
                                src="images/c1.gif"
                                border="0" width="3" height="5" /> <a
                                href="riads.php" class="Style8">RIADS</a></td>
  </tr>
  <tr>
    <td height="14" colspan="2"></td>
    <td height="14" colspan="9" bgcolor="#F2FAE4"></td>
  </tr>
  <tr>
    <td height="18" colspan="2"></td>
    <td height="18" colspan="9" bgcolor="#F8F9FA"><img src="images/location.jpg" width="201" height="20" alt="" /></td>
  </tr>
  <tr>
    <td height="14" colspan="2"></td>
    <td height="14" colspan="9" bgcolor="#F2FAE4"></td>
  </tr>
  <tr>
    <td height="26" colspan="2"></td>
    <td height="26" colspan="9" bgcolor="#F2FAE4"><img
                                src="images/c1.gif"
                                border="0" width="3" height="5" /> <a
                                href="l-villas.php" class="Style8">VILLAS</a></td>
  </tr>
  <tr>
    <td height="3" colspan="2"></td>
    <td height="3" colspan="9" bgcolor="#F2FAE4"><img src="images/c2.GIF" width="198" height="1" alt="" /></td>
  </tr>
  <tr>
    <td height="26" colspan="2"></td>
    <td height="26" colspan="9" bgcolor="#F2FAE4"><img
                                src="images/c1.gif"
                                border="0" width="3" height="5" /> <a
                                href="l-appart.php" class="Style8">APPARTEMENTS</a></td>
  </tr>
  <tr>
    <td height="3" colspan="2"></td>
    <td height="3" colspan="9" bgcolor="#F2FAE4"><img src="images/c2.GIF" width="198" height="1" alt="" /></td>
  </tr>
  <tr>
    <td height="67" colspan="2"></td>
    <td height="67" colspan="9" bgcolor="#F2FAE4">&nbsp;</td>
        </tr>
     
    </table></td>
    <td width="666" valign="top"><table width="200" border="0"  cellspacing="0">
      <tr>
        <td height="68" colspan="3"><? $con=mysql_connect("localhost","root","");
$base=mysql_select_db("mabase");

//-------------------------------------------------------------------------

if(!isset($_GET['pg']))
{
 $pg = 1;
}

else

{
 $pg = $_GET['pg'];
}

 


if(!is_numeric($pg))

{
 $pg = 1;
}


$con=mysql_connect("localhost","root","");

$base=mysql_select_db("mabase");


$enreg_par_pg = 3;


function pgs($enreg_par_pg, $pg, $con){

 $res = mysql_query("SELECT * FROM reference",$con);
 $nb_enreg = mysql_num_rows($res);

 
 $nb_pg_rounded = ceil( $nb_enreg / $enreg_par_pg ); 

 $pp = $pg - 1;

 $ps = $pg + 1;
 
 
 if($pg <= 1)
 {

  echo "&nbsp;&nbsp;&nbsp;   ||  $nb_pg_rounded  ||   &nbsp;&nbsp;&nbsp;<a href='?pg=$ps'>page suivante</a>";
 }

 elseif(($pg >= 1) and($pg <8))
 {
  
  echo "&nbsp;&nbsp;&nbsp;   <a href='?pg=$pp'>page précédente</a>";
  echo "&nbsp;&nbsp;&nbsp; <a href='?pg=$ps'>page suivante</a>";
 }
 

    else
 {
 echo "&nbsp;&nbsp;&nbsp;   <a href='?pg=$pp'>page précédente</a>&nbsp;&nbsp;&nbsp; page suivante "; 
 }
 
}


$limit = $enreg_par_pg*$pg-$enreg_par_pg;


$remp = mysql_query("SELECT txt1,img1,id FROM reference order by id desc LIMIT $limit, $enreg_par_pg");
//$remp = mysql_query($req4);

//$req4 ="select txt1,img1,id from reference order by id desc"; 
//$remp = mysql_query($req4);

echo "<br>";
pgs($enreg_par_pg, $pg, $link);


//-------------------------------------------------------------------------


//$req4 ="select txt1,img1,id from reference order by id desc"; 
//$remp = mysql_query($req4);
////////////////////////////////////////////////////////
//$count = mysql_num_rows($remp);
////////////////////////////////////////////////////////


$a = 0;
echo '<table><tr>';

while ($count = mysql_fetch_array($remp)) {
                echo '<td>&nbsp;&nbsp;&nbsp;</td>';
    echo '<td>';
 $k="aaaa";
 echo "";
 echo'<a href="'."source/".$count['img1'].$count['id'].".html".'"target=_"blank"'.'"><img src="'."images2/".$count['img1'].'" width="178" height="100"/><br></a>';
 echo'<b>';
 echo '<div align="center">'.$count['txt1'].'</div>';
 echo'<br>';
 echo'</td >';
              echo '<td>&nbsp;&nbsp;&nbsp;</td>';
    $a++;
    if ($a == 1) {
        echo '</tr><tr>';
        $a = 0;
    }
 
}

echo '</tr></table>';

///////////////////////////////////////////////////// ?></td>
        </tr>
     
    </table></td>
  </tr>
</table>
<table width="892" border="0" align="center" cellspacing="0">
  <tr align="center">
    <td width="11" height="21"></td>
    <td width="231" bgcolor="#EEEEEE"></td>
    <td width="4" bgcolor="#EEEEEE"><span class="Style11">|</span></td>
    <td width="72" height="21" bgcolor="#EEEEEE"><a href="index.php" class="Style8">Accueil</a></td>
    <td width="4" bgcolor="#EEEEEE"><span class="Style11">|</span></td>
    <td width="145" bgcolor="#EEEEEE"><a href="qui-sommes.php" class="Style8">Qui sommes nous?</a></td>
    <td width="4" bgcolor="#EEEEEE"><span class="Style11">|</span></td>
    <td width="126" bgcolor="#EEEEEE"><a href="offre.php" class="Style8">Formulaire d'offre</a></td>
    <td width="4" bgcolor="#EEEEEE"><span class="Style11">|</span></td>
    <td width="80" bgcolor="#EEEEEE"><a href="contact.php" class="Style8">Contact</a></td>
    <td width="4" height="21" bgcolor="#EEEEEE"><span class="Style11">|</span></td>
    <td width="151" bgcolor="#EEEEEE"></td>
    <td width="30"></td>
  </tr>
  <tr align="center">
    <td height="12" colspan="13"></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>

</html>

jeudi 8 février 2007 à 22:31:21 | Re : afficher nombre d'enregsitrement dans une table

coucou747

Administrateur CodeS-SourceS
Salut,

ajoute un or die(mysql_error());
pour avoir les messages


In a dream, I saw me, drop dead... U was there, U cried... It was just a dream, if I die, U won't cry, maybe, U'll be happy

Mon site (articles sur la programmation et programmes)
vendredi 9 février 2007 à 09:18:52 | Re : afficher nombre d'enregsitrement dans une table

coockiesch

Salut!
Pour compter le nombre d'enregistrements il vaut mieux faire:
$ret = mysql_query("SELECT COUNT(*) FROM table") or die('Erreur MySQL');
$row = mysql_fetch_row( $ret );
echo $row[0];

Que:
$ret = mysql_query( "SELECT * FROM table" ) or die( 'Erreur MySQL' );
echo mysql_num_rows( $ret );

En effet, la seconde solution récupère tous les enregistrements pour les compter (ce qui peut prendre bcp de tps is la table est grosse) tandis que, dans la première solution, MySQL compte et ne renvoie que le résultat! :)

@++

R@f

La boîte à bouts de codes
"On dit que seulement 10 personnes au monde comprenaient Einstein. Personne ne me comprends. Suis-je un génie???"
dimanche 11 février 2007 à 19:04:31 | Re : afficher nombre d'enregsitrement dans une table

stu76

Membre Club
Salut,

Moi perso, j'utilise la fonction count en sql pour compter les nombres d'enregistrements dans une table. Rapide et éfficace.

Si tu veux je t'envois un modèle de script que j'utilise dans une de mes applications. Mais la je suis pas chez moi .

Sinon fait recherche sur la fonction count de sql.

++

Stu76


Cette discussion est classée dans : images, gif, nbsp, over, sub2


Répondre à ce message

Sujets en rapport avec ce message

code anti-robot spam, rassembler des images pr n'en faire qu'une... ? [ par netwebzone ] Bonjour,Vous savez qu'il y a beaucoup de robots de spam qui scrutent le web et donc j'aimerais les empecher de remplir mes formulaires en créant un co Lecture d'un dossier... [ par RockmanX ] Voila mon "problème":Dans le dossier ci-dessous, il y a des images nommées:smile1.gif,smile2.gif,...smile8.gifj''ai écrit le script ci-dessous mais au Inclure a partir d'un rep different [ par fabiin ] Salutavoir voila mon problème:J'ai un fichier/dossier/monfichier.phpki inclu une page /page.phpet dans cette page il y a une image /images/machin.gifO comment Modifier l'interface de JMstudio? [ par yaanovitch78 ] bonjour à vous tous, cela fait maintenant quelque mois que j'etudie le language JAVA ( notemment la JMF), mais je suis encore un pauvre débutant. En échanges intervalles réguliers d'images [ par kartoon ] Bonsoir!J'ai des images(dans une popup) déclarées comme ceci:var image = new Image();new Image = ('n1.gif','n2.gif','n3.gif','n4.gif','n5.gif','n6.gif Affichage de resultat sans rapport avec mots-clés [ par ewertheimer ] Bonjour, Je me suis servi d'un tutorial pour essayer de crér un moteur de recherche pour mon site. Cependant, j'ai un petit probleme c'est que les res probleme de galerie [ par emieno ] bonjour j'ai un gros ou plutot  un petit probleme avec ma galerie  ( la voici => ma ga<img src="/im compteur de vie [ par jujulagor ] Salut les spécialistes,Je débute ds la programmation et j'ai besoin de vos talents.Voila le souci, pour la naissance de mon fils j'ai crée un site et probleme d'insertion de données dans une base de données à partir d'un formulaire [ par stageman ] Bonjour,Voila je suis nouveau sur ce forum et ceci est mon premier post.Je suis actuellement en stage dans une entreprise dans le cadre de mon DUT.J'a Site PHP SQL sur Free probleme images [ par regisgb17 ] Bonjour, J'ai fait un site en php et mysql: http://alpesfaune.free.frIl fonctionne bien so


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,186 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales