Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping too many times

Status
Not open for further replies.

camcim

Programmer
Jan 25, 2003
20
0
0
US
Hi all,
I can't seem to get this loop working properly.
Here is the script:


Code:
<?
$sql = &quot;SELECT * FROM company_categories WHERE company_id='$id'&quot;;
    $result = mysql_query($sql);
    $total = mysql_num_rows($result);
    while($row = mysql_fetch_array($result)){
    $comp_cat_id = $row[&quot;comp_cat_id&quot;];
    $company_id = $row[&quot;company_id&quot;];
    $category_id = $row[&quot;category_id&quot;];

$num = 1;
while ($num <= $total){

?>
                          <tr>
                          <td>
                              <input name=&quot;comp_cat_id<? echo $num ?>&quot; type=&quot;hidden&quot; value=&quot;<? echo $comp_cat_id ?>&quot;>
                              <input name=&quot;company_id<? echo $num ?>&quot; type=&quot;hidden&quot; value=&quot;<? echo $company_id ?>&quot;>
                              <input name=&quot;category_id<? echo $num ?>&quot; type=&quot;text&quot; size=&quot;16&quot; maxlength=&quot;16&quot; value=&quot;<? echo $category_id ?>&quot;>
                           </td>
                        </tr>
<?
$num++;
}
}
?>


It almost works except that the text input field and there values display 4 times (therefore if $total equaled 4 the results overall display 16 times over)
Any ideas how to get it to display the $total amount of times with the corresponding $category_id associated to it?

Cheers,
camcim
 
Remove the inner [tt]while[/tt] loop. (The [tt]
while ($num <= $total){[/tt] one). //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top