Jump to content

data value from database


Go to solution Solved by cyberRobot,

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

Edited by sigmahokies
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.

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 by cyberRobot

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.