begin process at 2012 05 31 03:15:59
  Trouver un code source :
 
dans
 
Accueil > Forum > 

PHP

 > 

Base de données

 > 

MySQL

 > 

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


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

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

lundi 13 août 2007 à 20:05:42 | Lien vers id suivant et précédant besoin d'aide !

adparker

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"><a href="video.php?id='.$precedent.'"><img src="video/design/bot1_ok.jpg" width="151" height="27" border="0"/></a></th>
            <th scope="col"><a href="video.php?id='.$suivant.'"><img src="video/design/bot2_ok.jpg" width="149" height="27" border="0" /></a></th></tr>
        </table></th>
      </tr>
      <tr>
        <th scope="row"><img src="video/design/7.jpg" width="300" height="16" /></th>
      </tr>
    </table></td>
  </tr>
</table><br />
';
}

?>

lundi 13 août 2007 à 20:40:25 | Re : Lien vers id suivant et précédant besoin d'aide !

Evangun

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
à+
lundi 13 août 2007 à 21:00:24 | Re : Lien vers id suivant et précédant besoin d'aide !

kishkaya

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
lundi 13 août 2007 à 21:47:04 | Re : Lien vers id suivant et précédant besoin d'aide !

coucou747

Administrateur CodeS-SourceS
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


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
mardi 14 août 2007 à 14:24:20 | Re : Lien vers id suivant et précédant besoin d'aide !

adparker

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 '
<table width="611" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <th colspan="3" scope="col"><img src="video/design/1.jpg" width="700" height="76" /></th>
  </tr>
  <tr>
    <th width="50" align="left" valign="top" scope="row"><img src="video/design/2.jpg" width="50" height="324" /></th>
    <td width="350" align="left" valign="top"><table width="350" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th width="4" height="324" align="center" valign="top" nowrap="nowrap" background="video/design/fond.jpg" scope="col">
<p id="player1"><a href="
http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<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>
</th>
      </tr>
     
    </table></td>
    <td width="300" align="left" valign="top"><table width="300" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th align="left" valign="top" scope="col"><img src="video/design/3.jpg" width="300" height="131" /></th>
      </tr>
      <tr>
        <th scope="row"><table width="300" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <th width="16" scope="col"><img src="video/design/4.jpg" width="16" height="150" /></th>
            <th scope="col"><table width="264" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <th height="128" align="left" valign="middle" scope="col"><div align="center"><span class="Style4">
    <table width="264" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <th align="left" class="Style4" scope="col"> <table width="50%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="left"> Info: '.$row['titre'].'</td>
  </tr>
</table>
</th>
                  </tr>
                  <tr>
                    <th nowrap="nowrap" background="design/bar.jpg" scope="row"><span class="Style6">&nbsp;&nbsp;&nbsp;&nbsp;</span></th>
                  </tr>
                  <tr>
                    <th align="left" valign="middle" scope="row"><span class="Style4">&nbsp;&nbsp;<u><em>Dur&eacute;e :</em></u> '.$row['temps'].'</span> </th>
                  </tr>
                  <tr>
                    <th align="left" valign="middle" scope="row"><span class="Style4">&nbsp;&nbsp;<u><em>Date&nbsp;&nbsp;&nbsp;:</em></u>'.$row['date'].'</span></th>
                  </tr>
                  <tr>
                    <th align="left" valign="middle" scope="row"><span class="Style4">&nbsp;&nbsp;<u><em>D&eacute;scription :</em></u></span></th>
                  </tr>
                  <tr>
                    <th scope="row"><div align="left">
                      <table width="264" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <th width="5" scope="col">&nbsp;</th>
                          <th width="254" scope="col"><div align="left"><strong><span class="Style5">'.$row['description'].'</span></strong></div></th>
                        </tr>
                      </table>
                    </div></th>
                  </tr>
                  <tr>
                    <th align="left" valign="middle" scope="row"><span class="Style4">&nbsp;&nbsp;<u><em>URL :</em></u>
                      <label for="textfield"></label>
                      <input name="textfield" type="text" id="textfield" value="'.$row['adresse'].'" size="32" />
                    </span></th>
                  </tr>
                </table>
    </span></div></th>
              </tr>
              <tr>
                <th scope="row"><img src="video/design/6.jpg" width="264" height="22" /></th>
              </tr>
            </table></th>
            <th width="16" scope="col"><img src="video/design/5.jpg" width="20" height="150" /></th>
          </tr>
        </table></th>
      </tr>
      <tr>
        <th scope="row"><table width="300" border="0" cellspacing="0" cellpadding="0">
          <tr>';
     $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 scope="col"><a href="video.php?id='.$precedent.'"><img src="video/design/bot1_ok.jpg" width="151" height="27" border="0"/></a></th>
            <th scope="col"><a href="video.php?id='.$suivant.'"><img src="video/design/bot2_ok.jpg" width="149" height="27" border="0" /></a></th></tr>
        </table></th>
      </tr>
      <tr>
        <th scope="row"><img src="video/design/7.jpg" width="300" height="16" /></th>
      </tr>
    </table></td>
  </tr>
</table><br />
';
}
}
?> 
<?

$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'<table width="660" border="0" align="center">';
$n = 3; // nb de colonne
for($i = 0; $i <= (count($t) - 1); $i ++) {
  if ($i % $n == 0) {
    echo'<tr>';
  }
   echo'<td width="220" align="center"><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#000000" width="200">
    <tr>
      <td width="25%" colspan="2">
      <p align="center"><img src="video/'.$t[$i]['photo'].'" alt="'.$t[$i]['titre'].'" width="100" height="85" border="0"></td>
    </tr>
    <tr>
      <td width="25%" colspan="2">
      <p align="center">'.$t[$i]['titre'].'</td>
    </tr>
    <tr>
      <td width="7%"><A HREF="?id='.$t[$i]['id'].'">
      <img border="0" src="images/lecture.jpg" width="100" height="25"></a></td>
      <td width="18%">
      <p align="right">
      <a target="_blank" href="'.$t[$i]['adresse'].'">
      <img border="0" src="images/telecharger.jpg" width="100" height="25"></a></td>
    </tr>
  </tr> 
</table>
<br></td>';
  if ($i % $n == (2)) {
    echo'</tr>';
  }
}
?>
</table>

</body>
</html>

mardi 14 août 2007 à 19:38:29 | Re : Lien vers id suivant et précédant besoin d'aide !

adparker

Pas d'idées ?

mardi 14 août 2007 à 21:59:01 | Re : Lien vers id suivant et précédant besoin d'aide !

Evangun

On t'a donné des solutions, que veux-tu de plus ?
mercredi 15 août 2007 à 18:33:45 | Re : Lien vers id suivant et précédant besoin d'aide !

adparker

oui, mais je ne sais pas comment faire

 

mercredi 15 août 2007 à 18:39:37 | Re : Lien vers id suivant et précédant besoin d'aide !

coucou747

Administrateur CodeS-SourceS
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 ???


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
mercredi 15 août 2007 à 20:59:43 | Re : Lien vers id suivant et précédant besoin d'aide !

adparker


Merci beaucoup, je testerai cela demain


1 2

Cette discussion est classée dans : aide, lien, video, id, précédant


Répondre à ce message

Sujets en rapport avec ce message

help! [ par LeRoux ] Je ne suis pas un pro. de PHP, mais j'aimerais savoir comment ouvrir, dans une page html, un id que le n'on connait pas auparavent: j'ai une feuille d lien du type nom.php?id=x [ par apego ] Bonjour,Je débute et je n'arrive pas à cerber ce que représentent les caractères qui suivent les url ...... je m'explique :Pour ce lien :http://www.ph Aide SVP accès urgent ;) [ par cyrilnd01 ] Bonjour à tous,Voila je me suis crée un script qui me permet d'afficher aléatoire des bannieres plublicitaire(...) mets j'ai un problèmevoila j'expliq Aide plz :) [ par zzzzzz ] helloEn fait j'aimerai supprimé par exemple le deuxieme insert d'une table. J'ai pensser a un champs id auto increment mais le blem c que csi par exem chti pb de lien [ par attentio ] salut !question a la conj'ai un probleme avec un lien qui m'envoi vers la page page2.php?new=$idet non vers la page : page2.php?new=id_numero_4comme upload de fichier video format wvm [ par laurentbalmer ] voilà mon problème j'ai réalisé un formulaire pour uploder des images gif ou jpg sa marche tres bien mais pour une vidéo au format wvm il rempli biens lien sur un bouton [ par troupe_a_jule ] julesalut c'est encore qui vient t'embéterj'ai encore un petit problème si tu pourrait m'aider ce serait trop sympaen faite je veut mettre un lien sur prob lien [ par cobrachris ] Bonsoir,je viens de refaire la construction de mes pages.je fais :  include('menu.php');?> <d Recherche aide desesperement [ par Croute ] CrouteBonjour tout le monde,J'ai plusieurs questions:1)Tout d'abord sur les sessions Je sais qu'il faut commencera creer un session avant BESOIN D AIDE [ par BIBICHOCOLAT ] BONJOUR,J ai besoin d un coup de main !!!j ai un formulaire qui genere un tableau grace a la base de donnee ce tableau contient un lien, j aimerais qu


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

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 : 0,421 sec (4)

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