Jump to content

Recommended Posts

In the fieldset (but not restricted to) the code is different than before it was put through foreach, also it is outputting six items when the array only has 4. What am I doing incorrect?

 

<?php
$result = mysql_query("SELECT * FROM module WHERE page_id='".$currentpage." ORDER BY order ASC'") or die(mysql_error());

$dbarray = mysql_fetch_array($result);
echo $dbarray['title'];

foreach ($dbarray as $array){
if ($array['fieldset'] == 1) {
	echo "<fieldset><legend>".$array['title']."</legend>";
	echo "content";
	echo "</fieldset>";
}
}
?>

 

results in this HTML (reformatted so it's easier to read(previously on one line))

 

Address
<fieldset>
<legend>
	1
</legend>
content
</fieldset>
<fieldset>
<legend>
	1
</legend>
content
</fieldset>
<fieldset>
<legend>
	1
</legend>
content
</fieldset>
<fieldset>
<legend>
	1
</legend>
content
</fieldset>
<fieldset>
<legend>
	1
</legend>
content
</fieldset>
<fieldset>
<legend>
	1
</legend>
content
</fieldset>

 

nonreformatted

 

Address<fieldset><legend>1</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset>

 

if I comment out the less necessary code (like this)

 

<?php
$result = mysql_query("SELECT * FROM module WHERE page_id='".$currentpage." ORDER BY order ASC'") or die(mysql_error());

$dbarray = mysql_fetch_array($result);
echo $dbarray['title'];

foreach ($dbarray as $array){
//if ($array['fieldset'] == 1) {
	echo "<fieldset><legend>".$array['title']."</legend>";
	echo "content";
	echo "</fieldset>";
//}
}
?>

 

i get

 

Address<fieldset><legend>5</legend>content</fieldset><fieldset><legend>5</legend>content</fieldset><fieldset><legend>3</legend>content</fieldset><fieldset><legend>3</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset><fieldset><legend>A</legend>content</fieldset><fieldset><legend>A</legend>content</fieldset><fieldset><legend>0</legend>content</fieldset><fieldset><legend>0</legend>content</fieldset><fieldset><legend>0</legend>content</fieldset><fieldset><legend>0</legend>content</fieldset><fieldset><legend>3</legend>content</fieldset><fieldset><legend>3</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset><fieldset><legend>1</legend>content</fieldset>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.