8791 sujets

Développement web côté serveur, CMS

Bonjour,

je cherche à masquer une div si un champ est vide dans ma base de données. Je n'arrive pas trouver comment faire.


<?php



mysql_connect('xxx','xxx','xxx') or die("ERROR DATABASE CONNECTION");
mysql_select_db('datatest') or die("DATA SELECTION ERRROR");


$query="select * from bdd where id=1";
$result=mysql_query($query);

	
while($rows=mysql_fetch_array($result)) {		

$rows['b']=$b;
			
?>




<!DOCTYPE html> 
<html> 
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<meta name="viewport" content="width=device-width, initial-scale=1"> 
		<title></title> 
		<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
		<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
		<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>

<script>
function hide()

 if ( !empty($b) ) {
      document.getElementById(cache6h).style.display="none";
}
</script>


	</head> 
	<body> 
		
			
			
		<div data-role="content" data-theme="b">			
			
			
	
			
<!--6h-->			

		<ul data-role="listview" data-inset="true" data-theme="a" data-dividertheme="e" style="background-color:#FFFFFF;">			
			    <li data-role="list-divider" style="margin-bottom:10px;">6h</li>
				
				<div class="ui-grid-a">
		
     		<div class="ui-block-a" style="margin-left:5px; width:62%; margin-right:-5px; height:80px; font-size:14px;"><li>
			
			<div id="cache6h"><? echo $rows['a']; ?><br/></div>
			<? echo $rows['a1'];?><br/>
			<? echo $rows['a2'];?><br/>
			<? echo $rows['a3'];?><br/>
			<? echo $rows['a4'];?><br/>
			<? echo $rows['a5'];?><br/>
			<? echo $rows['a6'];?><br/>
			<? echo $rows['a7'];?><br/>
			<? echo $rows['a8'];?><br/>
			<? echo $rows['a9'];?></li></div>
			
			
			<div class="ui-block-b" style="text-align:center; width:38%;height:80px;font-size:14px;color:#3366CC;"><li>
			
			<div id="cache6h"><? echo $rows['b']; ?><br/></div>
			<? echo $rows['b1']; ?><br/>
			<? echo $rows['b2']; ?><br/>
			<? echo $rows['b3']; ?><br/>
			<? echo $rows['b4']; ?><br/>
			<? echo $rows['b5']; ?><br/>
			<? echo $rows['b6']; ?><br/>
			<? echo $rows['b7']; ?><br/>
			<? echo $rows['b8']; ?><br/>
			<? echo $rows['b9']; ?></li></div>
				
				 </div><!-- /grid-a -->
			 </ul>		

 


Merci pour votre aide.
Modifié par daggoon (31 Mar 2012 - 15:04)
Modérateur
Salut,

Normal, il y a des erreurs de syntaxe. Bizzarre que tu n'aies pas eu des messages erreurs....
Modérateur
une (c'est peu dire) au hasard :


function hide()



 if ( !empty($b) ) {

      document.getElementById(cache6h).style.display="none";

}


apprend d'abord le html/css Smiley cligne
Modifié par niuxe (01 Apr 2012 - 11:45)
Bon j'ai fait quelques modifs. Mais ca marche toujours pas... Smiley confus

<script type="text/javascript">
function () {

if($b == "") {
		document.getElementById('cache6h').style.display='none'; 
	} else {
		document.getElementById('cache6h').style.display='block'; 
	}
}
</script>



<style type="text/css" media="screen">
      #cache6h{
        display:none;
      }
</style>

Modifié par daggoon (01 Apr 2012 - 14:24)
daggoon a écrit :
Bon j'ai fait quelques modifs. Mais ca marche toujours pas... Smiley confus

&lt;script type=&quot;text/javascript&quot;&gt;
function () {

if($b == &quot;&quot;) {
		document.getElementById('cache6h').style.display='none'; 
	} else {
		document.getElementById('cache6h').style.display='block'; 
	}
}
&lt;/script&gt;



&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;
      #cache6h{
        display:none;
      }
&lt;/style&gt;

Modifié par daggoon (01 Apr 2012 - 14:23)
Bonjour,

Je crois que tu fais un gros mélange de plusieurs langages sur ta page. Comme par exemple ta variable "b" en Javascript ne doit pas comporter de $ devant. Si la donnée vient de ta BDD en MySQL, tu la récupères avant en PHP comme tu as fait plus haut et tu peux éventuellement faire un truc de ce genre :


function hide(){
var b = "<?= $b; ?>";

if(b == ''){
.......


Pourrais tu expliquer ce que tu cherches à faire exactement ? Sinon oui essaie de voir comment interpréter les différents langages entre eux, de nombreux tutoriels sont disponibles pour ça Smiley cligne
Modifié par meteo59223 (01 Apr 2012 - 14:48)
En gros, ca donne ça:
Si le champ F est vide dans la bdd, les champs F et A sont cachés....etc


<? echo "<table width=100% style='font-size:14px;'>";
		if ($rows['f']!=="") { echo "<tr><td width=50%>".$rows['a']."</td>"; echo "<td width=50%   style='color:#3366CC;'>".$rows['f']."</td></tr>"; }
		if ($rows['f1']!=="") { echo "<tr><td width=50%>".$rows['a1']."</td>"; echo "<td width=50% style='color:#3366CC;'>".$rows['f1']."</td></tr>"; }
		if ($rows['f2']!=="") { echo "<tr><td width=50%>".$rows['a2']."</td>"; echo "<td width=50% style='color:#3366CC;'>".$rows['f2']."</td></tr>"; }
		if ($rows['f3']!=="") { echo "<tr><td width=50%>".$rows['a3']."</td>"; echo "<td width=50% style='color:#3366CC;'>".$rows['f3']."</td></tr>"; }
		if ($rows['f4']!=="") { echo "<tr><td width=50%>".$rows['a4']."</td>"; echo "<td width=50% style='color:#3366CC;'>".$rows['f4']."</td></tr>"; }
		if ($rows['f5']!=="") { echo "<tr><td width=50%>".$rows['a5']."</td>"; echo "<td width=50% style='color:#3366CC;'>".$rows['f5']."</td></tr>"; }
		if ($rows['f6']!=="") { echo "<tr><td width=50%>".$rows['a6']."</td>"; echo "<td width=50% style='color:#3366CC;'>".$rows['f6']."</td></tr>"; }
		if ($rows['f7']!=="") { echo "<tr><td width=50%>".$rows['a7']."</td>"; echo "<td width=50% style='color:#3366CC;'>".$rows['f7']."</td></tr>"; }
		if ($rows['f8']!=="") { echo "<tr><td width=50%>".$rows['a8']."</td>"; echo "<td width=50% style='color:#3366CC;'>".$rows['f8']."</td></tr>"; }
		if ($rows['f9']!=="") { echo "<tr><td width=50%>".$rows['a9']."</td>"; echo "<td width=50% style='color:#3366CC;'>".$rows['f9']."</td></tr>"; }
        echo "</table>";		?>]

Modifié par daggoon (03 Apr 2012 - 21:43)