Welcome Guest, Not a member yet? Register   Sign In
mysql php confusion
#1

[eluser]new_igniter[/eluser]
I am completely baffled by something that seems so simple. If you have a minute, can you look at this below? On the someFunction call below, the data never is there. So I have been having to run the same query twice to get the data for one, and the same data for another. Does mysql_fetch_array() use the data and then throw it away as it goes? I dont understand what I could not just use $result again and again.

Code:
$query = "select * from someTable";
$result = mysql_query($query);
  
while($row = mysql_fetch_array($result))
{
$idRowID = $row['twibsID'];
$idRowResultString .= "$idRowID','";
}

someFunction($result);

function someFunction ($result)
{
while($row = mysql_fetch_array($result))
{
do some stuff...
}
}
#2

[eluser]Dam1an[/eluser]
I think the reason is you increment an internal pointer every time in the first while loop
So when you reach the end of that and pass it into someFunction, its already at the end of the results

Maybe there's a reset pointer function?
#3

[eluser]new_igniter[/eluser]
yeah, the solution is to use:

Code:
mysql_data_seek($result,0);
#4

[eluser]xwero[/eluser]
Why not do
Code:
$query = "select * from someTable";
$result = mysql_query($query);

$rows = array();
  
while($row = mysql_fetch_array($result))
{
$idRowResultString .= $row['twibsID']."','";
$rows[] = $row;
}

mysql_free_result($result);

// do something else with the $rows array




Theme © iAndrew 2016 - Forum software by © MyBB