Using MySql data row value as html table headers and divisions in PHPCan I concatenate multiple MySQL rows into one field?Which MySQL data type to use for storing boolean valuesConvert HTML + CSS to PDF with PHP?Should I use the datetime or timestamp data type in MySQL?Finding duplicate values in MySQLDuplicating a MySQL table, indices, and dataHow do you parse and process HTML/XML in PHP?SQL select only rows with max value on a columnHow to fix “Headers already sent” error in PHPHow to get the sizes of the tables of a MySQL database?
Disabling quote conversion in docstrings
Why did WWI include Japan?
GitLab account hacked and repo wiped
Dangerous workplace travelling
Why is my arithmetic with a long long int behaving this way?
Endgame puzzle: How to avoid stalemate and win?
What's the 2-minute timer on mobile Deutsche Bahn tickets?
In "Avengers: Endgame", what does this name refer to?
Should I simplify my writing in a foreign country?
Motion-trail-like lines
Copy previous line to current line from text file
How to preserve a rare version of a book?
Would a small hole in a Faraday cage drastically reduce its effectiveness at blocking interference?
Sheared off exhasut pipe: How to fix without a welder?
Page count conversion from single to double-space for submissions
If an old FIN is delivered, will TCP terminate the new connection?
How to Practice After Stream Entry as Opposed to Before?
Which US defense organization would respond to an invasion like this?
Meaning of the (idiomatic?) expression "seghe mentali"
Why are oscilloscope input impedances so low?
How to pass query parameters in URL in Salesforce Summer 19 Release?
My first C++ game (snake console game)
Who filmed the Apollo 11 trans-lunar injection?
Why didn't this character get a funeral at the end of Avengers: Endgame?
Using MySql data row value as html table headers and divisions in PHP
Can I concatenate multiple MySQL rows into one field?Which MySQL data type to use for storing boolean valuesConvert HTML + CSS to PDF with PHP?Should I use the datetime or timestamp data type in MySQL?Finding duplicate values in MySQLDuplicating a MySQL table, indices, and dataHow do you parse and process HTML/XML in PHP?SQL select only rows with max value on a columnHow to fix “Headers already sent” error in PHPHow to get the sizes of the tables of a MySQL database?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I want to dynamically generate an HTML table based on MySql data, and the user would be able to update the table directly on the page (through JQuery and Ajax).
Week rows will be inserted for the entire year all at once in table schedule
.
Each week has no more than 2 users assigned to.
A user can be removed at any time and replaced with another user.
The first table column of each row contains all the users and then each column represents a week from tuesday to tuesday for the entire year. Expected HTML result :
+-------+--------------------------+--------------------------+--------------------------+
| Users | 2019-03-19 to 2019-03-26 | 2019-03-26 to 2019-04-02 | 2019-04-02 to 2019-04-09 |
+-------+--------------------------+--------------------------+--------------------------+
| 1 | | | |
+-------+--------------------------+--------------------------+--------------------------+
| 2 | X | X | |
+-------+--------------------------+--------------------------+--------------------------+
| 3 | X | | |
+-------+--------------------------+--------------------------+--------------------------+
| 4 | | | |
+-------+--------------------------+--------------------------+--------------------------+
| 5 | | X | |
+-------+--------------------------+--------------------------+--------------------------+
Schema :
table schedule
+-------------+------------+------------+------------+------------+
| schedule_id | user1 | user2 | dateStart | dateEnd |
| PK AUTO_INC | FK int(11) | FK int(11) | date | date |
+-------------+------------+------------+------------+------------+
| 1 | 3 | 2 | 2019-03-19 | 2019-03-26 |
+-------------+------------+------------+------------+------------+
| 2 | 5 | 2 | 2019-03-26 | 2019-04-02 |
+-------------+------------+------------+------------+------------+
| 3 | null | null | 2019-04-02 | 2019-04-09 |
+-------------+------------+------------+------------+------------+
Users are gradually being assigned. The user1
and user2
columns allow for null
and later on someone can enter the users for a particular week.
I need to check with PHP if one or two users are already assigned, then someone can update a row with either a user id or null (removing a user).
For this purpose I use variables $set1
and $set2
and data-attributes
(for later use with jQuery) telling me which week has a user in user1
or user2
.
I can echo the table <th>
with all the necessary data.
Now my question is how to echo the table <td>
. I need to find a way to generete <tr>
for each users and <td>
for each <th>
while matching the user id value.
Therefore, if the week inserted in <th>
has user 2 assigned, I will add an 'X' to the <td>
below that <th>
on user 2 row (see expected result above).
I was thinking myabe I can run another MySql query and while loop to echo by users and order by dates?
My code so far :
// Connect to database decyb
include 'dbconnect.php';
// MySQL query
$getUpdateDispoEnq = "
SELECT dispo_enq.*,
u1.firstName as enq1First,
u1.lastName as enq1Last,
u2.firstName as enq2First,
u2.lastName as enq2Last
FROM dispo_enq
JOIN users u1 ON dispo_enq.userEnq1 = u1.user_id
JOIN users u2 ON dispo_enq.userEnq2 = u2.user_id;";
// Prepared statements
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $getUpdateDispoEnq))
echo '<div class="red-text" style="margin-top: 1em">SQL error!</div>';
exit;
else
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($results);
$week = 0;
echo '<table class="dispo-enq">';
echo '<tr>';
echo '<th class="regular"><div><span>Enquêteurs</span></div></th>';
echo '<th class="regular"><div><span>Cellulaire</span></div></th>';
if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($results))
$enq1 = $row['userEnq1'];
$enq2 = $row['userEnq2'];
$dateStart = $row['dateStart'];
$dateEnd = $row['dateEnd'];
$week++;
// Check if users are set
if ($enq1 > 0)
$set1 = 1;
else
$set1 = 0;
if ($enq2 > 0)
$set2 = 1;
else
$set2 = 0;
// Display table headers
echo '<th class="rotate" data-week="'.$week.'" data-enq1="'.$set1.'" data-enq2="'.$set2.'"><div><span>'.$dateStart.' to '.$dateEnd.'</span></div></th>';
echo '</tr>';
echo '</table>';
exit;
php mysql
add a comment |
I want to dynamically generate an HTML table based on MySql data, and the user would be able to update the table directly on the page (through JQuery and Ajax).
Week rows will be inserted for the entire year all at once in table schedule
.
Each week has no more than 2 users assigned to.
A user can be removed at any time and replaced with another user.
The first table column of each row contains all the users and then each column represents a week from tuesday to tuesday for the entire year. Expected HTML result :
+-------+--------------------------+--------------------------+--------------------------+
| Users | 2019-03-19 to 2019-03-26 | 2019-03-26 to 2019-04-02 | 2019-04-02 to 2019-04-09 |
+-------+--------------------------+--------------------------+--------------------------+
| 1 | | | |
+-------+--------------------------+--------------------------+--------------------------+
| 2 | X | X | |
+-------+--------------------------+--------------------------+--------------------------+
| 3 | X | | |
+-------+--------------------------+--------------------------+--------------------------+
| 4 | | | |
+-------+--------------------------+--------------------------+--------------------------+
| 5 | | X | |
+-------+--------------------------+--------------------------+--------------------------+
Schema :
table schedule
+-------------+------------+------------+------------+------------+
| schedule_id | user1 | user2 | dateStart | dateEnd |
| PK AUTO_INC | FK int(11) | FK int(11) | date | date |
+-------------+------------+------------+------------+------------+
| 1 | 3 | 2 | 2019-03-19 | 2019-03-26 |
+-------------+------------+------------+------------+------------+
| 2 | 5 | 2 | 2019-03-26 | 2019-04-02 |
+-------------+------------+------------+------------+------------+
| 3 | null | null | 2019-04-02 | 2019-04-09 |
+-------------+------------+------------+------------+------------+
Users are gradually being assigned. The user1
and user2
columns allow for null
and later on someone can enter the users for a particular week.
I need to check with PHP if one or two users are already assigned, then someone can update a row with either a user id or null (removing a user).
For this purpose I use variables $set1
and $set2
and data-attributes
(for later use with jQuery) telling me which week has a user in user1
or user2
.
I can echo the table <th>
with all the necessary data.
Now my question is how to echo the table <td>
. I need to find a way to generete <tr>
for each users and <td>
for each <th>
while matching the user id value.
Therefore, if the week inserted in <th>
has user 2 assigned, I will add an 'X' to the <td>
below that <th>
on user 2 row (see expected result above).
I was thinking myabe I can run another MySql query and while loop to echo by users and order by dates?
My code so far :
// Connect to database decyb
include 'dbconnect.php';
// MySQL query
$getUpdateDispoEnq = "
SELECT dispo_enq.*,
u1.firstName as enq1First,
u1.lastName as enq1Last,
u2.firstName as enq2First,
u2.lastName as enq2Last
FROM dispo_enq
JOIN users u1 ON dispo_enq.userEnq1 = u1.user_id
JOIN users u2 ON dispo_enq.userEnq2 = u2.user_id;";
// Prepared statements
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $getUpdateDispoEnq))
echo '<div class="red-text" style="margin-top: 1em">SQL error!</div>';
exit;
else
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($results);
$week = 0;
echo '<table class="dispo-enq">';
echo '<tr>';
echo '<th class="regular"><div><span>Enquêteurs</span></div></th>';
echo '<th class="regular"><div><span>Cellulaire</span></div></th>';
if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($results))
$enq1 = $row['userEnq1'];
$enq2 = $row['userEnq2'];
$dateStart = $row['dateStart'];
$dateEnd = $row['dateEnd'];
$week++;
// Check if users are set
if ($enq1 > 0)
$set1 = 1;
else
$set1 = 0;
if ($enq2 > 0)
$set2 = 1;
else
$set2 = 0;
// Display table headers
echo '<th class="rotate" data-week="'.$week.'" data-enq1="'.$set1.'" data-enq2="'.$set2.'"><div><span>'.$dateStart.' to '.$dateEnd.'</span></div></th>';
echo '</tr>';
echo '</table>';
exit;
php mysql
add a comment |
I want to dynamically generate an HTML table based on MySql data, and the user would be able to update the table directly on the page (through JQuery and Ajax).
Week rows will be inserted for the entire year all at once in table schedule
.
Each week has no more than 2 users assigned to.
A user can be removed at any time and replaced with another user.
The first table column of each row contains all the users and then each column represents a week from tuesday to tuesday for the entire year. Expected HTML result :
+-------+--------------------------+--------------------------+--------------------------+
| Users | 2019-03-19 to 2019-03-26 | 2019-03-26 to 2019-04-02 | 2019-04-02 to 2019-04-09 |
+-------+--------------------------+--------------------------+--------------------------+
| 1 | | | |
+-------+--------------------------+--------------------------+--------------------------+
| 2 | X | X | |
+-------+--------------------------+--------------------------+--------------------------+
| 3 | X | | |
+-------+--------------------------+--------------------------+--------------------------+
| 4 | | | |
+-------+--------------------------+--------------------------+--------------------------+
| 5 | | X | |
+-------+--------------------------+--------------------------+--------------------------+
Schema :
table schedule
+-------------+------------+------------+------------+------------+
| schedule_id | user1 | user2 | dateStart | dateEnd |
| PK AUTO_INC | FK int(11) | FK int(11) | date | date |
+-------------+------------+------------+------------+------------+
| 1 | 3 | 2 | 2019-03-19 | 2019-03-26 |
+-------------+------------+------------+------------+------------+
| 2 | 5 | 2 | 2019-03-26 | 2019-04-02 |
+-------------+------------+------------+------------+------------+
| 3 | null | null | 2019-04-02 | 2019-04-09 |
+-------------+------------+------------+------------+------------+
Users are gradually being assigned. The user1
and user2
columns allow for null
and later on someone can enter the users for a particular week.
I need to check with PHP if one or two users are already assigned, then someone can update a row with either a user id or null (removing a user).
For this purpose I use variables $set1
and $set2
and data-attributes
(for later use with jQuery) telling me which week has a user in user1
or user2
.
I can echo the table <th>
with all the necessary data.
Now my question is how to echo the table <td>
. I need to find a way to generete <tr>
for each users and <td>
for each <th>
while matching the user id value.
Therefore, if the week inserted in <th>
has user 2 assigned, I will add an 'X' to the <td>
below that <th>
on user 2 row (see expected result above).
I was thinking myabe I can run another MySql query and while loop to echo by users and order by dates?
My code so far :
// Connect to database decyb
include 'dbconnect.php';
// MySQL query
$getUpdateDispoEnq = "
SELECT dispo_enq.*,
u1.firstName as enq1First,
u1.lastName as enq1Last,
u2.firstName as enq2First,
u2.lastName as enq2Last
FROM dispo_enq
JOIN users u1 ON dispo_enq.userEnq1 = u1.user_id
JOIN users u2 ON dispo_enq.userEnq2 = u2.user_id;";
// Prepared statements
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $getUpdateDispoEnq))
echo '<div class="red-text" style="margin-top: 1em">SQL error!</div>';
exit;
else
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($results);
$week = 0;
echo '<table class="dispo-enq">';
echo '<tr>';
echo '<th class="regular"><div><span>Enquêteurs</span></div></th>';
echo '<th class="regular"><div><span>Cellulaire</span></div></th>';
if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($results))
$enq1 = $row['userEnq1'];
$enq2 = $row['userEnq2'];
$dateStart = $row['dateStart'];
$dateEnd = $row['dateEnd'];
$week++;
// Check if users are set
if ($enq1 > 0)
$set1 = 1;
else
$set1 = 0;
if ($enq2 > 0)
$set2 = 1;
else
$set2 = 0;
// Display table headers
echo '<th class="rotate" data-week="'.$week.'" data-enq1="'.$set1.'" data-enq2="'.$set2.'"><div><span>'.$dateStart.' to '.$dateEnd.'</span></div></th>';
echo '</tr>';
echo '</table>';
exit;
php mysql
I want to dynamically generate an HTML table based on MySql data, and the user would be able to update the table directly on the page (through JQuery and Ajax).
Week rows will be inserted for the entire year all at once in table schedule
.
Each week has no more than 2 users assigned to.
A user can be removed at any time and replaced with another user.
The first table column of each row contains all the users and then each column represents a week from tuesday to tuesday for the entire year. Expected HTML result :
+-------+--------------------------+--------------------------+--------------------------+
| Users | 2019-03-19 to 2019-03-26 | 2019-03-26 to 2019-04-02 | 2019-04-02 to 2019-04-09 |
+-------+--------------------------+--------------------------+--------------------------+
| 1 | | | |
+-------+--------------------------+--------------------------+--------------------------+
| 2 | X | X | |
+-------+--------------------------+--------------------------+--------------------------+
| 3 | X | | |
+-------+--------------------------+--------------------------+--------------------------+
| 4 | | | |
+-------+--------------------------+--------------------------+--------------------------+
| 5 | | X | |
+-------+--------------------------+--------------------------+--------------------------+
Schema :
table schedule
+-------------+------------+------------+------------+------------+
| schedule_id | user1 | user2 | dateStart | dateEnd |
| PK AUTO_INC | FK int(11) | FK int(11) | date | date |
+-------------+------------+------------+------------+------------+
| 1 | 3 | 2 | 2019-03-19 | 2019-03-26 |
+-------------+------------+------------+------------+------------+
| 2 | 5 | 2 | 2019-03-26 | 2019-04-02 |
+-------------+------------+------------+------------+------------+
| 3 | null | null | 2019-04-02 | 2019-04-09 |
+-------------+------------+------------+------------+------------+
Users are gradually being assigned. The user1
and user2
columns allow for null
and later on someone can enter the users for a particular week.
I need to check with PHP if one or two users are already assigned, then someone can update a row with either a user id or null (removing a user).
For this purpose I use variables $set1
and $set2
and data-attributes
(for later use with jQuery) telling me which week has a user in user1
or user2
.
I can echo the table <th>
with all the necessary data.
Now my question is how to echo the table <td>
. I need to find a way to generete <tr>
for each users and <td>
for each <th>
while matching the user id value.
Therefore, if the week inserted in <th>
has user 2 assigned, I will add an 'X' to the <td>
below that <th>
on user 2 row (see expected result above).
I was thinking myabe I can run another MySql query and while loop to echo by users and order by dates?
My code so far :
// Connect to database decyb
include 'dbconnect.php';
// MySQL query
$getUpdateDispoEnq = "
SELECT dispo_enq.*,
u1.firstName as enq1First,
u1.lastName as enq1Last,
u2.firstName as enq2First,
u2.lastName as enq2Last
FROM dispo_enq
JOIN users u1 ON dispo_enq.userEnq1 = u1.user_id
JOIN users u2 ON dispo_enq.userEnq2 = u2.user_id;";
// Prepared statements
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $getUpdateDispoEnq))
echo '<div class="red-text" style="margin-top: 1em">SQL error!</div>';
exit;
else
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($results);
$week = 0;
echo '<table class="dispo-enq">';
echo '<tr>';
echo '<th class="regular"><div><span>Enquêteurs</span></div></th>';
echo '<th class="regular"><div><span>Cellulaire</span></div></th>';
if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($results))
$enq1 = $row['userEnq1'];
$enq2 = $row['userEnq2'];
$dateStart = $row['dateStart'];
$dateEnd = $row['dateEnd'];
$week++;
// Check if users are set
if ($enq1 > 0)
$set1 = 1;
else
$set1 = 0;
if ($enq2 > 0)
$set2 = 1;
else
$set2 = 0;
// Display table headers
echo '<th class="rotate" data-week="'.$week.'" data-enq1="'.$set1.'" data-enq2="'.$set2.'"><div><span>'.$dateStart.' to '.$dateEnd.'</span></div></th>';
echo '</tr>';
echo '</table>';
exit;
php mysql
php mysql
edited Mar 23 at 3:35
turboisturbo
asked Mar 23 at 3:12
turboisturboturboisturbo
205
205
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You have a task similar to mine in a way but since I can get the code I used there I decided to simply post what I can get out of my brain under such a short notice.
// MySQL query
$getUpdateDispoEnq = "
SELECT dispo_enq.*, u1.firstName as enq1First, u1.lastName as enq1Last, u2.firstName as enq2First, u2.lastName as enq2Last
FROM dispo_enq
JOIN users u1 ON dispo_enq.userEnq1 = u1.user_id
JOIN users u2 ON dispo_enq.userEnq2 = u2.user_id;";
$html = '';
// Prepared statements
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $getUpdateDispoEnq))
$html .= '<div class="red-text" style="margin-top: 1em">SQL error!</div>';
exit;
else
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($results);
$week = $set1 = $set2 = 0;
$dateStart = $dateEnd = '';
$html .= '<table class="dispo-enq"><tr>';
$html .= '<th class="regular"><div><span>Enquêteurs</span></div></th>';
$html .= '<th class="regular"><div><span>Cellulaire</span></div></th>';
if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($results))
$enq1 = $row['userEnq1'];
$enq2 = $row['userEnq2'];
$dateStart = $row['dateStart'];
$dateEnd = $row['dateEnd'];
$week++;
// Check if users are set
if ($enq1 > 0) $set1 = 1;
if ($enq2 > 0) $set2 = 1;
// Display table headers
$html .= '<th class="rotate" data-week="'.$week.'" data-enq1="'.$set1.'" data-enq2="'.$set2.'">';
$html .= '<div><span>'.$dateStart.' to '.$dateEnd.'</span></div></th>';
$html .= '</tr>';
$result = mysql_query("SELECT firstName, lastName FROM users");
while ($rows = mysql_fetch_assoc($result))
$html .= '<tr>';
$html = '<td>'.$week.'</td>';
foreach ($rows as $row) $html .= '<td>'.$row.'</td>';
$html = '<td>'.$dateStart.'</td>';
$html = '<td>'.$dateEnd.'</td>';
$html .= '</tr>';
$html .= '</table>';
exit;
return $html;
Thanks for the reply. I thnk we're going in the same direction with the second query and a foreach loop. I will have to modify your answer as you didn't display the rows the way i intended. Each row following the headers should look like<tr><td>Username</td><td></td><td></td><td></td>(repeated as many $week)</tr>
. I will try something similar.
– turboisturbo
Mar 23 at 12:47
It's because I don't get your table for users clearly. Modify your question to include mysql tables and I will modify the answer to fit your needs. Meanwhile be polite and upvote it
– Jack Siro
Mar 23 at 19:55
My question wasn't clear. See this link
– turboisturbo
Mar 23 at 20:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310254%2fusing-mysql-data-row-value-as-html-table-headers-and-divisions-in-php%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have a task similar to mine in a way but since I can get the code I used there I decided to simply post what I can get out of my brain under such a short notice.
// MySQL query
$getUpdateDispoEnq = "
SELECT dispo_enq.*, u1.firstName as enq1First, u1.lastName as enq1Last, u2.firstName as enq2First, u2.lastName as enq2Last
FROM dispo_enq
JOIN users u1 ON dispo_enq.userEnq1 = u1.user_id
JOIN users u2 ON dispo_enq.userEnq2 = u2.user_id;";
$html = '';
// Prepared statements
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $getUpdateDispoEnq))
$html .= '<div class="red-text" style="margin-top: 1em">SQL error!</div>';
exit;
else
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($results);
$week = $set1 = $set2 = 0;
$dateStart = $dateEnd = '';
$html .= '<table class="dispo-enq"><tr>';
$html .= '<th class="regular"><div><span>Enquêteurs</span></div></th>';
$html .= '<th class="regular"><div><span>Cellulaire</span></div></th>';
if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($results))
$enq1 = $row['userEnq1'];
$enq2 = $row['userEnq2'];
$dateStart = $row['dateStart'];
$dateEnd = $row['dateEnd'];
$week++;
// Check if users are set
if ($enq1 > 0) $set1 = 1;
if ($enq2 > 0) $set2 = 1;
// Display table headers
$html .= '<th class="rotate" data-week="'.$week.'" data-enq1="'.$set1.'" data-enq2="'.$set2.'">';
$html .= '<div><span>'.$dateStart.' to '.$dateEnd.'</span></div></th>';
$html .= '</tr>';
$result = mysql_query("SELECT firstName, lastName FROM users");
while ($rows = mysql_fetch_assoc($result))
$html .= '<tr>';
$html = '<td>'.$week.'</td>';
foreach ($rows as $row) $html .= '<td>'.$row.'</td>';
$html = '<td>'.$dateStart.'</td>';
$html = '<td>'.$dateEnd.'</td>';
$html .= '</tr>';
$html .= '</table>';
exit;
return $html;
Thanks for the reply. I thnk we're going in the same direction with the second query and a foreach loop. I will have to modify your answer as you didn't display the rows the way i intended. Each row following the headers should look like<tr><td>Username</td><td></td><td></td><td></td>(repeated as many $week)</tr>
. I will try something similar.
– turboisturbo
Mar 23 at 12:47
It's because I don't get your table for users clearly. Modify your question to include mysql tables and I will modify the answer to fit your needs. Meanwhile be polite and upvote it
– Jack Siro
Mar 23 at 19:55
My question wasn't clear. See this link
– turboisturbo
Mar 23 at 20:05
add a comment |
You have a task similar to mine in a way but since I can get the code I used there I decided to simply post what I can get out of my brain under such a short notice.
// MySQL query
$getUpdateDispoEnq = "
SELECT dispo_enq.*, u1.firstName as enq1First, u1.lastName as enq1Last, u2.firstName as enq2First, u2.lastName as enq2Last
FROM dispo_enq
JOIN users u1 ON dispo_enq.userEnq1 = u1.user_id
JOIN users u2 ON dispo_enq.userEnq2 = u2.user_id;";
$html = '';
// Prepared statements
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $getUpdateDispoEnq))
$html .= '<div class="red-text" style="margin-top: 1em">SQL error!</div>';
exit;
else
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($results);
$week = $set1 = $set2 = 0;
$dateStart = $dateEnd = '';
$html .= '<table class="dispo-enq"><tr>';
$html .= '<th class="regular"><div><span>Enquêteurs</span></div></th>';
$html .= '<th class="regular"><div><span>Cellulaire</span></div></th>';
if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($results))
$enq1 = $row['userEnq1'];
$enq2 = $row['userEnq2'];
$dateStart = $row['dateStart'];
$dateEnd = $row['dateEnd'];
$week++;
// Check if users are set
if ($enq1 > 0) $set1 = 1;
if ($enq2 > 0) $set2 = 1;
// Display table headers
$html .= '<th class="rotate" data-week="'.$week.'" data-enq1="'.$set1.'" data-enq2="'.$set2.'">';
$html .= '<div><span>'.$dateStart.' to '.$dateEnd.'</span></div></th>';
$html .= '</tr>';
$result = mysql_query("SELECT firstName, lastName FROM users");
while ($rows = mysql_fetch_assoc($result))
$html .= '<tr>';
$html = '<td>'.$week.'</td>';
foreach ($rows as $row) $html .= '<td>'.$row.'</td>';
$html = '<td>'.$dateStart.'</td>';
$html = '<td>'.$dateEnd.'</td>';
$html .= '</tr>';
$html .= '</table>';
exit;
return $html;
Thanks for the reply. I thnk we're going in the same direction with the second query and a foreach loop. I will have to modify your answer as you didn't display the rows the way i intended. Each row following the headers should look like<tr><td>Username</td><td></td><td></td><td></td>(repeated as many $week)</tr>
. I will try something similar.
– turboisturbo
Mar 23 at 12:47
It's because I don't get your table for users clearly. Modify your question to include mysql tables and I will modify the answer to fit your needs. Meanwhile be polite and upvote it
– Jack Siro
Mar 23 at 19:55
My question wasn't clear. See this link
– turboisturbo
Mar 23 at 20:05
add a comment |
You have a task similar to mine in a way but since I can get the code I used there I decided to simply post what I can get out of my brain under such a short notice.
// MySQL query
$getUpdateDispoEnq = "
SELECT dispo_enq.*, u1.firstName as enq1First, u1.lastName as enq1Last, u2.firstName as enq2First, u2.lastName as enq2Last
FROM dispo_enq
JOIN users u1 ON dispo_enq.userEnq1 = u1.user_id
JOIN users u2 ON dispo_enq.userEnq2 = u2.user_id;";
$html = '';
// Prepared statements
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $getUpdateDispoEnq))
$html .= '<div class="red-text" style="margin-top: 1em">SQL error!</div>';
exit;
else
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($results);
$week = $set1 = $set2 = 0;
$dateStart = $dateEnd = '';
$html .= '<table class="dispo-enq"><tr>';
$html .= '<th class="regular"><div><span>Enquêteurs</span></div></th>';
$html .= '<th class="regular"><div><span>Cellulaire</span></div></th>';
if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($results))
$enq1 = $row['userEnq1'];
$enq2 = $row['userEnq2'];
$dateStart = $row['dateStart'];
$dateEnd = $row['dateEnd'];
$week++;
// Check if users are set
if ($enq1 > 0) $set1 = 1;
if ($enq2 > 0) $set2 = 1;
// Display table headers
$html .= '<th class="rotate" data-week="'.$week.'" data-enq1="'.$set1.'" data-enq2="'.$set2.'">';
$html .= '<div><span>'.$dateStart.' to '.$dateEnd.'</span></div></th>';
$html .= '</tr>';
$result = mysql_query("SELECT firstName, lastName FROM users");
while ($rows = mysql_fetch_assoc($result))
$html .= '<tr>';
$html = '<td>'.$week.'</td>';
foreach ($rows as $row) $html .= '<td>'.$row.'</td>';
$html = '<td>'.$dateStart.'</td>';
$html = '<td>'.$dateEnd.'</td>';
$html .= '</tr>';
$html .= '</table>';
exit;
return $html;
You have a task similar to mine in a way but since I can get the code I used there I decided to simply post what I can get out of my brain under such a short notice.
// MySQL query
$getUpdateDispoEnq = "
SELECT dispo_enq.*, u1.firstName as enq1First, u1.lastName as enq1Last, u2.firstName as enq2First, u2.lastName as enq2Last
FROM dispo_enq
JOIN users u1 ON dispo_enq.userEnq1 = u1.user_id
JOIN users u2 ON dispo_enq.userEnq2 = u2.user_id;";
$html = '';
// Prepared statements
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $getUpdateDispoEnq))
$html .= '<div class="red-text" style="margin-top: 1em">SQL error!</div>';
exit;
else
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($results);
$week = $set1 = $set2 = 0;
$dateStart = $dateEnd = '';
$html .= '<table class="dispo-enq"><tr>';
$html .= '<th class="regular"><div><span>Enquêteurs</span></div></th>';
$html .= '<th class="regular"><div><span>Cellulaire</span></div></th>';
if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($results))
$enq1 = $row['userEnq1'];
$enq2 = $row['userEnq2'];
$dateStart = $row['dateStart'];
$dateEnd = $row['dateEnd'];
$week++;
// Check if users are set
if ($enq1 > 0) $set1 = 1;
if ($enq2 > 0) $set2 = 1;
// Display table headers
$html .= '<th class="rotate" data-week="'.$week.'" data-enq1="'.$set1.'" data-enq2="'.$set2.'">';
$html .= '<div><span>'.$dateStart.' to '.$dateEnd.'</span></div></th>';
$html .= '</tr>';
$result = mysql_query("SELECT firstName, lastName FROM users");
while ($rows = mysql_fetch_assoc($result))
$html .= '<tr>';
$html = '<td>'.$week.'</td>';
foreach ($rows as $row) $html .= '<td>'.$row.'</td>';
$html = '<td>'.$dateStart.'</td>';
$html = '<td>'.$dateEnd.'</td>';
$html .= '</tr>';
$html .= '</table>';
exit;
return $html;
answered Mar 23 at 5:25
Jack SiroJack Siro
1
1
Thanks for the reply. I thnk we're going in the same direction with the second query and a foreach loop. I will have to modify your answer as you didn't display the rows the way i intended. Each row following the headers should look like<tr><td>Username</td><td></td><td></td><td></td>(repeated as many $week)</tr>
. I will try something similar.
– turboisturbo
Mar 23 at 12:47
It's because I don't get your table for users clearly. Modify your question to include mysql tables and I will modify the answer to fit your needs. Meanwhile be polite and upvote it
– Jack Siro
Mar 23 at 19:55
My question wasn't clear. See this link
– turboisturbo
Mar 23 at 20:05
add a comment |
Thanks for the reply. I thnk we're going in the same direction with the second query and a foreach loop. I will have to modify your answer as you didn't display the rows the way i intended. Each row following the headers should look like<tr><td>Username</td><td></td><td></td><td></td>(repeated as many $week)</tr>
. I will try something similar.
– turboisturbo
Mar 23 at 12:47
It's because I don't get your table for users clearly. Modify your question to include mysql tables and I will modify the answer to fit your needs. Meanwhile be polite and upvote it
– Jack Siro
Mar 23 at 19:55
My question wasn't clear. See this link
– turboisturbo
Mar 23 at 20:05
Thanks for the reply. I thnk we're going in the same direction with the second query and a foreach loop. I will have to modify your answer as you didn't display the rows the way i intended. Each row following the headers should look like
<tr><td>Username</td><td></td><td></td><td></td>(repeated as many $week)</tr>
. I will try something similar.– turboisturbo
Mar 23 at 12:47
Thanks for the reply. I thnk we're going in the same direction with the second query and a foreach loop. I will have to modify your answer as you didn't display the rows the way i intended. Each row following the headers should look like
<tr><td>Username</td><td></td><td></td><td></td>(repeated as many $week)</tr>
. I will try something similar.– turboisturbo
Mar 23 at 12:47
It's because I don't get your table for users clearly. Modify your question to include mysql tables and I will modify the answer to fit your needs. Meanwhile be polite and upvote it
– Jack Siro
Mar 23 at 19:55
It's because I don't get your table for users clearly. Modify your question to include mysql tables and I will modify the answer to fit your needs. Meanwhile be polite and upvote it
– Jack Siro
Mar 23 at 19:55
My question wasn't clear. See this link
– turboisturbo
Mar 23 at 20:05
My question wasn't clear. See this link
– turboisturbo
Mar 23 at 20:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310254%2fusing-mysql-data-row-value-as-html-table-headers-and-divisions-in-php%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown