Jump to content


Photo

mysql_data_seek()


  • Please log in to reply
4 replies to this topic

#1 stb74

stb74
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts
  • LocationNorthern Ireland

Posted 20 July 2006 - 03:37 PM

Hi

I have a piece of code that runs through a loop to display 15 drop down lists to select teams for matches in a soccerstats program.  But I keep getting this error.

Warning: mysql_data_seek(): Offset 0 is invalid for MySQL result index 10

this is the code

<?php

//
//Query to get the teams from selected divisions.
//
$get_teams = mysql_query("
SELECT teamID AS id,
teamName AS name
FROM test_teams
WHERE teamdivisionID = '$divisionid'
ORDER BY teamName
", $connection)
or die(mysql_error());

//
//Prints 15 forms
//
$i=0;

while($i < 15)
{
//
//Query back to row 0 if not the first time in the loop
//
if($i > 1)
mysql_data_seek($get_teams, 0);

echo'
<tr>
<td align="left" valign="middle">
';

echo"<select name=\"home[$i]\">";

while($data = mysql_fetch_array($get_teams))
{
echo"<option value=\"$data[id]\">$data[name]</option>\n";
}

echo'
</select>
</td>
<td align="left" valign="middle">
';

//
//Back to line 0 in the query
//
mysql_data_seek($get_teams, 0);

echo"<select name=\"away[$i]\">";

while($data = mysql_fetch_array($get_teams))
{
echo"<option value=\"$data[id]\">$data[name]</option>\n";
}

echo"
</select>
</td>
<td align=\"center\" valign=\"middle\"><input type=\"text\" name=\"home_goals[$i]\" size=\"2\"></td>
<td align=\"center\" valign=\"middle\"><input type=\"text\" name=\"away_goals[$i]\" size=\"2\"></td>

</tr>
";




$i++;
}

mysql_free_result($get_teams);

?>
nifootball.co.uk

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 20 July 2006 - 03:40 PM

Your going abou this completely the wrong way. Look into using a LIMIT clause in your query, then simply loop through a while() until all results have been displayed.

#3 stb74

stb74
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts
  • LocationNorthern Ireland

Posted 20 July 2006 - 05:03 PM

Your going abou this completely the wrong way. Look into using a LIMIT clause in your query, then simply loop through a while() until all results have been displayed.


I am a complete novice and I am learning as I go.

This is someone else's code that I am trying to tidy up and improve on, they aren't available to help anymore.  If you can give a couple of pointers as to what you mean I would appreciate it.

Thanks

Scott
nifootball.co.uk

#4 treilad

treilad
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 20 July 2006 - 05:07 PM

http://pear.php.net/...ject.limit.html

#5 stb74

stb74
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts
  • LocationNorthern Ireland

Posted 20 July 2006 - 05:17 PM

Can't access that.
nifootball.co.uk




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users