php - mysql column data display, fetching all fields of a column and displaying it as a link -


i have code fields of column "username".

what trying is, want display each user in separate line , make link consists of each respective username.

for example have usernames mike , tom in column "username" of database, want display mike link href="/mike" , tom link href="/tom". amount of usernames varying need output them all.

    <a href="/<?php $sql = "select * users"; $result = mysql_query($sql); while ( $db_field = mysql_fetch_assoc($result) ) {  print $db_field['username'] . "<br>";  }?>"><?php $sql = "select * users"; $result = mysql_query($sql); while ( $db_field = mysql_fetch_assoc($result) ) {  print $db_field['username'] . "<br>";  } ?></a> 

the way did here, taking names , outputs 1 link names in it.

so wondering how can separate each username , give own link?

thanks in advance guys!

do -

<?php  $mysqli = new mysqli('host', 'username', 'password', 'db'); $sql = "select * users"; $result = mysqli_query($mysqli, $sql);  while ( $db_field = mysqli_fetch_assoc($result)) { ?>  <a href="/<?php echo $db_field['username'];?>"><?php echo $db_field['username'];?></a><br/> <?php } 

mysql deprecated. use mysqli or pdo instead.


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -