Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP & HTML Table Help

    Hello and thanks in advance. I am pretty much new to php, and I have been having fun until now learning. lol I am honestly lost on this. Anyway, I am trying to get some data from MySql using php into a table with a format similar to this with links...

    Name1 Name2 Name3 Name4
    Name5 Name6 Name7 Name8
    Name9 Name10 Name11 Name12

    What I get so far is either

    Name1
    name2
    Name3
    Name4

    Or

    Name1 Name1 Name1 Name1
    Name2 Name2 Name2 Name2

    The code is below. Any help or good tutorials is appreciated.
    Code:
    <?
    
    
    /* DB Connect */
    $dbh = mysql_connect ("localhost", "XXXXXXXXXX",
    "XXXXXXXX") or die('Cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("XXXXXXXX", $dbh);
    $result = mysql_query('SELECT * FROM `smf_members` WHERE `fbname` != \'\' ORDER BY `date_registered` ASC') ;
    $num = mysql_numrows($result);
    
    echo '<table>' ;
    
    for($i = 0; $i < $num; $i++) {
    $row = mysql_fetch_assoc($result);
    $member_name = stripslashes($row['real_name']) ;
    $fbid = $row['fbname'] ;
    $link = '<a href="http://apps.facebook.com/castle_age/party.php?twt=jneg&jneg=true&user='. $fbid .'&lka='. $fbid .'=nf" target="_blank">'. $member_name .'</a>' ;
    
    
    echo '<tr>' ;
    	echo '<td>'. $link .'</td>' ;
    echo '</tr>' ;
    }
    
    echo '</table>' ;
    
    
    mysql_close($dbh);
    ?>

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Try this. You'll need to add your db open/close code back in at the top/bottom of the file.

    Code:
    $count = 0;
    
    print('<table>'."\n");
    
    while ($row = mysql_fetch_assoc($result))
    {
            $link = '<a href="http://apps.facebook.com/castle_age/party.php?twt=jneg&jneg=true&user='.$row['fbname'].'&lka='.$row['fbname'].'=nf" target="_blank">'.stripslashes($row['real_name']).'</a>';
    
            if ($count == 0)
            {
                    print('<tr>');
            }
            ++$count;
            print('<td>'.$link.'</td>');
    
            if ($count == 4)
            {
                    $count = 0;
                    print('</tr>'."\n");
            }
    }
    print('</table>'."\n");
    Last edited by MattF; 03-19-2010 at 09:57 PM.

  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I thank you sir... It worked perfectly. I have spent 2 days trying to get this to work the way I wanted, but I am pretty new to all of this.


  •  

    Posting Permissions

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