/    Sign up×
Community /Pin to ProfileBookmark

dynamic table

Hi!
I have a problem with my php code.
I have a query that return me some records (the number of records can change).
I need a page html that show me that record and put result in a table.
How can create this table with my php?
I need 7 record for each row. Can you help me to build my table with php?
An if number of record for each line become 5? Is possible modify easily my html table?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 15.2011 — [code=php]
$numColumns = 7; // number of columns in table
$sql = "SELECT * FROM table_name";
$result = mysql_query($sql);
$data = array();
while($row = mysql_fetch_assoc($result)) {
$data[] = $row;
}
$chunks = array_chunk($data, $numColumns);
echo "<table>n";
foreach($chunks as $chunk) {
echo "<tr>n";
foreach($chunk as $col) {
echo "<td>".$col['some_field']."</td>n";
}
// this for() loop only needed if you want to fill out last row with
// empty cells:
for($ix = 0, $max = $numColumns - count($chunk); $ix < $max; $ix++) {
echo "<td>&nbsp;</td>";
}
echo "</tr>n";
}
echo "</table>";
[/code]
Copy linkTweet thisAlerts:
@ojal__authorJun 22.2011 — Hi!thank for reply!

now I need to manage the paging of data. After 42 results of my query I need to add button for page next and prev..

I need help..
Copy linkTweet thisAlerts:
@NvenomJun 22.2011 — why dont you just get a data grid like FlexiGrid OR my personal favorite because of how easy it is to use Eyesis Data Grid
×

Success!

Help @ojal__ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...