Lien vers id suivant et précédant besoin d'aide !

adparker Messages postés 6 Date d'inscription mardi 7 février 2006 Statut Membre Dernière intervention 15 août 2007 - 13 août 2007 à 20:05
coucou747 Messages postés 12303 Date d'inscription mardi 10 février 2004 Statut Membre Dernière intervention 30 juillet 2012 - 15 août 2007 à 21:04
Bonjour, j'ai besoin d'un peu d'aide, je suis en train de créer un script php pour une gestion de video que je vais mettre sur mon site quand il sera fini, mais j'ai un petit problème. J'aimerais crée des liens vers les id suivant et précédant, jusque la, tout va bien, mais lorsque l'on affiche la dernière id, il y a un lien vers une id qui n'existe pas.

Voila une partie de mon script php, et j'aimerai l'améliorer.
J'aimerai que lorsque l'on est à la dernière id, ou a la premiere, le bouton change, pour le bouton précédent, se serai video/design/bot1_hs.jpg et pour le bouton suivant, video/design/bot2_hs.jpg

Merci beaucoup

<?php

$result=mysql_query("SELECT * FROM video WHERE id='".$_GET["id"]."'");
if ($row=mysql_fetch_array($result)) {
   echo '<th scope="col">[video.php?id='.$precedent.' ]</th>
            <th scope="col">[video.php?id='.$suivant.' ]</th></tr>
        </table></th>
      </tr>
      <tr>
        <th scope="row"></th>
      </tr>
    </table></td>
  </tr>
</table>

';
}

?>
A voir également:

10 réponses

Evangun Messages postés 1980 Date d'inscription dimanche 20 février 2005 Statut Membre Dernière intervention 24 septembre 2012 4
13 août 2007 à 20:40
Salut,

je ne comprends pas trop ton bout de code mais bon...

Avec mysql_num_row($result) tu peux connaitre le nombre de ligne renvoyées. Ainsi tu peux :
- traiter la ligne *1* comme tu veux
- faire une boucle qui ira de 2 à *mysql_num_row($result) - 1*
- traiter la ligne *mysql_num_row($result)* comme tu veux

j'espère que ça t'aidera
à+
0
kishkaya Messages postés 365 Date d'inscription samedi 26 juin 2004 Statut Membre Dernière intervention 17 avril 2008
13 août 2007 à 21:00
Bonjour,
C'est vrai que ton code HTML veut pas dire grand chose, il doit manquer le début.
Fait gaffe aux injections SQL avec ta variable GET.

_Marikou
0
coucou747 Messages postés 12303 Date d'inscription mardi 10 février 2004 Statut Membre Dernière intervention 30 juillet 2012 44
13 août 2007 à 21:47
Salut

$result2=mysql_query('SELECT id, nom, ...

 FROM video WHERE id<"'.$_GET['id'].'" ORDER BY id DESC LIMIT 1') or die(mysql_error());

$result1=mysql_query('SELECT

id, nom, ...


 FROM video WHERE id>"'.$_GET['id'].'" ORDER BY id ASC LIMIT 1' )or die(mysql_error());

list($precedent_id, $precedent_nom ...)=mysql_fetch_rows($result2);
list($suivant_id, $suivant_nom ...)=mysql_fetch_rows($result1);

...

ensuite, il ne te reste plus que des echo

<hr />une recherche sur exalead vous aurait peut-etre evite de poser cette question

In a dream, I saw me, drop dead...
U were there, U cried...
It was just a dream,
if I die, U won't cry, maybe, U'll be happy
0
adparker Messages postés 6 Date d'inscription mardi 7 février 2006 Statut Membre Dernière intervention 15 août 2007
14 août 2007 à 14:24
Oui, je sais que tout mon code n'y est pas, mais le voila en entier !
config.php :
---------------------------------------------------------------------------------------------------------
<?php
//variables de connection à la base de donnée
$host = 'localhost'; //nom de l' host
$user = 'root'; //pseudo du compte sql
$pass= ''; //mot de passe du compte sql
$bdd = 'adparker'; //nom de la base de donnée.
$table = 'video'; //nom de la table sql des videos






mysql_connect($host, $user, $pass); //connexion à mysql
  mysql_select_db($bdd); //sélection de la base de données
?>




Video.php :

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

<head>
<script type="text/javascript" src="swfobject.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
 font-family: Arial, Helvetica, sans-serif;
 font-size: 10px;
 color: #000000;
}
-->
</style></head>






<?php
include("admin/config.php");
if (isset($_GET['id'])) 
{
 $num = $_GET['id']; $result mysql_query("SELECT id,titre,description,nom,adresse,photo,temps,date FROM " . $table . " WHERE id '$num'");
 while($row = mysql_fetch_array($result))
echo '
  ----

    |
 
  ----

    |
    <td width =\"350\" align= \"left\" valign=\"top\"><table width=\"350\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
      ----

       
http://www.macromedia.com/go/getflashplayer">Get

the Flash Player to see this player.

<script type="text/javascript">
 var s1 = new SWFObject("flvplayer.swf","single","350","300","7");
 s1.addParam("allowfullscreen","true");
 s1.addVariable("file","video/'.$row['nom'].'");
 s1.addVariable("image","video/'.$row['photo'].'");
 s1.write("player1");
</script> |
     
     
   
</td>
    <td width ="300" align= "left" valign="top">      ----

        |
     
      ----

        <table width ="300" border= "0" cellspacing="0" cellpadding="0">
          ----

           
|</th>
            <table width="264" border="0" cellspacing="0" cellpadding="0">
              ----

                |

    <table width =\"264\" border= \"0\" cellspacing=\"0\" cellpadding=\"0\">
                  ----

                    <th align=\"left\" class=\"Style4\" scope=\"col\"> <table width=\"50%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  ----

    Info: '.$row['titre'].',
 

</th>
                  </tr>
                  <tr>
                    <th nowrap="nowrap" background="design/bar.jpg" scope="row">&nbsp;&nbsp;&nbsp;&nbsp;</th>
                  </tr>
                  <tr>
                    <th align="left" valign="middle" scope= "row">&nbsp;&nbsp; Dur&eacute;e : </th>
                  </tr>
                  <tr>
                    <th align ="left" valign="middle" scope= "row">&nbsp;&nbsp; Date&nbsp;&nbsp;&nbsp;: </th>
                  </tr>
                  <tr>
                    <th align ="left" valign="middle" scope= "row">&nbsp;&nbsp; D&eacute;scription : </th>
                  </tr>
                  <tr>
                    <th scope ="row">

                                              ----

                          &nbsp; |
                          '.$row['description'].' |
                       
                     

                   
</th>
                  </tr>
                  <tr>
                    <th align ="left" valign= "middle" scope="row">&nbsp;&nbsp;URL :
                      <label for="textfield"></label>
                     
                    </th>
                  </tr>
                </table>
    
</th>
              </tr>
              <tr>
                <th scope="row"></th>
              </tr>
            </table></th>
            <th width="16" scope="col"></th>
          </tr>
        </table></th>
      </tr>
      <tr>
        <th scope="row">          ----
';
     $id=$_GET[\"id\"];
  $id1=$_GET[\"id\"];
  $precedent=--$id;
  $suivant=++$id1;
 
 
$result=mysql_query(\"SELECT * FROM video WHERE id='\".$_GET[\"id\"].\"'\");
if ($row=mysql_fetch_array($result)) {
   echo ' |
            |
       
</th>
      </tr>
      <tr>
        <th scope ="row"></th>
      </tr>
    </table></td>
  </tr>
</table>

';
}
}
?> 
<?






$sql = "SELECT * FROM " . $table . " ORDER BY id ASC";
 $result = mysql_query($sql) or die('Erreur SQL : '.mysql_error());






if(mysql_numrows($result) == "0")
  {
  echo'Il n\'y a pas encore de video.';
  }
while ($row = mysql_fetch_array($result)) {
    $t[] = $row;
}
echo'';
$n = 3; // nb de colonne
for($i = 0; $i <= (count($t) - 1); $i ++) {
  if ($i % $n == 0) {
    echo'----
';
  }
   echo'<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#000000" width="200">
    ----

     ,
      </td>
   
    ----

            '.$t[$i]['titre'].',
   
    ----

     
      ,
           
     
      ,
   
   

</td>';
  if ($i % $n == (2)) {
    echo'</tr>';
  }
}
?>
</table>







</html>
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
adparker Messages postés 6 Date d'inscription mardi 7 février 2006 Statut Membre Dernière intervention 15 août 2007
14 août 2007 à 19:38
Pas d'idées ?
0
Evangun Messages postés 1980 Date d'inscription dimanche 20 février 2005 Statut Membre Dernière intervention 24 septembre 2012 4
14 août 2007 à 21:59
On t'a donné des solutions, que veux-tu de plus ?
0
adparker Messages postés 6 Date d'inscription mardi 7 février 2006 Statut Membre Dernière intervention 15 août 2007
15 août 2007 à 18:33
oui, mais je ne sais pas comment faire


 
0
coucou747 Messages postés 12303 Date d'inscription mardi 10 février 2004 Statut Membre Dernière intervention 30 juillet 2012 44
15 août 2007 à 18:39
Salut

$result2=mysql_query('SELECT id, nom, ...
 FROM video WHERE id<"'.$_GET['id'].'" ORDER BY id DESC LIMIT 1') or die(mysql_error());

$result1=mysql_query('SELECT
id, nom, ...

 FROM video WHERE id>"'.$_GET['id'].'" ORDER BY id ASC LIMIT 1' )or die(mysql_error());

list($precedent_id, $precedent_nom ...)=mysql_fetch_rows($result2);
list($suivant_id, $suivant_nom ...)=mysql_fetch_rows($result1);

echo $suivant_nom.'   => '.$suivant_id.'<hr/>'.
$precedent_nom.'   => '.$precedent_id.'<hr/>';

t'as teste au moins ??? ca donne un message d'erreur ???

<hr />une recherche sur exalead vous aurait peut-etre evite de poser cette question

In a dream, I saw me, drop dead...
U were there, U cried...
It was just a dream,
if I die, U won't cry, maybe, U'll be happy
0
adparker Messages postés 6 Date d'inscription mardi 7 février 2006 Statut Membre Dernière intervention 15 août 2007
15 août 2007 à 20:59
Merci beaucoup, je testerai cela demain
0
coucou747 Messages postés 12303 Date d'inscription mardi 10 février 2004 Statut Membre Dernière intervention 30 juillet 2012 44
15 août 2007 à 21:04
Salut

je ne sais pas si tu te rends compte... mais t'as la reponse depuis deja deux jours... et entre temps, t'as dit "pas d'idees ?"

<hr />une recherche sur exalead vous aurait peut-etre evite de poser cette question

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