473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

displaying check box inside row query

ddtpmyra
333 100+
Hi below is my script displaying all the information inside the table.

Pupose:
pupose of this php page is to display all the information on my table and have a check box at the last column that will allow the user to approved the member.

Problem:
I don't how to insert a checkbox on a loop condition.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # Connect to the database
  3. $dbLink = mysql_connect("xxx.xxx.xx.x", "xxx", "xxx")
  4. or die("Error! Failed to connect to the MySQL server!");
  5. mysql_select_db("databasename", $dbLink)
  6. or die("Error! Failed to select a database!");
  7.  
  8. # Query for a list of all existing files
  9. $result = mysql_query("SELECT name, age, approved FROM table1");
  10.  
  11. # Check if it was successfull
  12. if($result)
  13. {
  14. # Make sure there are some files in there
  15. if(mysql_num_rows($result) == 0) {
  16.     echo "<p>There are no files in the database</p>";
  17. }
  18. else
  19. {
  20.     # Print the top of a table or header
  21.     echo "<table width='100%'><tr>";
  22.     echo "<td><b>Name</b></td>";
  23.     echo "<td><b>Age</b></td>";
  24.     echo "<td><b>Click the box to approved</b></td>";        
  25.  
  26.     # Print each data
  27.     while($row = mysql_fetch_assoc($result))
  28.     {
  29.         # Print file info
  30.         echo "<tr border=10><td>". $row['name']. "</td>";
  31.         echo "<td>". $row['age']. "</td>";
  32.         #how could I add a check box here?
  33.         echo "</tr>";
  34.     }
  35.  
  36.     # Close table
  37.     echo "</table>";
  38. }
  39. }
  40. else
  41. {
  42. echo "Error! SQL query failed:";
  43. echo "<pre>". mysql_error($dbLink) ."</pre>";
  44. }
  45.  
  46. # Close the mysql connection
  47. mysql_close($dbLink) ;
  48. ?>
Sep 2 '08 #1
14 3662
pbmods
5,821 Expert 4TB
Heya, ddtpmyra.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]

Thanks for your time.

pbmods
Sep 2 '08 #2
ddtpmyra
333 100+
anybody can help?

All I need is to insert a text box inside the row
Sep 4 '08 #3
maheswaran
190 100+
could you explain little bit brief.... Why u can't add the checkbox in to loop.....
Sep 5 '08 #4
ddtpmyra
333 100+
Hi maheswaran,

Below again is the script I placed 'comment #' where i wanted to insert a check box. The code will be used for displaying the list of documents coming from mysql database.

Placing the checkbox inside the loop will allow the admin to approved it by checking the texbox and I'm having trouble of placing the check box inside the loop while displaying the records.

[PHP]{

# Print the top of a table LABELINGS
echo "<table width='100%'><tr>";
echo "<td><b>Created</b></td>";
echo "<td><b>File Name</b></td>";
echo "<td><b>Requestor</b></td>";
echo "<td><b>Author</b></td>";
echo "<td><b>Deadline Feedback</b></td>";
echo "<td><b>Approved</b></td>";
echo "<td><b>Category</b></td>";
echo "<td><b>Click the box to approved</b></td>"; echo "<td><b>&nbsp;</b></td>";
echo "</tr>";

# #Print each file
while($row = mysql_fetch_assoc($result))
{

# Print file info FROM THE MYSQL TABLE
echo "<td>". $row['Created']. "</td>";
echo "<tr border=10><td>". $row['FileName']. "</td>";
echo "<td>". $row['Created']. "</td>";
echo "<td>". $row['Requestor']. "</td>";
echo "<td>". $row['Author']. "</td>";
echo "<td>". $row['DeadLineFeedback']. "</td>";
echo "<td>". $row['approved']. "</td>";
echo "<td>". $row['category']. "</td>";

#THIS IS WHERE WHERE I WANTED TO PUT THE CHECK BOX echo "<td><input type="text"></td>";
#Print download link
echo "<td><a href='get_file.php?id=". $row['FileID'] ."'>Download";
echo "</tr>";
}[/PHP]
Sep 10 '08 #5
maheswaran
190 100+
Hey could said where u can face the problems..?

Am not facing any problem in ur code (i changed some thing see)

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. #
  4. # Print the top of a table LABELINGS
  5. #
  6.                             echo "<table width='100%'><tr>";
  7. #
  8.                             echo "<td><b>Created</b></td>";
  9. #
  10.                             echo "<td><b>File Name</b></td>";
  11. #
  12.                             echo "<td><b>Requestor</b></td>";
  13. #
  14.                             echo "<td><b>Author</b></td>";
  15. #
  16.                             echo "<td><b>Deadline Feedback</b></td>";
  17. #
  18.                             echo "<td><b>Approved</b></td>";
  19. #
  20.                             echo "<td><b>Category</b></td>";                           
  21. #
  22.     echo "<td><b>Click the box to approved</b></td>";                           echo "<td><b>&nbsp;</b></td>";
  23. #
  24.                             echo "</tr>";
  25. #
  26.          $res="select * from app";
  27.          $result=mysql_query($res);
  28. #
  29.                             # #Print each file
  30. #                            
  31.                             $i=0;
  32.                             while($row = mysql_fetch_assoc($result))
  33. #
  34.                             {
  35. #
  36.                            $i++;
  37. #
  38. # Print file info FROM THE MYSQL TABLE
  39. #
  40.                                 echo "<tr border=10><td>". $row['Created']. "</td>";
  41. #
  42.                                 echo "<td>". $row['File Name']. "</td>";
  43. #
  44.  
  45. #
  46.                                 echo "<td>". $row['Requestor']. "</td>";
  47. #
  48.                                 echo "<td>". $row['Author']. "</td>";
  49. #
  50.                                 echo "<td>". $row['Deadline Feedback']. "</td>";
  51. #
  52.                                 echo "<td>". $row['Approved']. "</td>";
  53. #
  54.                                 echo "<td>". $row['Category']. "</td>";
  55.                                 echo "<td><input type=\"checkbox\" name=\"chkid_$i\"></td>";
  56. #
  57.  
  58. #
  59.  #THIS IS WHERE WHERE I WANTED TO PUT THE CHECK BOX        echo "<td><input type="text"></td>";
  60. #
  61.                                 #Print download link
  62. #
  63.                                 echo "<td><a href='get_file.php?id=". $row['FileID'] ."'>Download";
  64. #
  65.                                 echo "</tr>";
  66. #
  67.                             }
  68.                             ?>
  69.  
Sep 11 '08 #6
ddtpmyra
333 100+
Hey Maheswaran it works thanks a ton... its the syntax all a long :)
Sep 11 '08 #7
ddtpmyra
333 100+
maheswaran,

How can I update mysql table when the box are checked?

thanks!
Sep 15 '08 #8
maheswaran
190 100+
for that am incresed the checkbox name with $i

Expand|Select|Wrap|Line Numbers
  1. <input type=\"checkbox\" name=\"chkid_$i\">
  2.  
Just you make the loop for number of rows or count. We knew the total number of records, so pass the this count and do it like

(for xample i=5)
Expand|Select|Wrap|Line Numbers
  1. for($j=0;$j<$i;$j++)
  2. {
  3. $chkid=$_POST['$chkid'_$j'];
  4. $qry="update qry";
  5. $res=mysql($qry,$db);
  6. }
Sep 17 '08 #9
ddtpmyra
333 100+
maheswaran
please tell me what's wrong with my update it's not working

[PHP]
<?php

# Connect to the database
$dbLink = mysql_connect("localhost", "xxx", "xxx")
or die("Error! Failed to connect to the MySQL server!");
mysql_select_db("cmr", $dbLink)
or die("Error! Failed to select a database!");



# Gather all required data
$i=5;
for($j=0;$j<$i;$j++)
{
$chkid=$_POST['$chkid'_$j'];
$qry="update filestorage set Approved='Y'";
$res=mysql($qry,$db);
}

?>
[/PHP]


and what if I don't know exactly how many the $i is since the user will add data and delete data daily?

thanks!
Sep 17 '08 #10
maheswaran
190 100+
Hey myra,

Just for an example am giving $i=5; just you count the number of rows in ur table and place that one (.i.e $i=$count_rows)..and sorry i mistakenly added $_POST['$chkid'_$j'] instead of $_POST['chkid'_$j'] and change the mysql connection string.. see below... may its help...

Expand|Select|Wrap|Line Numbers
  1.                      $i=$count_rows;
  2.                         for($j=0;$j<$i;$j++)
  3.                         {
  4.                         $chkid=$_POST['chkid'_$j'];
  5.                         $qry="update filestorage set Approved='Y'";
  6.                         $res=mysql_query($qry);
  7.                         }  
  8.  
Sep 18 '08 #11
ddtpmyra
333 100+
Hi maheswaran... i'ts still not updating my table please help if I missing a link here.

Step 1 Displaying the row data
[PHP]
<form action='approvals_file3.php' method='post'>
<?php


# Connect to the database
$dbLink = mysql_connect("localhost", "xxx", "xxx")
or die("Error! Failed to connect to the MySQL server!");
mysql_select_db("cmr", $dbLink)
or die("Error! Failed to select a database!");

# Query
$result = mysql_query("SELECT filebaname, approved from filestorage");


# Print the top of a table
echo "<td><b>filename</b></td>";
echo "<td><b>aproved</b></td>";


# Print each file
while($row = mysql_fetch_assoc($result))
{
# Print file info
echo "<tr border=10><td>". $row['filename']. "</td>";
echo "<td><input type=\"checkbox\" name=\"chkid_$i\"></td>";
}


# Close the mysql connection
mysql_close($dbLink);

?>
<input type='submit' value='Submit'>
</form>
[/PHP]

Step 2 Updating the row data

[PHP]
<?php

# Connect to the database
$dbLink = mysql_connect("localhost", "xxx", "xxx")
or die("Error! Failed to connect to the MySQL server!");
mysql_select_db("cmr", $dbLink)
or die("Error! Failed to select a database!");

$i=$count_rows;
for($j=0;$j<$i;$j++)
{
$chkid=$_POST['chkid'_$j'];
$qry="update filestorage set Approved='Y'";
$res=mysql_query($qry);
}

# Close the mysql connection
mysql_close($dbLink);
?>
[/PHP]
Sep 18 '08 #12
ddtpmyra
333 100+
This update my table but it updates all the records.
Little more help on this.. how can I update the only checked ones?

[PHP] $i=10;
for($j=0;$j<$i;$j++)
{
$chkid=$_POST['chkid_$j'];
$qry="update filestorage set Approved='Y'";
$res=mysql_query($qry);
}


[/PHP]
Sep 18 '08 #13
maheswaran
190 100+
just add where conditions in that
Sep 19 '08 #14
Try this
Expand|Select|Wrap|Line Numbers
  1.  while($row = mysql_fetch_assoc($result))
  2.     {
  3.         # Print file info
  4.         echo "<tr border=10><td>". $row['name']. "</td>";
  5.         echo "<td>". $row['age']. "</td>";
  6.         echo"<input type='checkbox' name='check' name='value' id='check'>";
  7.         echo "</tr>";
  8.     }
Jun 28 '14 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
0
by: Wynter | last post by:
RE: from Displaying a Document using the ASPNET user account to the Client Browser discussion (3/2/2004 Buddy Thanks for helping me on getting the document to display. But now I am left with a...
5
by: skinnybloke | last post by:
Hi I am trying to do something with PHP and having problems - a bit of a a PHP novice I'm afraid. What I am trying to achieve is to display the alphabet and numbers 0-9 on a web page. I want...
6
by: Matt K. | last post by:
Hi there, I have a form in an Access project that contains a subform which displays the results of a query of the style "select * from where = #a certain date#". In the main part of the form...
5
by: Robert | last post by:
Hello Accessors I have some reports created in Access that are very good for what they do. However, it seems to me that when you are displaying information you don't need to print out that a...
7
by: Joe | last post by:
I am using Access 2003 and are linking to an Oracle 9i ODBC datasource (using Oracle ODBC drivers). After linking the tables in Access, I inspect the data contained in the linked tables. For...
16
by: Akhenaten | last post by:
I must be missing something rather obvious. I have the following snippet of code that echo's my result twice when it should be echoing just once (only one element in the array). What am I...
7
by: EManning | last post by:
I'm using A2003 connected to a SQL 2000 backend. This is not an adp. I have a table which I store 0 and -1 for 2 bit fields. I have a listbox on a form based on a query of this table. The...
3
by: viperRider | last post by:
So, I'm not a total newbie, but I am stuck with this one. I have a database built up for my homebrewing operation. Each batch i make has steps like any recipe does, but these steps all have dates...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.