Pregunta

Using the following php code:

$queryfor = "SELECT * FROM entrydata WHERE data_email = '{$email}'";
$resultfor = mysqli_query($connection, $queryfor);
if (!$resultfor){die("Database Failed1!");} 

$rowfor = mysqli_fetch_assoc($resultfor);

If I use $rowfor["other_column"] I receive the data from another column which had the given {$email} in its data_email column.

** My problem is I have multiple rows with the same email address in their data_email column. How do I access the "other_column" for the second and third match to my {$email} query. **

I've tried using mysqli_fetch_array and combinations of $rowfor[x][y] with no luck.

¿Fue útil?

Solución

mysqli_fetch_array() returns an array for one record at a time so try iterating using while loop like:

while($rowfor = mysqli_fetch_array($resultfor))
{
       echo $rowfor["yourColumnName"]."<br />";
}

mysqli_fetch_array() will return false when there are no more rows in your resultSet.

Otros consejos

you can use

while($rowfor = mysqli_fetch_assoc($resultfor))
{
    if($rowfor["other_column"] == ...)
    {
        ...
    }
}

to access all columns of you query result

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top