Mysql fetch array, table results

后端 未结 6 1864
名媛妹妹
名媛妹妹 2021-01-14 10:07

i\'m pretty new to this and not sure how should i do it,

I\'ve got a database with a column called \"names\"

how can i make it display in so?



        
6条回答
  •  春和景丽
    2021-01-14 10:21

    So most of these answers are going for the kludge. First, if all you want is the name in your resultset, then only ask for it. So rather than going with:

    $result = mysql_query('SELECT * FROM member');
    

    Instead go with:

    $result = mysql_query('SELECT names FROM member');
    

    Also, everyone seems to be ignoring the three column request, and that can be satisfied using a modulo to tell when to break the rows. We'll do a little magic to make sure you always close the row tag.

    $row_count = 0;
    while($row = mysql_fetch_array($result))
      {
      if( $row_count % 3 == 0 )
        {
           echo '';
        }
        echo ''.$row['names'].'';
      if( $row_count % 3 == 0 )
        {
           echo '';
        }
      $row_count++; 
      }
    

    I don't want to get too picky about your schema, but if you have a choice, it's better to name the table a plural like members rather than member, since you have a collection of rows, each one representing one 'member'. And unless your members have multiple names that column could probably best be called 'name' instead.

提交回复
热议问题