Jump to content

[SOLVED] Problem with the while function


isbhenrylu

Recommended Posts

Hi guys,

I've got a problem to do with the while() function. What I'm trying to do is to create a table of 2 columns, one column is user id and the other is user names. This is what I did:

 

<table border="2px">

<tr>

    <th>NameId</th>

        <th>Name</th>

    </tr>

<?php

$c = 1;

define ('NAME1', 'Henry');

define ('NAME2', 'Mary');

define ('NAME3', 'Gary');

define ('NAME4', 'Cherry');

define ('NAME5', 'Berry');

 

 

 

$i = 1;

 

    while ($c <= 5){

echo "<tr><td>" . $c . "</td>";

 

while ($i == $c){

echo "<td>" . NAME . $i . "</td>";

$i++;

}

echo "</td>";

$c++;

}

?>

</table>

 

The user id part works fine, going from 1-5 for the 5 rows. But for the user name column, the result is NAME1, NAME2, NAME3, NAME4, NAME5 instead of Henry, Mary, Gary, Cherry, Berry.

 

Can someone please tell me why

    echo "<td>" . NAME . $i . "</td>";

is interpreted literally as NAME1 instead of finding the constant NAME1 and returning the value "Henry", which was defined in the constant at the start of the script.

 

Really appreciate if someone can show me how to fix this problem as I'm a newbie in programming, thanks!

Link to comment
Share on other sites

Sorry mate, but this still doesn't solve the problem. The results is still:

 

NameId

Name

1

NAME1

2

NAME2

3

NAME3

4

NAME4

5

NAME5

 

instead of what I want it to yield, which is suppose to be:

NameId

Name

1

Henry

2

Mary

3

Gary

4

Cherry

5

Berry

 

Please help! thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.