sigmahokies Posted June 3, 2015 Share Posted June 3, 2015 (edited) 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 Edited June 3, 2015 by sigmahokies Quote Link to comment https://forums.phpfreaks.com/topic/296618-data-value-from-database/ Share on other sites More sharing options...
fastsol Posted June 3, 2015 Share Posted June 3, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/296618-data-value-from-database/#findComment-1513091 Share on other sites More sharing options...
cyberRobot Posted June 3, 2015 Share Posted June 3, 2015 (edited) For what it's worth, you can surround array variables with curly brackets if you want to include them in a string. echo "<p>{$data['value']} was checked</p>"; But I would use fastsol's suggestion for what you're currently trying to do. Edited June 3, 2015 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/296618-data-value-from-database/#findComment-1513093 Share on other sites More sharing options...
sigmahokies Posted June 3, 2015 Author Share Posted June 3, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/296618-data-value-from-database/#findComment-1513118 Share on other sites More sharing options...
ginerjm Posted June 3, 2015 Share Posted June 3, 2015 Did you get an error message? Try doing the arithmetic outside of the array reference. Quote Link to comment https://forums.phpfreaks.com/topic/296618-data-value-from-database/#findComment-1513119 Share on other sites More sharing options...
Solution cyberRobot Posted June 3, 2015 Solution Share Posted June 3, 2015 Unless I'm missing something, $result contains the MySQLi result object. It looks like $data should contain the values you want. Quote Link to comment https://forums.phpfreaks.com/topic/296618-data-value-from-database/#findComment-1513121 Share on other sites More sharing options...
sigmahokies Posted June 4, 2015 Author Share Posted June 4, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/296618-data-value-from-database/#findComment-1513152 Share on other sites More sharing options...
sigmahokies Posted June 4, 2015 Author Share Posted June 4, 2015 Hi cyberRobot, Never mind about above comment, I got it! just add $data[$i + ($j * $rows)] in value! it all takes in! Right now, i am testing to use $_GET and $_POST... Quote Link to comment https://forums.phpfreaks.com/topic/296618-data-value-from-database/#findComment-1513154 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.