Page 1 of 1

Display 1-50 in list menu

Posted: Thu May 13, 2010 5:10 am
by Zain_Slasher
[text]Hello there i am a newbie for php coding. [/text]

Code: Select all

<?php 
		
		mysql_connect("localhost", "root", "") or die(mysql_error());
		mysql_select_db("watch") or die(mysql_error());
		
		$id=$_GET['id'];
		
		$result = mysql_query("SELECT * From product Where Prod_ID='$id'")
		or die(mysql_error()); 
		
		 while ($row = mysql_fetch_array ($result)) { 
		 
		 $qty=$row['Prod_Qty'];
		 
		
		
		 
		   echo "<table border=1> <tr> <td style=background-image:url(images/no_image.gif)>     <img src=\"global.php?id=$id\"/></td>
		  				  <td align=left>
		 
						$row[Prod_Name]<br></td>
						 
                <td><select name=QTY>
                <option value=0 selected=selected>Select Qty</option>
                <option value=$qty>$qty</option>
               
              </select>  </td>
						  <td>$row[Prod_Price]</td>
						  <td></td></tr></table>"; 	 
			
		 }
		?>
[text]As you see i have a list menu and i want to display the some numbers for the user to select as quantity . For example if i have 50as the total quantity i need to display 1 to 50 in the list menu with a for loop. Please help me. [/text]

Re: Display 1-50 in list menu

Posted: Thu May 13, 2010 7:42 am
by roders
use a while loop.

Code: Select all

$i=1;
while($i <= $qty)
{   
    echo $i;
    $i++;
}

Re: Display 1-50 in list menu

Posted: Sun May 16, 2010 3:39 am
by Zain_Slasher
Thanks a lot for the code. Sorry for the late response.