SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist rhysboy84's Avatar
    Join Date
    May 2007
    Location
    Colwyn Bay, North Wales, UK
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Constantly repeating a section of code....what's going wrong?

    Hi everybody

    Having a bit of problem with php (trying to learn it). The script I'm writing basically repeats 10 rows, or it should, as it repeats row #2 constantly.

    Anyway, here's the code:-

    Code:
    <?php
    $result = mysql_query("SELECT * FROM rsfields");
    $rows = mysql_num_rows($result);
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    <?php echo $rows; ?>
      <table width="100%"  border="0">
        <tr bgcolor="#CCCCCC">
          <td width="20%"><div align="center"><strong>Current Name </strong></div></td>
         
          <td width="20%"><div align="center"><strong>Field Type</strong></div></td>
          <td width="20%"><div align="center"><strong>Default Value </strong></div></td>
          <td width="20%"><div align="center"><strong>Required</strong></div></td>
    	  <td width="20%"><div align="center"><strong>Included On Main Page? </strong></div></td>
    	  <td width="20%">Edit</td>
        </tr>
    <?php 
    
    while ($customfields = mysql_fetch_array($result))
    { 
    $fieldid = $customfields['ID'];
    $fieldtype = $customfields['customtype'];
    $fieldname = $customfields['customname'];
    $fielddefault = $customfields['customdefault'];
    $fieldrequired = $customfields['customrequired'];
    $fieldmainroster = $customfields['custommainroster'];
    ?>
    
        <tr>
          <td>
    	  <?php echo $fieldid; ?>
    	  <?php echo $fieldname; ?></td>
          <td><div align="center">
    	  <? 
    	 	  
    	  if ($fieldtype == "Text") { 
    	  echo 'Text Input';
    	  } 
    	  if ($fieldtype == "Checkbox") { 
    	  echo '
       			True/False
            ';
    	  } 
    	  if ($fieldtype == "Dropdown") { 
    	  echo 'Drop Down Selection';
    	  } 
    	  ?>
    
          </div></td>
          <td><div align="center">
            <? echo $fielddefault; ?>
          </div></td>
         <td><div align="center">
    	   <? $typeoffield = mysql_result($result,$i,4);
    	  if ($typeoffield == "1") { 
    	  echo 'Yes';
    	  }else{
    	  echo 'No';
    	  } ?>
            
          </div></td>
    	  <td><div align="center">
    	     <? 
    	  if ($fieldrequired  == "1") { 
    	  echo 'Yes';
    	  }else{
    	  echo 'No';
    	  } ?>
    	  </div></td>
    	  <td>
    	  <a href="customedit.php?id=<?php echo $fieldid; ?>">Edit</a>
    	  </td>
        </tr>
    <?php } ?>	
      </table>
    
    </body>
    </html>
    It should produce something like this

    Code:
    10
    Current Name	Field Type	Default Value	Required	Included On Main Page?	Edit
    1 Custom 1 	Text Input	Yes	Yes	Edit
    2 Custom 2 	Text Input	Yes	Yes	Edit
    3 Custom 3 	Text Input	Yes	Yes	Edit
    4 Custom 4 	Text Input	Yes	Yes	Edit
    all the way upto 10, but instead it produces this

    Code:
    10
    Current Name	Field Type	Default Value	Required	Included On Main Page?	Edit
    1 Custom 1 	Text Input	Yes	Yes	Edit
    2 Custom 2 	Text Input	Yes	Yes	Edit
    2 Custom 2 	Text Input	Yes	Yes	Edit
    2 Custom 2 	Text Input	Yes	Yes	Edit
    Indefinitely.

    Any suggestions? I can post a link if you're struggling, but I don't want to as I don't want you guys overloading my server with repeat requests. I'm hosted on hostgator
    I'm Rhys Wynne & I blog at Winwar Media
    WP Email Capture: Free Email/Ebook Marketing Wordpress Plugin
    UK Based SEO? Tweet Your Location to #ukseohere!
    | My Brand New Brand | Twitter |

  2. #2
    SitePoint Evangelist rhysboy84's Avatar
    Join Date
    May 2007
    Location
    Colwyn Bay, North Wales, UK
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, fixed it. It had some dodgy mysql_result code in there that I removed.

    People: always make sure you're code is clean before asking the good people of sitepoint! :P
    I'm Rhys Wynne & I blog at Winwar Media
    WP Email Capture: Free Email/Ebook Marketing Wordpress Plugin
    UK Based SEO? Tweet Your Location to #ukseohere!
    | My Brand New Brand | Twitter |


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •