Mysql_fetch_row() expects parameter 1 to be resource, null given in

Virginie -  
jordane45 Messages postés 30426 Date d'inscription   Statut Modérateur Dernière intervention   -
Bonjour,

Ca fait quelques années que je bidouille sur un vieux logiciel qui gère une base de données de pedigrees de chiens, je n'ai pas de connaissances approfondies du domaine.
Je suis en train de copier le logiciel sur un autre hébergeur, or je rencontre des soucis que je n'ai pas sur l'hébergeur d'origine.
Les 2 sont sous php 5.4, pour la version SQL, je ne sais pas où trouver cela :/

J'ai ce message d'erreur sur une page, alors que mon résultat de recherche s'y affiche correctement :
Warning: mysql_fetch_row() expects parameter 1 to be resource, null given in [...]newest.php on line 177

<?php

echo "<table>\n";

while ($pline = mysql_fetch_row($presult)) {

echo "\t<tr><td style='padding-left:40px'><a href='managePerson.php?personId=$pline[0]'>$pline[1] $pline[2]</a></td>\n";

echo "\t\t<td><label>($pline[3])</label></td>\n";

echo "\t</tr>\n";

}

echo "</table>\n";

?>

Je ne comprends pas ce qui ne va pas, quelqu'un pour m'aider?
Merci beaucoup ;)

Configuration: Linux / Firefox 94.0

2 réponses

  1. jordane45 Messages postés 30426 Date d'inscription   Statut Modérateur Dernière intervention   4 830
     
    Bonjour
    Cela veut dire que ta variable $presult est null...
    Donc faut voir comment tu l'initiliases... Et à mon avis, ta requête sql doit retourner une erreur..
    0
  2. Virginie
     
    Et pourquoi je n'ai pas ce message d'erreur avec l'autre hébergeur alors que le logiciel est identique?
    0
    1. jordane45 Messages postés 30426 Date d'inscription   Statut Modérateur Dernière intervention   4 830
       
      Ben... as tu bien recopié les tables à l'identique ?
      As tu bien paramétré la connexion à la bdd ?

      Quoi qu'il en soit, si tu veux qu'on t'aide à trouver l'erreur... il faudrait nous montrer le code COMPLET.


      A noter que l'extension mysql_* est obsolète.
      Dans l'idéal il faudrait passer à mysqli_* ( ne serait qu'au cas où un jour tu passes à une version php supérieure .. )
      0
      1. jordane45 Messages postés 30426 Date d'inscription   Statut Modérateur Dernière intervention   4 830 > jordane45 Messages postés 30426 Date d'inscription   Statut Modérateur Dernière intervention  
         
        ps: Pour poster du code sur le forum, tu devras utiliser les BALISES DE CODE.
        Explications ( à lire entièrement !!) disponibles ici : https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
        0
      2. Virginie.88 Messages postés 3 Statut Membre > jordane45 Messages postés 30426 Date d'inscription   Statut Modérateur Dernière intervention  
         
        Bonjour Jordane,

        Désolée pour la réponse tardive.

        La bdd fonctionne bien, elle répond à mes recherche et enregistre mes mises à jours.

        Le site est hébergé initialement chez OVH, et celui que je mets en place pour une autre race est sur Wedos. J'ai a priori paramétré les 2 hébergeurs de la même façon (php 5.4).

        Voici la page où s'affiche le message d'erreur, on voit bien qu'à part ce message, les infos que je demande sont présentes :


        Et voici le code de la page en question :
        (peut être faut-il que je trouve d'où provient la variable $presult?)
        <?php
        
        	include 'header.php';
        	include 'db/db_connect.php';
        
        // time interval (86400 seconds = 1 day)
        //$interval = 86400;
        // time interval (3600 seconds = 1 hour)
        $interval = 3600;
        $timeframe = $_POST['timeframe'];
        if (!$timeframe) 
        	$timeframe=2;
        $timeframeInMs = date("YmdHis", time() - $timeframe*$interval);
        
        // Query
        
        $query = "(SELECT id,
        
                         date_format(changed, '%Y-%m-%d %H:%i:%s') as changed
        
                  FROM   dog
        
                  WHERE  changed > $timeframeInMs)
        
        					UNION 
        
        					(SELECT dog_id, date_format(changed, '%Y-%m-%d %H:%i:%s') as changed
        
        					 FROM photos_dog
        
        					 WHERE changed > $timeframeInMs)
        
        					UNION 
        
        					(SELECT dog_id, date_format(changed, '%Y-%m-%d %H:%i:%s') as changed
        
        					 FROM breeders_dogs
        
        					 WHERE changed > $timeframeInMs)
        
        					UNION 
        
        					(SELECT dog_id, date_format(changed, '%Y-%m-%d %H:%i:%s') as changed
        
        					 FROM owners_dogs
        
        					 WHERE changed > $timeframeInMs)					 					 
        
        					ORDER BY changed DESC";
        
        $result = mysql_query($query) or die('Query failed: ' . mysql_error());
        
        ?>
        
        
        <div class="main">
        	<div class="content" >
        		<div style="float:left">
        			<h3>Newest Dog Updates </h3>
        		</div>
        		<div style="float:left;padding-left:30px;padding-top:18px">
        			<form action="newest.php" method="post">
        			<label>Current timeframe: </label> 
        			<select name="timeframe" onChange="javascript:submit();">
        				
        				<option value="24" <?php if($timeframe == "24") echo "selected='selected'"; ?>>the last 24 hours</option>			
        				<option value="72" <?php if($timeframe == "72") echo "selected='selected'"; ?>>the last 3 days</option>
        				<option value="168" <?php if($timeframe == "168") echo "selected='selected'"; ?>>the last week</option>
        				<option value="336" <?php if($timeframe == "336") echo "selected='selected'"; ?>>the last 2 week</option>
        			</select>
        			</form>
        		</div>
        		<div style="text-align:right;float:right">				
        			<img src="images/TWA_logo_square_colored_18px_green.gif"> <label>Most important data available</label><br>
        			<img src="images/TWA_logo_square_colored_18px.gif"> <label>Important data is missing </label>
        
        	  	</div>
        
        		<div style="clear:both">
        		<table width="95%"><tr><td valign="top">
        		<?php 
        
        			echo "<table id='newest'>\n";
        
        			$dogs = array();
        
        			while ($line = mysql_fetch_row($result)) {
        
        				$dogid = $line[0];
        
        				$timestamp = $line[1];
        
        				if ($dogs[$dogid]<$timestamp)
        
        					$dogs[$dogid]=$timestamp;
        
        			}
        
        			foreach ($dogs as $key => $value) {
        
        				$dquery = "SELECT name,creator,last_modifier,sire_id,dam_id,sex,yearofbirth,yearofdeath,color
        
        						FROM dog
        
        						WHERE id = $key";
        
        				$dresult = mysql_query($dquery) or die('Query failed: ' . mysql_error());
        
        				$dline = mysql_fetch_array($dresult);
        				
        				//
        				if (($dline['yearofdeath'] == null)) {
        				if (($dline['sire_id'] == null) || ($dline['dam_id'] == null) || ($dline['sex'] == null) || ($dline['yearofbirth'] == null) || ($dline['color'] == null)) {
        					$imgIcon = 'images/TWA_logo_square_colored_21px.gif';
        					$tooltipText = 'Important info missing';
        				} else {
        					$imgIcon = 'images/TWA_logo_square_colored_21px_green.gif'; 
        					$tooltipText = 'Most important info available';
        				} 
        				} else {
        						$imgIcon = 'images/TWA_logo_square_noir_21px.gif';
        						$tooltipText = 'This dog is dead';
        				}
        				?>			
        				<tr><td><img src='<? echo $imgIcon ?>' onmouseover="Tip('<? echo $tooltipText ?>', WIDTH, 170, BGCOLOR, '#CADCEB', BORDERCOLOR, '#115098',
        							FONTCOLOR,'#354A6A',FONTFACE,'verdana,geneva,sans-serif',FONTSIZE,'10px', SHADOW, true, 
        							SHADOWCOLOR,'#115098', SHADOWWIDTH,3,PADDING,2)"/>				
        				<?
        				echo "<a href='details.php?id=$key'>$dline[name]</a></td>\n";
        				echo "\t\t<td><label>($value)</label></td>\n";
        				
        				if ($_CURRENT_USER->can_see_user_actions()) {
        					$creatorQuery = "SELECT username,userid FROM users WHERE userId = '$dline[creator]'";
        					$creatorResult = mysql_query($creatorQuery) or die('Query failed: ' . mysql_error());
        					$creatorLine = mysql_fetch_row($creatorResult);
        					$modifierQuery = "SELECT username,userid FROM users WHERE userId = '$dline[last_modifier]'";
        					$modifierResult = mysql_query($modifierQuery) or die('Query failed: ' . mysql_error());
        					$modifierLine = mysql_fetch_row($modifierResult);	
        					//echo "\t\t<td><label> created by: <a href='php_users/htdocs/profile.php?id=".$creatorLine[1]."'><b>$creatorLine[0]</b></a>, last modified by: <a href='php_users/htdocs/profile.php?id=".$modifierLine[1]."'><b>$modifierLine[0]</b></a></label></td>\n";
        				}
        				
        				$q="SELECT photo_id FROM photos_dog WHERE dog_id=$key";
        				$r = mysql_query($q) or die('Query failed: ' . mysql_error());
        				if ($l = mysql_fetch_object($r)) {		
        					if ($l != null)
        						?>
        						<td><img src='images/camera.png' style="opacity: .8;filter: alpha(opacity=80);" 
        						onmouseover="this.T_WIDTH=95;this.T_BGCOLOR='#e7e7e7';
        						this.T_BORDERCOLOR='#cc9966';this.T_FONTCOLOR='#333333';
        						this.T_FONTFACE='verdana,geneva,sans-serif';this.T_FONTSIZE='10px';
        						this.T_SHADOWCOLOR='#cc9966';this.T_SHADOWWIDTH=3;this.T_PADDING=2;
        						return escape('photo available')"/></td>
        						<?php
        				}
           			echo "\t</tr>\n";
        
        			}
        
        			echo "</table>\n";			
        
        		?>
        		<p> </p>
        		
        		<div style="clear:both">
        		<?php 
        
        			echo "<table>\n";
        
        			while ($pline = mysql_fetch_row($presult)) {
        
        				echo "\t<tr><td style='padding-left:40px'><a href='managePerson.php?personId=$pline[0]'>$pline[1] $pline[2]</a></td>\n";
        
        				echo "\t\t<td><label>($pline[3])</label></td>\n";					
        
        	   			echo "\t</tr>\n";
        
        			}
        
        			echo "</table>\n";			
        
        		?>
        		</div>
        
        		</td>
        		<td valign="top" align="right" style="width:130px;padding-left:30px;padding-top:20px; padding-bottom:200px">
        			<?php /*
        			<script type="text/javascript"><!--
        				google_ad_client = "pub-1096996726337786";
        				google_ad_width = 120;
        				google_ad_height = 600;
        				google_ad_format = "120x600_as";
        				google_ad_type = "text_image";
        				google_ad_channel = "";
        				google_color_border = "FFFFFF";
        				google_color_bg = "eeeeee";
        				google_color_link = "CC9966";
        				google_color_text = "333333";
        				google_color_url = "CC9966";
        			//--></script>
        			<script type="text/javascript"
        		  		src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
        			</script> */ ?>		
        		</td>
        		</tr></table>
        		</div>
        
        	</div>
        </div>
        
        <?php 
        	include 'footer.php';
        ?>
        
        0
      3. jordane45 Messages postés 30426 Date d'inscription   Statut Modérateur Dernière intervention   4 830 > Virginie.88 Messages postés 3 Statut Membre
         
        peut être faut-il que je trouve d'où provient la variable $presult?

        oui
        0