Jump to content

data value from database


sigmahokies

Recommended Posts

I succeed to create the vertical data, but I just add checkbox in data table in PHP. I know how to set up the value in checkbox, but i can't figure how to put name and value that from database. for example, when you can see name list in columns, you click checkbox that which has name that selected data from database. here example in code:

 

 

I can get value from outside of php in html:

<input type="checkbox" name="???" value="<?php echo $data['Name'] ?>">

 

But I can't figure to set up the value that inside php:

echo "<tr><td><input type="checkbox" name="???" value=?></td></tr>";

 

my point is I can use echo to print, but echo is used already, php cannot take two name code in same time, same line number. Can you help? If you want to see my full code in php, Let me know...I will put my code in next comment in this thread.

 

Thank you so much!

Gary Taylor

Link to comment
https://forums.phpfreaks.com/topic/296618-data-value-from-database/
Share on other sites

echo '<tr><td><input type="checkbox" name="'.$data['name'].'" value='.$data['value'].'></td></tr>';

When echoing html, I find it best to use 'single quotes' to encase the string.  That way you don't have to escape the double quotes in the html to concatenate the php vars in the string.  This way also makes the vars stand out in the code o you can see them better.

Hi Fastsol,

 

I did that...seem value didn't set up with database. here my full code in php. Bold words means it needs to be fix.

 

1 <!doctype html>
2 <html>
3 <head>
4 <title>Test array with columns</title>
5 </head>
6 <body>
7 <form action="testarray3.php" method="GET">
8< fieldset>
9 <?php
10 $column = 2;
 
11 $Garydb = mysqli_connect('xxxx','xxxx','xxxx') or die("Could not connect to database.");
12 mysqli_select_db($Garydb, 'xxxx');
13 $sql = "SELECT CONCAT(FirstName,' ',LastName) AS Name FROM Members ORDER BY LastName ASC";
14 $result = mysqli_query($Garydb, $sql);
15 $num_rows = mysqli_num_rows($result);
16 $rows = ceil($num_rows / $column);
17 while ($row = mysqli_fetch_array($result)) {
18 $data[] = $row['Name'];
19 }
20 echo "<table border='1'>\n";
21 for($i = 0; $i < $rows; $i++) {
22 echo "<tr>\n";
23 for($j = 0; $j < $column; $j++) {
24 if(isset($data[$i + ($j * $rows)])) {
25 echo "<td>".$data[$i + ($j * $rows)]."</td><td><input type='checkbox' name='".$result['Name']."' value='".$result['Name']."'></td>\n";
26 }
27 }
28 echo "</tr>\n";
29 }
30 echo "</table>\n";
31 ?>
32 <input type="submit" value='Attendence'>
33 </fieldset>
34 </form>
35 </body>
36 </html>
 
I know #25 is wrong, I just can't figure how to put data can display name in checkbox itself. I need to have name from database that inside checkbox, so value can transfer the name into another page.

Hi cyberRobot,

 

very close, but web address show "Array=Array&Array=Array&Array=Array&Array=Array". I need something to show "Gary=Taylor&(first name)=(last name)&(first name)=(last name)&...

which allow transfer any value to other page or display in below of array on top of screen.

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.