John Davidson

php - Ho to get data from dynamic table

0 comments
Message:


i am new to php and got a problem, where I can not find the right answer for.
My goal is to print an invoice from a MySQL database, but instead of directly throwing it trough fpdf, I want to to create a page, where the user can edit the values, that are finally printed.
I have realized this with a dynamic table which looks like that:


<?php
while($aufstellung = mysqli_fetch_array($content)){
$gesamtRechnungsSumme += $aufstellung['GesamtpreisZeit'];
echo
"<tr>
<td><input type='text' name='w_type' value=".$aufstellung['w_type']."></td>
<td><input type='text' name='dauer' value=".$aufstellung['Dauer']."></td>
<td><input type='text' name='price' value=".$aufstellung['price']."€"."></td>
<td><input type='text' name='gesamtzeit' value=" .$aufstellung['GesamtpreisZeit']."€"."></td></tr>";
}

But now the amount of fields in table varies for every invoice. So how can I grab every single value as a constant like $_POST['XY'] in my fpdf page?


Thank you for every idea.



My Answer:
To grab every single value from the dynamic table as a constant in your fpdf page, you can use an array to store the values of each input field. Here's an example of how you can modify your code to achieve this:

php
$values = array();
while($aufstellung = mysqli_fetch_array($content)){
$gesamtRechnungsSumme += $aufstellung['GesamtpreisZeit'];
echo
"



";

// Store the values in the array
$values[] = array(
'w_type' => $aufstellung['w_type'],
'dauer' => $aufstellung['Dauer'],
'price' => $aufstellung['price'],
'gesamtzeit' => $aufstellung['GesamtpreisZeit']
);
}

// Store the values array in a session variable
$_SESSION['invoice_values'] = $values;
?>


In your fpdf page, you can access the values from the session variable like this:

php
session_start();

// Get the values array from the session variable
$values = $_SESSION['invoice_values'];

// Loop through the values array and access each value
foreach($values as $value){
$w_type = $value['w_type'];
$dauer = $value['dauer'];
$price = $value['price'];
$gesamtzeit = $value['gesamtzeit'];

// Use the values as needed in your fpdf page
}
?>


This way, you can store the values from the dynamic table in an array and access them in your fpdf page using the session variable.

Rate this post

3 of 5 based on 7368 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us