Solved

Creating a Simple Content system (Viewing records in expanding table view)

Posted on 2007-03-23
4
256 Views
Last Modified: 2013-12-13
Hi all,

The second issue would be to dynamically display the contents of my update table with expanding tables, when the cell with the updateinfo and date is clicked the description would be shown.

So heres the problem, I have little PHP MySQL knowledge. The application I am developing is in vb to show updates on software I publish on the network and general information to all users at logon, I have a webcontrol that is going to contain the finished output.

I am looking for some help to put together 3 parts, so 3 questions.

1. Just a simple add record form to MySQL db, 4 fields in the table(Updates).

Date   UpdateName Description   ID

2. Show the contents of the the updates in table form ie using expanding tables, the title click expands the description.

Start Menu Changes(UpdateName)                    23/03/07(Date)
blah blah blah.........................................................(Description)
Desktop Changes(UpdateName)                        22/03/07(Date)
blah blah blah.........................................................(Description)
Application Changes(UpdateName)                    21/03/07(Date)
blah blah blah.........................................................(Description)

3. Just a simple remove record form to MySQL db, 4 fields in the table(Updates).

Many Thanks
Steve
0
Comment
Question by:Stephen Manderson
  • 2
4 Comments
 
LVL 14

Assisted Solution

by:Vel Eous
Vel Eous earned 100 total points
ID: 18783326
To retreive your results and display them in a table:

<?PHP

$get_all_data = mysql_query("SELECT * FROM table");  // get all db data, if any
$count_all_data = mysql_num_rows($get_all_data);  // count all the db data

// if there is data in the db
if ($count_all_data > 0) {

      // create a table
      echo ("<br/>&nbsp; &nbsp; &nbsp; Below is a list of all current data ...<br /><br />");
      echo ("<table width='90%' align='center'><tr><td><font color='#FF0000'>Col1</font></td><td><font color='#FF0000'>Col2</font></td><td><font color='#FF0000'>Col3</font></td><td><font color='#FF0000'>Col4</font></td><td><font color='#FF0000'>Col5</td></tr>");

      //while there is more data in the db
      while($rows = mysql_fetch_array($get_all_data)) {
            // display that data [col1], [col2] etc are your table field names
            echo ("<tr><td>") . $rows[col1] . ("</td><td>") . $rows[col2] . ("</td><td>") . $rows[col3] . ("</td><td>") . $rows[col4] . ("</td><td>") . $rows[col5] . ("</td>");
      }

      // close the table
      echo ("</tr></table><br /><br />");

}

?>

You will obviously need to include your DB connection code aswell.
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 400 total points
ID: 18783343
Here is the hole thing in a single file add , show , delete the sql for the table is at the top of the page

<?

/*##########SQL TABLE#################


CREATE TABLE `record` (
  `ID` int(11) NOT NULL auto_increment,
  `Date` date NOT NULL,
  `UpdateName` varchar(255) NOT NULL,
  `Description` text NOT NULL,
  PRIMARY KEY  (`ID`)
);



*/

$db_name = "test";

$db = mysql_connect("localhost","root","qazplm");
mysql_select_db($db_name,$db);

if($_POST["op"]=="Add") {

      mysql_query("INSERT INTO record SET Date=now(), UpdateName='".$_POST["UpdateName"]."', Description='".$_POST["Description"]."'");


}

if($_POST["op"]=="Delete" && $_POST["del"]){

      
      $i=0;
      
      foreach($_POST["del"] as $value) {
      
            if($i==0) {
            
                  $str = " WHERE ID=".$value;
                  
            }else{
            
                  $str .= " OR ID=".$value;
            }            
            
      
            $i++;
      }
      
      $q = "DELETE FROM record ".$str;
      
      
      mysql_query("DELETE FROM record ".$str) or die(mysql_error());


}

      $get_record = mysql_query("SELECT * FROM record ORDER by Date");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Simple Content system</title>
<script type="text/javascript">
<!--
function show_hide(obj) {
      var el = document.getElementById(obj);
      if ( el.style.display != "none" ) {
            el.style.display = 'none';
      }
      else {
            el.style.display = '';
      }
}
//-->
</script>
</head>

<body>
<form name="myform" action="<?=$_SERVER['PHP_SELF']?>" method="post">
<h3>ADD RECORD</h3>
<div>
<p><b>UpdateName</b><br />
<input type="text" name="UpdateName" /><br />
</p>

<p><b>Description</b><br />
<textarea name="Description" cols="60" rows="8"></textarea><br />
</p>
<input type="submit" name="op" value="Add" />
</div>

<hr width="100%" />

<?

      while($row = mysql_fetch_object($get_record)) {
      
            print "<p><b><a  onClick='show_hide(\"d_".$row->ID."\")' style='cursor:hand;'>".$row->UpdateName."</a></b> <input type='checkbox' name='del[]' value='".$row->ID."'> delete</p>";
            
            print "<div id='d_".$row->ID."' style='display:none;border:#666666 solid 1px;'>";
            
            print $row->Description;
            
            print "</div>";
      
      
      
      
      
      }



?>
<p>
<input type="submit" name="op" value="Delete" />
</p>


</body>
</html>
0
 
LVL 19

Author Comment

by:Stephen Manderson
ID: 18786227
Many Thanks for that Seth

Just a quick question tough, how would i go about displaying the expanding tables in their own page? and can it be done where the cell click expands the row?

Thanks
Steve
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 18788056
Hi steve, thanks for the points and the grade . Here is an update for the records page

$db_name = "test";

$db = mysql_connect("localhost","root","qazplm");
mysql_select_db($db_name,$db);

if($_POST["op"]=="Delete" && $_POST["del"]){

      
      $i=0;
      
      foreach($_POST["del"] as $value) {
      
            if($i==0) {
            
                  $str = " WHERE ID=".$value;
                  
            }else{
            
                  $str .= " OR ID=".$value;
            }            
            
      
            $i++;
      }
      
      $q = "DELETE FROM record ".$str;
      
      
      mysql_query("DELETE FROM record ".$str) or die(mysql_error());


}

      $get_record = mysql_query("SELECT * FROM record ORDER by Date");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Simple Content system</title>
<script type="text/javascript">
<!--
function show_hide(obj) {
      var el = document.getElementById(obj);
      if ( el.style.display != "none" ) {
            el.style.display = 'none';
      }
      else {
            el.style.display = '';
      }
}
//-->
</script>
</head>

<body>
<form name="myform" action="<?=$_SERVER['PHP_SELF']?>" method="post">


<table cellpadding="2" cellspacing="0" border="1" width="600">

<?

      while($row = mysql_fetch_object($get_record)) {
      
            print "<tr>
                              <td valign='top' onClick='show_hide(\"d_".$row->ID."\")' width='500'  style='cursor:hand;'>";
            print "<b>".$row->UpdateName."</b></td>";
            print "<td valign='top' width='100'><input type='checkbox' name='del[]' value='".$row->ID."'> delete";
            print "</td></tr>";
            print "<tr id='d_".$row->ID."' style='display:none;'><td valign='top' colspan='2'>";
            
            print $row->Description;
            
            print "</td></tr>";
      
      }



?>
</table>
<p>
<input type="submit" name="op" value="Delete" />
</p>
</form>

</body>
</html>
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now