0

I have a table in database name Accounts in which i have many rows and many columns, i want to show a column Account (all values) in my html table. I have tried many method to show a specific column values without using index in html using php and I am using MySql.

$storeArray = Array();
while($rowval = mysql_fetch_array($whole, MYSQL_ASSOC))
{ 
$storeArray[] =  $rowval['Account'];  
$status= $rowval['status'];
$ph1= $rowval['Phone1'];
$ph2= $rowval['Phone2'];
}

by using <?php echo $storeArray[0]; ?> and <?php echo $storeArray[1]; ?> in <td> i got the solution. My question is there any way, it automatically show all values without providing any index?

4
  • 1
    Even a simple search on this site would have turned out hundreds of examples... Commented Jan 7, 2015 at 8:20
  • 1
    please show your code Commented Jan 7, 2015 at 8:23
  • edited, please check this out and help me out. Commented Jan 7, 2015 at 8:30
  • you can extract $rowval so that you can use table field name as variable name like $Account Commented Jan 7, 2015 at 9:41

4 Answers 4

2
$conn=new mysqli("localhost","root","","your_db");

$rows=$conn->query("select username from User");

echo "<table border='1'>";
echo "<tr><th>Username</th></tr>";
while(list($username)=$rows->fetch_row()){
  echo "<tr><td>$username</td></tr>";
}
echo "</table>";
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, can you tell me is there any way if click on $username then it fetch the whole row related to that username?
1

This is a pretty elaborate question. I think the best I can do is point you in the right direction. There is a good tutorial for this on w3schools.com. You should at least read these:

PHP - Connect to MySQL

PHP - Select Data From MySQL

and maybe

PHP - Limit Data Selections From MySQL

1 Comment

Thanks for your help. without giving index means automatically takes all the values from Accounts column and display in my html table
1
**file user.php**
<?php
$conn=new mysqli("localhost","root","","your_db");

$rows=$conn->query("select id,username from User");

echo "<table border='1'>";
echo "<tr><th>Username</th></tr>";
while(list($id,$username)=$rows->fetch_row()){
  echo "<tr>";
  echo "<td>";
  echo "<form action='user_details.php' target='_blank' method='post'>";
  echo "<input type='hidden' name='txtId' value='$id' />";
  echo "$id - $username";
  echo "<input type='submit' name='btnView' value='View' />";
  echo "</form>";
  echo "</td>";
  echo "</tr>";
}
echo "</table>";
?>

**file user_details.php**
<?php 

 if(isset($_POST["btnView"])){

   $id=$_POST["txtId"];

   $conn=new mysqli("localhost","root","","your_db");

   $row=$conn->query("select id,username,email,phone from User where id='$id'");

   list($id,$username,$email,$phone)=$row->fetch_row();

   echo $id," ",$username," ",$email," ",$phone;

 }



?>

2 Comments

Thanks. imgur.com/6QsvYrK Here is the link of image, I want whenever user click on name its details shows in above boxes, the details are associated to that specific name which is clicked.
If you want to a show the details above of the name list then include the user_details.php file at the top of user.php
1

if you want to fetch more than one database column in your html table column.

$conn=new mysqli("localhost","root","","your_db");

$rows=$conn->query("select col1,col2 from Tablename");

echo "<table border='1'>";
echo "<tr><th>col1</th><th>col2</th></tr>";
while(list($col1, $col2)=$rows->fetch_row())
{
  echo "<tr><td>$col1</td><td>$col2</tr>";
}
echo "</table>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.