1

mySQL Table

ID | Name

1 | A

2 | B

3 | C

4 | D

5 | E

mySQL Query

$query = "SELECT * FROM ego_work WHERE 1;
$result = mysql_query($query);

$rows = array();
while ($row = mysql_fetch_array($result)) {
    $rows[] = $row;
}

php Code

<?php foreach ($rows as $work): ?>
     <span> <?php echo $work['id']; ?>, </span>
<?php endforeach; ?>
<br \>
<?php foreach ($rows as $work): ?>
     <span> <?php echo $work['name']; ?>, </span>
<?php endforeach; ?>

RESULT

1,2,3,4,5

E,A,B,C,D

What did I do wrong? I'm trying to get the 2nd result to be A,B,C,D,E

1
  • 1
    Could you post the result of a var_dump on $rows? I suspect your table's data aren't what you think they are. Commented Dec 17, 2011 at 5:00

1 Answer 1

1

can you try below code

<?php foreach ($rows as $work): ?>
<span> <?php echo $work['id']; ?>, </span>
<?php endforeach; ?>

<?php reset($rows);?>
<br \>
<?php foreach ($rows as $work): ?>
 <span> <?php echo $work['name']; ?>, </span>
<?php endforeach; ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.