Jump to content

sql data into table


truck7758

Recommended Posts

Hi All,

 

I currently have a table in mysql called supplier(suppid, name, address, telno, fax, website, accountno, accountmanager, email, accountlogin, accountpwd, otherinfo)

 

Was just wondering if it is possible to do 'select * from supplier' and then show the results in a table. Also, new suppliers are going to be added so the table will need to be able to handle these as they are added as well.

Hope this makes sense,

Thanks in advance,

Mike  :)

Link to comment
Share on other sites

Hi rhodesa,

 

I have copied the example and edited it to suit my particulars and have come up with the following:

 

<?php

// Connecting, selecting database

$mysqli = new mysqli('localhost','root','newr00t');

$mysqli->select_db('orders');

 

// Performing SQL query

$result = $mysqli->query("SELECT * FROM supplier");

 

// Printing results in HTML

echo "<table>\n";

 

while($line = $result->fetch_array()) {

 

echo "\t<tr>\n";

    foreach ($line as $col_value) {

        echo "\t\t<td>$col_value</td>\n";

    }

    echo "\t</tr>\n";

}

echo "</table>\n";

 

// Free resultset

mysqli_free_result($result);

 

// Closing connection

$result->close();

?>

 

Now, although this does display the results from my table it is displaying everything twice and it also doesnt look very tidy. was kinda hoping for a table with visible rows and columns if this is possible.

 

Thanks for your support,

Mike

 

 

Link to comment
Share on other sites

Couple things...

1) Never post your passwords with your code. Replace them with stars: ********

2) Please use the code button when posting blocks of code. It's the one with the # sign on the toolbar

 

Glad you got it working. To use column headings use the following:

 

<table>
  <tr>
    <th>Column 1</th>
    <th>Column 2</th>
    <th>Column 3</th>
    <th>Column 4</th>
    <th>etc</th>
  </tr>
<?php
// Connecting, selecting database
$mysqli = new mysqli('*****','*******','*****');
      $mysqli->select_db('orders');

// Performing SQL query
$result = $mysqli->query("SELECT * FROM supplier");

while($line = $result->fetch_array()) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
// Free resultset
mysqli_free_result($result);
// Closing connection
$result->close();
?>
</table>

Link to comment
Share on other sites

Thanks guys a combination of the last 2 posts has left me with exactly what i require although there is still 1 error showing up:

 

Warning: Couldn't fetch mysqli_result in c:\webs\test\createingviewsuppliers2.php on line 27

 

Line 27 is:

 

$result->close();

 

Thanks,

Mike

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.