Jump to content

Displaying columns with the values


scrubbicus

Recommended Posts

try google, you should find examples there.

 

Effectivly what you need to do though is:

 

<?php
$db_connect = database_connection();

$result = $db_connect->query('SELECT * FROM table1');

?>

<table>
  <tr>
    <th>Table Heading 1</th>
    <th>Table Heading 2</th>
  </tr>

<?php

while($row = $result->fetchObject())
{
  echo '<tr><td>'.$row->object_1.'</td><td>'.$row->object_2.'</td></tr>';
}

$db_connect = NULL;

?>

</table>

<?php ?>

 

actually this link will be better suited to what you want, because im used to using PDO now so my example wont work if you dont use PDO.

 

http://www.w3schools.com/php/php_mysql_select.asp

So I should mention that my display is within a class already. Can I put a class in another class not through extends? Any who what's that database_connection() function?

 

I also checked out the w3 and all that mentions is looping through table and only getting the values, it already fills in the headers for me. I'm trying the headers and the table values to both be dynamically generated so there doesn't have to be any hard code HTML.

umm... the database connection is that link I showed you. It basically connects to your mysql database, and lets you access it.

 

So you want the php to echo everything including the table headers?

Basically do the same as what you see in that link, except include the <th> tags in it. You wont be able to get away with including the <table> elements within that while loop, but you can always echo it out above as such:

 

echo '<table>';

 

while()

{

 

echo the rest of your table here...

 

}

 

echo '</table>';

 

Thats basically all I can say really, the answers are there.

 

EDIT: sorry I just realised what you are saying. You want the data thats within your database to be dynamically generated within your table? Well that piece of code I gave you does that.

Unless you are talking about ajax. But thats another can of worms.

Here's the code that displays it on my page

} elseif(isset($_GET['clients'])) {

$display->getClient($_GET['clients']);

}

 

And here's the method in the class

 

public function getClient($client) {

$results_columns = mysql_query('SHOW COLUMNS FROM clients');

$results_info = mysql_query('SELECT * FROM clients

WHERE name=\''.urldecode($client).'\'');

echo 'SELECT * FROM clients

WHERE name=\''.urldecode($client).'\'';

echo '<table width="100%">

<tr> <th> Field </th> <th> Data </th> </tr>';

while($row = mysql_fetch_array($results_info)) {

while($row1 = mysql_fetch_array($results_columns)) {

echo '<tr> <td>'.$row.'</td>'; echo '<td>'.$row1.'</td> </tr>';

}

 

}

echo '</table>';

}

 

That's what I have so far but all it echos is Array for everything

 

 

I don't want the fields to be on horizontally on top I want them to be vertically on the left side and my information be on the right like

 

<tr> <td> Name: </td> <td> namehere </td> </tr>

<tr> <td> E-Mail: </td> <td> [email protected] </td> </tr>

<tr> <td> Information: </td> <td> here </td> </tr>

 

<tr> <td> $header['name']: </td> <td> $info['name'] </td> </tr>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.