变量没有通过?

I have this code

while($row = mysql_fetch_row($result))
{
echo '<tr>';
$pk = $row[0]['ARTICLE_NO'];

foreach($row as $key => $value)
{
echo '<td><a href="#" onclick="GetAuctionData(\''.$pk.'\')">' . $value . '</a></td>';
}

which gets pk. pk is then passed on to the axjax part with this:

function GetAuctionData(pk)
{
.....
var url="get_auction.php?"
url=url+"cmd=GetAuctionData&pk="+pk;

And finally used in a separate php file with:

$pk = $_GET["pk"];
$sql="SELECT * FROM Auctions WHERE ARTICLE_NO ='$pk'";

the second php file works fine when using it by itself and passing parameters. Likewise there are no errors anywhere. The problem seems to be with passing or generating $pk, as the links in the output file result in $pk being incremednted by 2, eg 4, 6, 8 etc

I can not understand why this is happening.

mysql_fetch_row link does not have subarrays. It will return the first field as 0, next as 1, etc.

Try with

$pk = $row[0];

This can easily be used with your foreach

while($row = mysql_fetch_assoc($result))
$pk = $row['ARTICLE_NO'];

or this gives you both associative and numbered array.

while($row = mysql_fetch_array($result, MYSQL_BOTH))
$pk = $row['ARTICLE_NO'];

EDIT: Based on

$result = mysql_query("SELECT SELLER_ID, ACCESSSTARTS, ARTICLE_NAME FROM {$table}");

You have to include the row you want a value from. ;)

$result = mysql_query("ARTICLE_NO, SELECT SELLER_ID, ACCESSSTARTS, ARTICLE_NAME FROM {$table}");

BTW: Im pretty sure this nested loop will not produce what you want. You'll get 3 links to each article_no. The first with seller_id as text, the second text is accessstarts, and the last link with the same href will have the text article_name.

Maybe something like this?

while($row = mysql_fetch_assoc($result))
{
    $pk = $row['ARTICLE_NO'];
    echo '<td><a href="#" onclick="GetAuctionData(\''.$pk.'\')">' . $row['ARTICLE_NAME'] . '</a></td>';
}

I don't think this does what you expect:

$pk = $row[0]['ARTICLE_NO'];

Try with:

$pk = $row['ARTICLE_NO'];

As troelskn says, it looks like you are a bit confused as to what mysql_fetch_row is returning.

mysql_fetch_row will return $article[0], $article[1] etc

there are also:

mysql_fetch_assoc // return $article['ARTICLE_NO'], $article['otherfield'] etc

mysql_fetch_array // returns an array that is effectively the above two array_merge'd
mysql_fetch_object // returns a stdclass object, as if mysql_fetch_assoc had been passed to get_object_vars()

you need to refactor a bit, in light of this ....

The other responses here should answer your problem sufficiently, but I just wanted to add an extra debugging tip to could help you should you run into a similar problem in the future.

You can do some very basic debugging by merely printing to the screen information about the variables you're working with. (A PHP IDE will often have more powerful debugging features, but for something like this problem, this method will be fine)

Your original code:

while($row = mysql_fetch_row($result))
{
    echo '<tr>';
    $pk = $row[0]['ARTICLE_NO'];

    foreach($row as $key => $value)
    {
        echo '<td><a href="#" onclick="GetAuctionData(\''.$pk.'\')">' . $value . '</a></td>';
    }
}

You notice that the GetAuctionData function isn't getting its variable properly. Add this line:

$pk = $row[0]['ARTICLE_NO'];
var_dump($pk);

If you look at the output when you run the file, you'd probably see it saying that $pk is null. Hmmm, that didn't work. Let's change it a bit:

$pk = $row[0]['ARTICLE_NO'];
var_dump($row);

You'd now see something like this:

array(2) {
  [0]=> string(2) "12"
  [1]=> string(7) "myValue"
}

Aha! Now that you can see exactly what you're working with, you'd see that the code you wanted to use in the first place was:

$pk = $row[0];

var_dump() is your friend. If you're working with arrays, print_r() gives you similar information, but formatted nicely.

Good luck.