By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

problem with printing array values

P: 92
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_desc);
for($x=0; $x<=$desc_array; $x++)
{
?>
self.opener.document.form1.particles[<?=$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.
Feb 14 '08 #1
Share this Question
Share on Google+
6 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Statement 6 should have the $x instead of the x:
[php]$part_desc[$x][/php]
Ronald
Feb 14 '08 #2

P: 92
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.
Feb 14 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
Should "$part_desc[x]"; not be enclosed within quotes? If so, the statement should be:
[php]
self.opener.document.form1.particles[<?=$x?>].value=<?echo "'".$part_desc[$x]."'";?>;
[/php]
Ronald
Feb 14 '08 #4

P: 92
Should "$part_desc[x]"; not be enclosed within quotes? If so, the statement should be:
[php]
self.opener.document.form1.particles[<?=$x?>].value=<?echo "'".$part_desc[$x]."'";?>;
[/php]
Ronald
Still no luck. Didn't work as well. I forgot to mention that the for loop is inside another for loop.
Feb 14 '08 #5

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 14 '08 #6

P: 92
[PHP]<?
include("conn_db.php");
?>
<html>
<head>
<title>Customers</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"><table width="126" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="126" align="center" bgcolor="#FF0000" 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_category, 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_approved, 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_category 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="goCorDeal()" style="width:125px">
<?
while($row = mysql_fetch_array($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_category"];
$serial = $row["serial_no"];
$model = $row["model_no"];
$prepared_by = $row["user"];
$costing_approved = $row["user"];
$tlname = $row["tlname"];
$tfname = $row["tfname"];
$tmname = $row["tmname"];
$technician = $tlname.", ".$tfname." ".$tmname;
$labor = $row["labor"];
$spare_parts = $row["spare_parts"];
$materials = $row["materials"];
$total_charges = $row["total_charges"];
$part_desc = $row["part_desc"];

print "<option value='$so_no`$cust_id`$company`$tin`$contact`$add ress`$city`$province`$areacode`$phone`$areacode2`$ fax`$mobile`$email`$prod_id`$product`$category`$se rial`$model`$labor`$spare_parts`$materials`$total_ charges`$part_desc'>SO №: ".$so_no."</option>\n";
?>
<script type="text/javascript">
function goCorDeal()
{
var names = document.form.customers.options[document.form.customers.selectedIndex].value;
var temp = new Array();
temp = names.split('`');

for(i=0;i<='<?=$so_no?>';i++)
{
self.opener.document.form1.so_no.value = temp[0];
self.opener.document.form1.cust_id.value = temp[1];
self.opener.document.form1.company.value = temp[2];
self.opener.document.form1.tin.value = temp[3];
self.opener.document.form1.contactperson.value = temp[4];
self.opener.document.form1.address.value = temp[5];
self.opener.document.form1.city.value = temp[6];
self.opener.document.form1.province.value = temp[7];
self.opener.document.form1.areacode.value = temp[8];
self.opener.document.form1.phone.value = temp[9];
self.opener.document.form1.areacode2.value = temp[10];
self.opener.document.form1.fax.value = temp[11];
self.opener.document.form1.mobile.value = temp[12];
self.opener.document.form1.email.value = temp[13];
self.opener.document.form1.prod_id.value = temp[14];
self.opener.document.form1.product.value = temp[15];
self.opener.document.form1.category.value = temp[16];
self.opener.document.form1.serial.value = temp[17];
self.opener.document.form1.model.value = temp[18];
self.opener.document.form1.labor.value = temp[19];
self.opener.document.form1.spareparts.value = temp[20];
self.opener.document.form1.materials.value = temp[21];
self.opener.document.form1.total_charges.value = temp[22];
}
<?
$desc_array = count($part_desc);
for($x=0; $x<=$desc_array; $x++)
{?>
self.opener.document.form1.particles[<?=$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.
Feb 14 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.