0

So here is what I did so far: http://d.pr/i/c6z

Code:

<tbody>
<?php while ($row = mysql_fetch_assoc($result)): ?>
    <tr>
        <td><?php echo $row['id']; ?></td>
        <?php foreach ($row as $key): ?>
        <td><a href="#"><?php echo $key; ?></a></td>
        <?php endforeach; ?>
    </tr>
<?php endwhile; ?>
</tbody>

and my mysql table looks like that: id (PRIMARY KEY), fullname, username. As you can see, what i'm trying to do is to display all of these records in html table, but what I don't want is href link in first column, just a numbers. SSo, how to remove in foreach loop the first value from the array which is 'id' or maybe there is a better way to do this thing?

1
  • If you don't want to display a link in the first column, why have you wrapped it in an <a> tag? Commented Jul 2, 2013 at 13:23

3 Answers 3

1

try this :

<tbody>
<?php while ($row = mysql_fetch_assoc($result)): ?>
    <tr>
        <?php foreach ($row as $key): ?>
            <?php if($key === 'id'): ?>
               <td><?php echo $row['id']; ?></td>
            <?php else: ?>
               <td><a href="#"><?php echo $key; ?></a></td>
            <?php endif; ?>
        <?php endforeach; ?>
    </tr>
<?php endwhile; ?>
</tbody>

Two different views so you have two conditions. It is easier to read for a view.

Sign up to request clarification or add additional context in comments.

Comments

1
<tbody>
<?php while ($row = mysql_fetch_assoc($result)): ?>
    <tr>
        <td><?php echo $row['id']; unset($row['id']); ?></td>
        <?php foreach ($row as $key): ?>
        <td><a href="#"><?php echo $key; ?></a></td>
        <?php endforeach; ?>
    </tr>
<?php endwhile; ?>
</tbody>

Comments

1

Without commenting on the efficiency or otherwise of your code, you can always use unset to unset a specific element of your array, for example,

unset($row['id']);

will unset the element of $row array with key id - effectively removing that element from the array.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.