Looping Database

goodday everyone;

i’ve some problem to show data from my database, it used to create form with dynamic input name (same on database settings)

  1. Database Structure

idDiyTemplate,set1, set2, set3, etc…

  1. Problem = show looping w/ syntax while (on bold),

<?

$sql=“SELECT * FROM diyTemplate WHERE idDiyTemplate=‘1’”;

$post=DiyTemplate::model()->findBySql($sql);

$setting=$post->jmlSetting;

$set=1;

[indent]

while ($setting >= ‘1’){

?>

[indent]

<tr>

<td width="100"><? echo $post->set[$set]; ?></td>

<td>

<input name="<? echo $post->set1; ?>" size="30" type="text" />

</td>

</tr>

[/indent]

&lt;? 


echo &#036;setting.&quot;-&quot;;


&#036;set++;


&#036;setting--;


} 


?&gt;

[/indent]

how can i fix this?

thanks so much to advices;

check


while ($setting >= '1'){

you cannot assign string to compare >= it should be while ($setting >= 1)

Hi Absar A Hasan,

thanks for advice,

but it’s still work to compare it, :)

PROBLEM SOLVED

it can not be used variable on it = $post->set[$set]

i used $set=set1; and adding value 1 ($set++;) on loop, and it works,




	<?

	$sql="SELECT * FROM diyTemplate WHERE idDiyTemplate='1'";

	$post=DiyTemplate::model()->findBySql($sql);

	$setting=$post->jmlSetting;

	$set=set1;

	

	while ($setting >= 1){

	?>

		<tr>

			<td width="100"><? echo $post->$set; ?></td>

			<td>

				<input name="<? echo $post->$set; ?>" size="30" type="text" />

			</td>

		</tr>

	<? 

	echo $setting."-";

	$set++;

	$setting--;

	} 



The results are = set1, set2, set3, …

Thanks Yii ,

and special to Absar A Hasan, thanks dude :)

why don’t you just use a simple


foreach