Re: Mixed Up Values

From: Date: Tue, 26 Apr 2005 05:07:23 +0000
Subject: Re: Mixed Up Values
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-213854@lists.php.net to get a copy of this message
Mark Sargent wrote:
Hi All, with the below code, $myrow[1] should = product_name's value, $myrow[2] should = product_model_number's value and $myrow[3] should = product_serial_number's value, but, product_name's value is not being displayed, and the values are being moved to the left 1. Meaning product_model_number is being displayed as product_name and so forth. What is wrong with the code.? Cheers. Mark Sargent. $result = mysql_query("SELECT product_name, product_model_number,
    23 product_serial_number FROM Products",$db);
    24
    25
    26
    27 echo "<table border=1>\n";
    28
    29
    30
    31 echo "<tr><td>Product Name</td><td>Product Model Number</td><td>Product
    32 Serial Number</td></tr>\n";
    33
    34
    35
    36 while ($myrow = mysql_fetch_row($result)) {
    37
    38
    39
    40         printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",
    41                 $myrow[1], $myrow[2], $myrow[3]);
Change line 41 to $myrow[0], $myrow[1], $myrow[2]);
By default, arrays start from 0 and work their way up, unless you supply index names/values yourself.

« previous php.general (#213854) next »