problem with printing array values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • backups2007
    New Member
    • Jul 2007
    • 92

    problem with printing array values

    I have an array of values that come from a database.

    I used a FOR loop to retrieve each of the values and pass it on to text fields. But the instead of displaying the whole word, only the first letter of the values get displayed and it doesn't even pass the values.

    [PHP]
    <?
    $desc_array = count($part_des c);
    for($x=0; $x<=$desc_array ; $x++)
    {
    ?>
    self.opener.doc ument.form1.par ticles[<?=$x?>].value=<?echo "$part_desc[x]";?>;
    <?}?>
    [/PHP]

    could you in any way improve my code so that it would work? I really need a solution for this. I need to present my program tomorrow afternoon. This is the only problem that some how I couldn't fix. I was actually able to make it work by chance yesterday but I accidentally pressed the shutdown button on my keyboard. It is dangerously beside the enter key.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Statement 6 should have the $x instead of the x:
    [php]$part_desc[$x][/php]
    Ronald

    Comment

    • backups2007
      New Member
      • Jul 2007
      • 92

      #3
      Originally posted by ronverdonk
      Statement 6 should have the $x instead of the x:
      [php]$part_desc[$x][/php]
      Ronald
      Thanks for the reply. But the thing is, it still didn't work.

      For some reason, it just broke apart the array values and displayed the letter of the value where the position is $x.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Should "$part_desc[x]"; not be enclosed within quotes? If so, the statement should be:
        [php]
        self.opener.doc ument.form1.par ticles[<?=$x?>].value=<?echo "'".$part_d esc[$x]."'";?>;
        [/php]
        Ronald

        Comment

        • backups2007
          New Member
          • Jul 2007
          • 92

          #5
          Originally posted by ronverdonk
          Should "$part_desc[x]"; not be enclosed within quotes? If so, the statement should be:
          [php]
          self.opener.doc ument.form1.par ticles[<?=$x?>].value=<?echo "'".$part_d esc[$x]."'";?>;
          [/php]
          Ronald
          Still no luck. Didn't work as well. I forgot to mention that the for loop is inside another for loop.

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Originally posted by backups2007
            Still no luck. Didn't work as well. I forgot to mention that the for loop is inside another for loop.
            Well, the part I showed you works (I tested that).
            Since you mention another loop, maybe it is time to show all code.

            Ronald

            Comment

            • backups2007
              New Member
              • Jul 2007
              • 92

              #7
              [PHP]<?
              include("conn_d b.php");
              ?>
              <html>
              <head>
              <title>Customer s</title>
              <link href="css/format.css" rel="stylesheet " type="text/css">
              </head>

              <body>
              <form name="form">
              <table width="136" border="1">
              <tr>
              <td width="126"><ta ble width="126" border="0" cellpadding="0" cellspacing="0" >
              <tr>
              <td width="126" align="center" bgcolor="#FF000 0" class="header"> Dealers / Corporate</td>
              </tr>
              <tr>
              <td align="center">
              <?
              $code = mysql_query ("SELECT so.so_no, fs.form_status as status, ct.cust_type as customer_type, so.cust_id,
              c.company as customer, c.tin, c.contact, c.address, cy.name as city, p.name as province,
              c.area_code, c.phone_no, c.fax_no, c.mobile_no, c.email, pr.description as product,
              so.serial_no, pc.prod_cat as product_categor y, pr.model_no, pa.part_desc as part_desc, sp.qty, m.description, sm.qty,
              u.username as prepared_by, t.last_name as tlname, t.first_name as tfname, t.middle_name as tmname,
              u.username as costing_approve d, labor, spare_parts, materials, total_charges
              FROM service_order as so
              LEFT JOIN forms_status as fs ON fs.form_status_ id = so.status
              LEFT JOIN customer_type as ct ON ct.cust_type_id = so.cust_type_id
              LEFT JOIN customer as c ON c.cust_id = so.cust_id
              LEFT JOIN city as cy ON cy.city_id = c.city_id
              LEFT JOIN province as p ON p.province_id = c.province_id
              LEFT JOIN product as pr ON pr.prod_id = so.prod_id
              LEFT JOIN product_categor y as pc ON pc.code_cat = pr.code_cat
              INNER JOIN so_parts AS sp ON so.so_no = sp.so_no
              LEFT JOIN parts AS pa ON pa.part_id = sp.part_id
              INNER JOIN so_materials AS sm ON so.so_no = sm.so_no AND sp.parts_so_id = sm.parts_so_id
              LEFT JOIN material AS m ON m.material_id = sm.mat_id
              LEFT JOIN user as u ON u.user_id = so.prepared_by
              LEFT JOIN technician as t ON t.tech_id = so.service_tech
              WHERE so.cust_id != 'NULL' AND ct.cust_type_id = '2'");
              ?>
              <select name="customers " size="10" class="txtreq" onChange="goCor Deal()" style="width:12 5px">
              <?
              while($row = mysql_fetch_arr ay($code))
              {
              $so_no = $row["so_no"];
              $cust_id = $row["cust_id"];
              $company = $row["customer"];
              $tin = $row["tin"];
              $contact = $row["contact"];
              $address = $row["address"];
              $city = $row["city"];
              $province = $row["province"];
              $areacode = $row["area_code"];
              $phone = $row["phone_no"];
              $areacode2 = $areacode;
              $fax = $row["fax_no"];
              $mobile = $row["mobile_no"];
              $email = $row["email"];
              $prod_id = $row["prod_id"];
              $product = $row["product"];
              $category = $row["product_catego ry"];
              $serial = $row["serial_no"];
              $model = $row["model_no"];
              $prepared_by = $row["user"];
              $costing_approv ed = $row["user"];
              $tlname = $row["tlname"];
              $tfname = $row["tfname"];
              $tmname = $row["tmname"];
              $technician = $tlname.", ".$tfname." ".$tmname;
              $labor = $row["labor"];
              $spare_parts = $row["spare_part s"];
              $materials = $row["materials"];
              $total_charges = $row["total_char ges"];
              $part_desc = $row["part_desc"];

              print "<option value='$so_no`$ cust_id`$compan y`$tin`$contact `$address`$city `$province`$are acode`$phone`$a reacode2`$fax`$ mobile`$email`$ prod_id`$produc t`$category`$se rial`$model`$la bor`$spare_part s`$materials`$t otal_charges`$p art_desc'>SO №: ".$so_no."</option>\n";
              ?>
              <script type="text/javascript">
              function goCorDeal()
              {
              var names = document.form.c ustomers.option s[document.form.c ustomers.select edIndex].value;
              var temp = new Array();
              temp = names.split('`' );

              for(i=0;i<='<?= $so_no?>';i++)
              {
              self.opener.doc ument.form1.so_ no.value = temp[0];
              self.opener.doc ument.form1.cus t_id.value = temp[1];
              self.opener.doc ument.form1.com pany.value = temp[2];
              self.opener.doc ument.form1.tin .value = temp[3];
              self.opener.doc ument.form1.con tactperson.valu e = temp[4];
              self.opener.doc ument.form1.add ress.value = temp[5];
              self.opener.doc ument.form1.cit y.value = temp[6];
              self.opener.doc ument.form1.pro vince.value = temp[7];
              self.opener.doc ument.form1.are acode.value = temp[8];
              self.opener.doc ument.form1.pho ne.value = temp[9];
              self.opener.doc ument.form1.are acode2.value = temp[10];
              self.opener.doc ument.form1.fax .value = temp[11];
              self.opener.doc ument.form1.mob ile.value = temp[12];
              self.opener.doc ument.form1.ema il.value = temp[13];
              self.opener.doc ument.form1.pro d_id.value = temp[14];
              self.opener.doc ument.form1.pro duct.value = temp[15];
              self.opener.doc ument.form1.cat egory.value = temp[16];
              self.opener.doc ument.form1.ser ial.value = temp[17];
              self.opener.doc ument.form1.mod el.value = temp[18];
              self.opener.doc ument.form1.lab or.value = temp[19];
              self.opener.doc ument.form1.spa reparts.value = temp[20];
              self.opener.doc ument.form1.mat erials.value = temp[21];
              self.opener.doc ument.form1.tot al_charges.valu e = temp[22];
              }
              <?
              $desc_array = count($part_des c);
              for($x=0; $x<=$desc_array ; $x++)
              {?>
              self.opener.doc ument.form1.par ticles[<?=$x;?>].value=<?echo $part_desc[$x];?>;
              <?
              }?>
              window.close();
              }
              </script>
              <?
              }
              ?>
              </select>
              </td>
              </tr>
              </table>
              </td>
              </tr>
              </table>
              </form>
              </body>
              </html>[/PHP]

              here's the complete code.

              Comment

              Working...