Transformer une variable en lien

Modérateur PHPfrance
Modérateur PHPfrance | 7636 Messages

04 sept. 2005, 21:25

Je voudrais transformer la variable link2 extrait de ma table radioshow en lien pointant vers /mix/link2, (link2 étant en fait le nom du fichier à télécharger inscrit dans ma base, du type monlien.mp3)
David
Si j'ai bien compri tu veux lister les mp3 dt le nom est contenu ds ta base
et tu veux avoir un truc du style:

lien musique1
lien musique2
...

as tu essayé comme ça ?
<?php 
while($radioshow = mysql_fetch_assoc($exec6)) 
{ 
echo '<a href="mix/'.$radioshow['link2'].'.mp3">Telecharger le fichier</a>';
} 
?> 

Eléphanteau du PHP | 38 Messages

04 sept. 2005, 21:36

Dans ce cas, le lien correspondant me donne www.monurl/mix/.mp3

Il manque le nom du fichier... :roll:

L'exemple ici: http://www.samidee.com/radioshow.php

Je joins mon code au cas ou...
<?php include('connection.inc.php'); ?>
<?php
// Connexion à la base
$conn=mysql_connect($host,$user,$password) or die("Impossible de se connecter au serveur MySQL"); 
$bd=mysql_select_db($bdd,$conn) or die("Impossible de se connecter à la base de données"); 

$idMix = (isset($_GET['idMix']))?$_GET['idMix']:null;
// Requete 1
$req= "SELECT id, num_show FROM radioshow";
$exec = mysql_query($req);

// Requete 2
$req2= "SELECT baseline FROM radioshow WHERE id=".$idMix;
$exec2 = mysql_query($req2);

// Requete 3
$req3= "SELECT part1 FROM radioshow WHERE id=".$idMix;
$exec3 = mysql_query($req3);

// Requete 4
$req4= "SELECT link1 FROM radioshow WHERE id=".$idMix;
$exec4 = mysql_query($req4);

// Requete 5
$req5= "SELECT part2 FROM radioshow WHERE id=".$idMix;
$exec5 = mysql_query($req5);

// Requete 6
$req6= "SELECT part2 FROM radioshow WHERE id=".$idMix;
$exec6 = mysql_query($req6);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sami Dee, le site officiel</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
	color: #FFFFFF;
}
a {
	font-size: 12px;
	color: #FFFFFF;
}
a:visited {
	color: #FCD300;
	text-decoration: none;
}
a:hover {
	color: #FCD300;
	text-decoration: none;
}
a:active {
	color: #FCD300;
	text-decoration: none;
}
a:link {
	text-decoration: none;
}
.Style1 {
	font-size: 11px;
	font-weight: bold;
}
body {
	background-color: #FFFFCC;
}
.Style2 {
	color: #FDD303;
	font-weight: bold;
}
.Style3 {
	color: #FCD300;
	font-weight: bold;
}
-->
</style>
</head>

<body>
<table width="740" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="000000" >
  <tr>
    <td><table width="740" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><table width="740" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="img/hautgauche.jpg" width="330" height="150"></td>
              <td><a href="index.php"><img src="img/hautdroite.jpg" width="410" height="150" border="0"></a></td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td><? include "menu.php" ?></td>
      </tr>
      <tr>
        <td height="420" background="img/background-radioshow.jpg" ><table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="55" colspan="6">&nbsp;</td>
            </tr>
          <tr>
            <td width="26" height="306">&nbsp;</td>
            <td width="391" height="306" align="left" valign="top">
				<table width="100%"  border="0">
                <tr>
                  <td>
	<span class="Style2">
	<?php
	while($radioshow = mysql_fetch_assoc($exec2)) 
    {
	echo $radioshow['baseline'];
	}
	?>
	</span>
	<div align="justify"></div></td>
                </tr>
                <tr>
                  <td height="4"><div align="justify"><br>
                    <br>
                  </div></td>
                </tr>
                <tr>
                  <td>
	<span class="Style2">PART. ONE</span><br>	<?php
	while($radioshow = mysql_fetch_assoc($exec3)) 
    {
	echo $radioshow['part1'];
	}
	?>
	<div align="justify"></div></td>
                </tr>
                <tr>
                  <td><div align="justify"></div></td>
                </tr>
                <tr>
                  <td align="right">
	<?php
	while($radioshow = mysql_fetch_assoc($exec4)) 
    {
	echo $radioshow['link1'];
	}
	?>
	<div align="justify"></div></td>
                </tr>
                <tr>
                  <td>
	<span class="Style3">PART 2.</span><br>	<?php
	while($radioshow = mysql_fetch_assoc($exec5)) 
    {
	echo $radioshow['part2'];
	}
	?>
	<div align="justify"></div></td>
                </tr>
                <tr>
                  <td><div align="justify"></div></td>
                </tr>
                <tr>
                  <td align="right">
	<?php
	while($radioshow = mysql_fetch_assoc($exec6))
	{
	echo '<a href="mix/'.$radioshow['link2'].'.mp3">Telecharger le fichier</a>'; 
	}
	?>
	
	<div align="justify"></div></td>
                </tr>
              </table>			
	
			
        
			  <div align="left"></div></td>
            <td width="84" height="306" valign="top"><div align="center">
			
			<br>
			<br>
			
			<?php
			// Requête 1 et récupération du lien
			while($radioshow = mysql_fetch_assoc($exec))
    { 
			  echo '<a href="'.$_SERVER['PHP_SELF'].'?idMix='.$radioshow['id'].'">'.$radioshow['num_show'].'</a><br/>'; 
} 
			?>
			
			</div></td>
            <td width="39" height="306"></td>
            <td width="178" height="306"><table width="100%" height="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td height="215"></td>
              </tr>
              <tr>
                <td align="center" valign="top"><div align="center"><span class="Style1"><a href="/mix/253-1.mp3" target="_blank"><br>
                  SEPTEMBRE 05<br>
                  AOUT 05 Part.1</a></span><br>
                    <span class="Style1"><a href="/mix/253-2.mp3" target="_blank">AOUT 05 Part 2.</a></span> </div></td>
              </tr>
            </table></td>
            <td height="306"></td>
          </tr>
          <tr>
            <td height="59" colspan="6"></td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td>
        <tr>
              <td><img src="img/footer2-on.jpg" width="740"></td>
        </tr>
            <tr>
              <td><img src="img/footer3.jpg" width="740" height="7"></td>
            </tr>
        </table></td>
  </tr>
</table>    </td>
  </tr>
</table>
<map name="Lien S.MediasMap">
  <area shape="rect" coords="685,3,731,18" href="#">
</map>
</body>
</html>
Modifié en dernier par davidc le 04 sept. 2005, 21:39, modifié 1 fois.

Modérateur PHPfrance
Modérateur PHPfrance | 7636 Messages

04 sept. 2005, 21:38

alors tu dis que comme ca il affiche les liens
<?php
while($radioshow = mysql_fetch_assoc($exec6))
{
echo $radioshow['link2'];
}
?>
et avec le code précédemment donné il n'affiche plus la variable ????? :-k

Eléphanteau du PHP | 38 Messages

04 sept. 2005, 21:41

Exactement.
<?php 
while($radioshow = mysql_fetch_assoc($exec6)) 
{ 
echo $radioshow['link2']; 
} 
?> 
Comme ça, il m'affiche bien le nom du fichier du type '251-1.mp3'

Modérateur PHPfrance
Modérateur PHPfrance | 7636 Messages

04 sept. 2005, 21:44

euh ...comment veut tu affcher "link2" alors que tu ne fait pas un select dessus
$req6= "SELECT part2 FROM radioshow WHERE id=".$idMix;
$exec6 = mysql_query($req6); 
ca ne serai pas plus:
$req6= "SELECT link2 FROM radioshow WHERE id=".$idMix;
$exec6 = mysql_query($req6); 

Eléphanteau du PHP | 38 Messages

04 sept. 2005, 21:47

:oops:

Quand je pense que je me prends la tête pour un truc con, pour lequel d'ailleurs, dans mon esprit, j'ai vérifié 200 fois...

Y'a des fois ou son écran devient un véritable brouillard

Merci énormement, moi je vais me tirer une balle dans le genou...

HD
Mammouth du PHP | 1181 Messages

04 sept. 2005, 21:49

lol non :lol: tu vas juste mettre resolu
"Si Dieu descendait sur la Terre, tous les peuples se mettraient a genoux, excepte les Français qui diraient : " Ah ! Vous êtes la ! C'est pas trop tôt ! On va pouvoir discuter un peu !" [Michel Balfour]