Log in

View Full Version : Problem related to While Loop



koolkedar
04-15-2012, 05:20 AM
Hi all
I am not sure how to do this with php.

I have two queries


$qry = "select * from product where productid='".$dlist."'";

$result=mysql_query($qry);


$subprodqry = "select * from subproducts where productid='".$dlist."'";

$subprod=mysql_query($subprodqry);



i am writting while loop



while($row = mysql_fetch_array($result) and $subprods = mysql_fetch_array($subprod))
{

}


within the while loop there is a point where i have to assign the values from 2nd array $subprods.

But the thing is while doing that i have three different records (product names), which i need to assign to 3 different product images. when i do that i get three different results
how can i do that do have to write another while loop for assigning the values. I am giving the code where i have to write it....


<td align="left" valign="middle" bgcolor="#4E8EB4" >';
echo "&nbsp;Product Name :-- '". $subprods["subPartName"]."'</td>";
echo '
<td rowspan="4" valign="top" bgcolor="#FFFFCC" ><!--DWLayoutEmptyCell-->&nbsp;</td>
<td align="left" valign="middle" bgcolor="#4E8EB4" >';
echo "&nbsp;Product Name :--'". $subprods["subPartName"]."'<!--DWLayoutEmptyCell-->&nbsp;</td>";
echo '
<td rowspan="4" valign="top" bgcolor="#FFFFCC" ><!--DWLayoutEmptyCell-->&nbsp;</td>
<td align="left" valign="middle" bgcolor="#333333" >';
echo "&nbsp;Product Name :-->'". $subprods["subPartName"]."'<!--DWLayoutEmptyCell-->&nbsp;</td>";
echo '
<td >


i want to put the sub product name from the $subprods array ,every image has its name so it will be assigned uniquely....how can i do that....same after the image is displayed and below that is the product code same way while loop and every product has product code which need to be displayed.
Thanks in Advance....
Help need is urgent...for my customer web site..

koolkedar
04-15-2012, 05:39 AM
Hi Just to give information, i have resolved the problem.
I took three loops for three different fields and within the while loop i put another loop and took the records from $subprods into each array and i assigned the array value to product name and product code the code is as below




while($row = mysql_fetch_array($result) )
{
//session_destroy();
while ($subprods = mysql_fetch_array($subprod))
{
$subarray[]=$subprods["subPartName"];
$subpcode[]=$subprods["subPartId"];
$subdesc[]=$subprods["subProdDesc"];
}

}


I took three arrays like above and following code gives idea about how i use that array for assigning the values.


<td align="left" valign="middle" bgcolor="#4E8EB4" >';
echo "&nbsp;Product Name :-- '". $subarray[0]."'</td>";
echo '
<td rowspan="4" valign="top" bgcolor="#FFFFCC" ><!--DWLayoutEmptyCell-->&nbsp;</td>
<td align="left" valign="middle" bgcolor="#4E8EB4" >';
echo "&nbsp;Product Name :--'". $subarray[1]."'<!--DWLayoutEmptyCell-->&nbsp;</td>";
echo '
<td rowspan="4" valign="top" bgcolor="#FFFFCC" ><!--DWLayoutEmptyCell-->&nbsp;</td>
<td align="left" valign="middle" bgcolor="#333333" >';
echo "&nbsp;Product Name :-->'". $subarray[2]."'<!--DWLayoutEmptyCell-->&nbsp;</td>";
echo '
<td >




Hope this info will be help full to someone...

koolkedar
04-15-2012, 05:42 AM
Hi Admin This thread can be closed as the problem is resolved.. Please let me know how to make it solved or i request you to please make it solved and close the thread
Thanking you.

keyboard
04-15-2012, 05:56 AM
If this thread is finished, please set it to resolved.
You can do this by editing the first post within the thread - Pressing go advanced - then where it says no prefix, selecting resolved then save.

That's how you set the thread to resolved. DDadmin (and Moderators?) can close the thread.