|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
can anybody help me?? i got problem with my looping codes.. please help me..!! i want to show table that represent prize of my contest.
for($thisprize=1; $thisprize<=$RANK; $thisprize++) // $thisprize represents the ranking. { $trial = "SELECT ContestID, Prize FROM Prizes WHERE ContestID=$c_id and Rank=$thisprize"; $query_trial = mysql_query($trial); while($data = mysql_fetch_array($query_trial)) { $hadiahku = $data["Prize"]; } echo " <tr>\n"; echo " <td width=\"10%\" align=\"center\" nowrap>$thisprize</td>\n"; if(!empty($hadiahku)) { echo " <td width=\"30%\" align=\"center\" nowrap>$hadiahku</td>\n"; echo " <td width=\"30%\" align=\"center\"><a href=\"editthisprize.php?c_id=$c_id&RANK=$thisprize\">Edit</a>  "; echo "<a href=\"deletethisprize.php?c_id=$c_id&RANK=$thisprize\" name=\"delete\">Delete</a></td>\n"; } else { echo " <td width=\"30%\" align=\"center\"> </td>\n"; echo " <td width=\"30%\" align=\"center\"><a href=\"fillPrize.php?contestid=$c_id&rank=$thisprize\">Add</a></td>\n"; } } |
|
#2
|
||||
|
||||
|
You didn't say what goes wrong, but I can point out at least one problem you may encounter.
It's in this part: PHP Code:
this way, if the MySQL query returns more than one result, you'll only display the last one, as the while loop won't terminate till the query-result is empty. You con fix this by moving the closing bracket of the while loop to the end of your code, just before the closing bracket of the for loop. That way, every entry will get it's own row in the table. |
|
#3
|
|||
|
|||
|
sorry,because i didn't point my problem.the situation is i had create one table 'Contest' hold the detail of contest.
It's hold ranking available but it's just int.Like a dummy data. So i,create another table 'Prizes' that hold detail of prize of each rank. So in my page it's auto generate one table so I can enter prize detail for each rank. The rank which are generated in my page, i get from the Contest table. So i create the looping codes like above. That page i put some function to edit or delete. But it's go wrong when I delete the prize detail for certain rank. The prize which i delete...eg: I delete prize of rank 3.. then in the row of rank 3, it carried the prize detail of rank 2. I check it in my database..There is no problem.. can u please help me... Itsacon or whoever know how to solve my problem.. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > looping problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|