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. -
<?php
-
# Connect to the database
-
$dbLink = mysql_connect("xxx.xxx.xx.x", "xxx", "xxx")
-
or die("Error! Failed to connect to the MySQL server!");
-
mysql_select_db("databasename", $dbLink)
-
or die("Error! Failed to select a database!");
-
-
# Query for a list of all existing files
-
$result = mysql_query("SELECT name, age, approved FROM table1");
-
-
# Check if it was successfull
-
if($result)
-
{
-
# Make sure there are some files in there
-
if(mysql_num_rows($result) == 0) {
-
echo "<p>There are no files in the database</p>";
-
}
-
else
-
{
-
# Print the top of a table or header
-
echo "<table width='100%'><tr>";
-
echo "<td><b>Name</b></td>";
-
echo "<td><b>Age</b></td>";
-
echo "<td><b>Click the box to approved</b></td>";
-
-
# Print each data
-
while($row = mysql_fetch_assoc($result))
-
{
-
# Print file info
-
echo "<tr border=10><td>". $row['name']. "</td>";
-
echo "<td>". $row['age']. "</td>";
-
#how could I add a check box here?
-
echo "</tr>";
-
}
-
-
# Close table
-
echo "</table>";
-
}
-
}
-
else
-
{
-
echo "Error! SQL query failed:";
-
echo "<pre>". mysql_error($dbLink) ."</pre>";
-
}
-
-
# Close the mysql connection
-
mysql_close($dbLink) ;
-
?>
14 3662
Heya, ddtpmyra.
Please use CODE tags when posting source code:
[CODE=php]
PHP code goes here.
[/CODE]
Thanks for your time.
pbmods
anybody can help?
All I need is to insert a text box inside the row
could you explain little bit brief.... Why u can't add the checkbox in to loop.....
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> </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]
Hey could said where u can face the problems..?
Am not facing any problem in ur code (i changed some thing see) -
<?
-
-
#
-
# 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> </b></td>";
-
#
-
echo "</tr>";
-
#
-
$res="select * from app";
-
$result=mysql_query($res);
-
#
-
# #Print each file
-
#
-
$i=0;
-
while($row = mysql_fetch_assoc($result))
-
#
-
{
-
#
-
$i++;
-
#
-
# Print file info FROM THE MYSQL TABLE
-
#
-
echo "<tr border=10><td>". $row['Created']. "</td>";
-
#
-
echo "<td>". $row['File Name']. "</td>";
-
#
-
-
#
-
echo "<td>". $row['Requestor']. "</td>";
-
#
-
echo "<td>". $row['Author']. "</td>";
-
#
-
echo "<td>". $row['Deadline Feedback']. "</td>";
-
#
-
echo "<td>". $row['Approved']. "</td>";
-
#
-
echo "<td>". $row['Category']. "</td>";
-
echo "<td><input type=\"checkbox\" name=\"chkid_$i\"></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>";
-
#
-
}
-
?>
-
Hey Maheswaran it works thanks a ton... its the syntax all a long :)
maheswaran,
How can I update mysql table when the box are checked?
thanks!
for that am incresed the checkbox name with $i -
<input type=\"checkbox\" name=\"chkid_$i\">
-
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) -
for($j=0;$j<$i;$j++)
-
{
-
$chkid=$_POST['$chkid'_$j'];
-
$qry="update qry";
-
$res=mysql($qry,$db);
-
}
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!
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... -
$i=$count_rows;
-
for($j=0;$j<$i;$j++)
-
{
-
$chkid=$_POST['chkid'_$j'];
-
$qry="update filestorage set Approved='Y'";
-
$res=mysql_query($qry);
-
}
-
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]
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]
just add where conditions in that
Try this - while($row = mysql_fetch_assoc($result))
-
{
-
# Print file info
-
echo "<tr border=10><td>". $row['name']. "</td>";
-
echo "<td>". $row['age']. "</td>";
-
echo"<input type='checkbox' name='check' name='value' id='check'>";
-
echo "</tr>";
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
| |