Jump to content

Archived

This topic is now archived and is closed to further replies.

stb74

mysql_data_seek()

Recommended Posts

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);

?>

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=101262.msg400501#msg400501 date=1153410009]
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.
[/quote]

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

Share this post


Link to post
Share on other sites
http://pear.php.net/manual/en/html/package.database.db-dataobject.db-dataobject.limit.html

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.