problema mysql_data_seek

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
Salve, ho un problema con mysql_data_seek in un esempio che ho trovato su internet,

mi dite come posso risolvere questo Warning?

<b>Warning</b>: mysql_data_seek() [<a href='function.mysql-data-seek'>function.mysql-data-seek</a>]: Offset 3 is invalid for MySQL result index 5 (or the query data is unbuffered) in <b>D:\xampp\htdocs\directory\submitlink.php</b> on line <b>121</b><br />

e il suo codice che viene richiamato e cosi:
traverse(0,0,$selcat2);

codice:
PHP:
<?php
function traverse($root, $depth, $sql) 
{ 
     $row=0; 
     while ($acat = mysql_fetch_array($sql)) 
     { 
          if ($acat['CatParent'] == $root) 
          { 
               print "<option value='" . $acat['CatID'] . "'>"; 
               $j=0; 
               while ($j<$depth) 
               {     
                     print "&nbsp;&nbsp;";
                    $j++; 
               } 
               if($depth>0)
               {
                 print "-";
               }
               print $acat['CatName'] . "</option>"; 
               mysql_data_seek($sql,0); 
               traverse($acat['CatID'], $depth+1,$sql); 
                
          } 
          $row++; 
          mysql_data_seek($sql,$row); 
           
     } 
}

da errore qui : mysql_data_seek($sql,$row);

grazie mille.
 
cito dal manuale ufficile:
row_number starts at 0. The row_number should be a value in the range from 0 to mysql_num_rows() - 1. However if the result set is empty (mysql_num_rows() == 0), a seek to 0 will fail with a E_WARNING and mysql_data_seek() will return FALSE.
 

ciao, ho visto ma non risolvo nulla anche mettendo i controlli del manuale come dice ma mi da sempre i avvisi..

ti posto tutto il codice:
PHP:
<?php
include "connect.php";

session_start();
if(isset( $_SESSION['diradmin']))
{
  print "<table border='0' cellspacing='20'>";
  print "<tr><td valign='top'>";
  include "adminleft.php";
  print "</td>";
  print "<td valign='top'>";
  print "<table border='1' bordercolor='red'>";
  print "<tr><td bgcolor='red'><center><font color='white'>Add Link</font></center></td></tr>";
  print "<tr><td>";
  if(isset($_POST['submit']))
  {
    if(!$_POST['entry'])
    {
      print "You did not enter a Title";
    }
    else if(!$_POST['url']) 
    {
      print "You did not enter a URL";
    }
    else if (!$_POST['category'])
    {
      print "Please select a category";
    }
    else if(!$_POST['desc'])
    {
      print "Please input a description";
    }
    else //all required fields have been validated
    {
      if(!$_POST['rank'])
      {
        $rank=0;
      }
      else 
      {
        $rank=$_POST['rank'];
      }
      $entry=$_POST['entry'];
      $url=$_POST['url'];
      $category=$_POST['category'];
      $desc=$_POST['desc'];
      $insertentry="INSERT into cl_entries(EntryName, CatID,URL,Description,importance,validated) values('$entry','$category','$url','$desc','$rank','1')";
      mysql_query($insertentry) or die("Could not insert entry");
      print "Link Added Successfully";        

  }
 }
  else
  {
    print "<form action='addlink.php' method='post'>";
    print "Title of site:<br>";
    print "<input type='text' name='entry' size='20'><br>";
    print "URL(include http://)<br>";
    print "<input type='text' name='url' size='20'><br>";
    print "Category:<br>";
    $selcat="SELECT * from cl_categories order by CatName ASC";
    $selcat2=mysql_query($selcat) or die("Could not select category"); 
    print "<Select name='category'>";  
    
   traverse(0,0,$selcat2);
   
   

    print "</select>";  
    print "Importance(Zero is default, anything above zero is a sponsered listing)<br>";
    print "<input type='text' name='rank' size='5' value='0'><br>";
    print "Description:<br>";
    print "<textarea name='desc' rows='5' cols='40'></textarea><br>";
    print "<input type='submit' name='submit' value='submit'></form>";
  
  }
  print "</td></tr></table>";
  print "</td></tr></table>";
}
else
{
  print "Not logged in";
}

?>
<?php

function traverse($root, $depth, $sql) 
{ 
     $row=0; 
     while ($acat = mysql_fetch_assoc($sql)) 
     { 
          if ($acat['CatParent'] == $root) 
          { 
               print "<option value='" . $acat['CatID'] . "'>"; 
               $j=0; 
               while ($j<$depth) 
               {     
                     print "&nbsp;&nbsp;";
                    $j++; 
               } 
               if($depth>0)
               {
                 print "-";
               }
               print $acat['CatName'] . "</option>"; 
               mysql_data_seek($sql,0); 
               traverse($acat['CatID'], $depth+1,$sql); 
                
          } 
             $row++; 
		
		mysql_data_seek($sql,$row);   // QUESTA DA ERRORE.

  } 
} 
?>

Mi aiuti... poi dopo lo trovo convertire in Mysqli.

grazie mille.
 
Vedo

PHP:
mysql_data_seek($sql,$row)

se stampi a video il valore di $row cosa ti restituisce? Inserisci un controllo con mysql_error.
 
Scambia queste righe:
PHP:
             $row++;  
         
        mysql_data_seek($sql,$row);   // QUESTA DA ERRORE.
In questo modo:
PHP:
mysql_data_seek($sql, $row);
$row++;

nulla solito avviso .. e poi c'è una cosa che viene solamente scritto nel sorgente html invece a video non viene visualizzato ma solo quando io faccio "mostra sorgente pagina"...

boh!

non ci sto capendo più nulla.
comunque lo script è questo:
http://www.chipmunk-scripts.com/page.php?ID=15

grazie mille.
 
hai stampato a video il valore della variabile? Hai inserito il controllo con mysql_error()?
 

Discussioni simili