SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why i get the same record ?

    I wish to output the record in a table form, following is my code

    PHP Code:
        $result mysql_query('SELECT dive_id,dive_diverid FROM divefile'); 
        
    $info mysql_fetch_assoc($result);
        if (
    $result && mysql_num_rows($result)) {
          
    $numrows mysql_num_rows($result);
          
    $rowcount 1;
          print 
    "There are $numrows records here!<br /><br />";
          while(
    $row mysql_fetch_assoc($result)) {
             
    $diverid $info['dive_id'];
            
    $divername $info['dive_diverid'];
            
    $Dive_list_fields .=<<<__HTML_END
    <table width="500" border="1" cellspacing="1" cellpadding="1"> 
    <tr>
    <td>
    Dive id : 
    $diverid   
    </td>
    <td>
    Dive name : 
    $divername 
    </td>
    </tr>
    __HTML_END;
    }

    it contains four record, but only return three record, this is probably i call the mysql_fetch_assoc() to $info, but if i did not assign to $info, how should i get each data from the field ? at the same time, all three record display is the first record , I have little confuse now, please help me.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Eliminate the line with $info = mysql_fetch_assoc...
    Inside the while-loop, substitute $info[..] with $row[..]

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You just fetch rows two times just comment the first fetch line:
    Code php:
    	$result = mysql_query('SELECT dive_id,dive_diverid FROM divefile'); 
    	# $info = mysql_fetch_assoc($result);
    	if ($result && mysql_num_rows($result)) {
    		$numrows = mysql_num_rows($result);
    		$rowcount = 1;
    		print "There are $numrows records here!<br /><br />";
    		while($row = mysql_fetch_assoc($result)) {
    			$diverid 	= $info['dive_id'];
    			$divername 	= $info['dive_diverid'];
    			$Dive_list_fields .= <<<__HTML_END
    <table width="500" border="1" cellspacing="1" cellpadding="1"> 
    <tr>
    <td>
    Dive id : $diverid   
    </td>
    <td>
    Dive name : $divername 
    </td>
    </tr>
    __HTML_END;
    		}
    	}

    Then it must work. Is it so?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much, it works now.

  5. #5
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <table width="500" border="1" cellspacing="1" cellpadding="1"> 
    <?php
    $result 
    mysql_query('SELECT dive_id,dive_diverid FROM divefile') or die(mysql_error());
    if (
    $result &&  mysql_num_rows($result)){
        
    $numrows mysql_num_rows($result);
        
    $rowcount 1;
        print 
    "There are $numrows records here!<br /><br />";
        while(
    $row mysql_fetch_assoc($result)){
            
    $diverid $row['dive_id'];
            
    $divername $row['dive_diverid'];
            
    $Dive_list_fields = <<<__HTML_END
    <tr> 
    <td> 
    Dive id : 
    $diverid    
    </td> 
    <td> 
    Dive name : 
    $divername 
    </td> 
    </tr>
    __HTML_END;
            echo 
    $Dive_list_fields;
             }
         }
    ?>
    </table>
    my mobile portal
    ghiris.ro


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
  •