Reusing a Data query result set
Posted: Mon Jul 26, 2010 12:59 am
Hi all,
I'm relatively a novice to php(I've worked mainly in ASP.NET in the past) and therefore using the mysql and/or mysqli libraries. I have a result set that is very small and I'm using it to populate a html select list like so:
As you can see I'm making a list of clients. This is for a work order/time entry system. The problem is that I would like to reuse the result set and make a second list of clients for another data field namely billable clients.
If I understand $result->fetch_array() correctly the result set is iterated through or else consumed like stack's pop(). I'd either like to reset the result set so I can start back at the beginning or else make a copy of it so I can pull data out of the copy. I'd prefer to not run the query twice if I don't have to.
Thanks,
-Jordan
I'm relatively a novice to php(I've worked mainly in ASP.NET in the past) and therefore using the mysql and/or mysqli libraries. I have a result set that is very small and I'm using it to populate a html select list like so:
Code: Select all
<?php
$conn = mysqli_connect(.....);
$sql = "select id, name
from client
order by name";
$result = $conn->query($sql) or die("Database Error: " . mysqli_error($conn));
?>
.
.
.
<select name="client" id="client">
<?php
while($row = $result->fetch_array())
{
echo"<option value =".$row['id'].">".$row['name']."</option>";
}
?>
</select>
If I understand $result->fetch_array() correctly the result set is iterated through or else consumed like stack's pop(). I'd either like to reset the result set so I can start back at the beginning or else make a copy of it so I can pull data out of the copy. I'd prefer to not run the query twice if I don't have to.
Thanks,
-Jordan