Solved

How do I export to XML from a user selected set of checkboxes

Posted on 2008-06-19
2
302 Views
Last Modified: 2013-12-12
Hi
I have dishes stored in a database, and I have them called to index.php and i have added checkboxes to allow the user to add the selected dish to the XML output.

But the XML is creating a full list of database items in the XML I am using DW CS3 and Dreamweaver Development Toolbox with the Export to XML behavior

I want the user to be able to select the dishes he wants and then click a button to export to a XML file, is there any other way to do this?

Using PHP/MySQL

<?php require_once('Connections/db.php'); ?>
<?php
// Load the XML classes
//require_once('includes/XMLExport/XMLExport.php');
 
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
mysql_select_db($database_db, $db);
$query_Recordset1 = "SELECT * FROM menu";
$Recordset1 = mysql_query($query_Recordset1, $db) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
 
// Begin XMLExport Recordset1
//$xmlExportObj = new XMLExport();
//$xmlExportObj->setRecordset($Recordset1);
//$xmlExportObj->addColumn("Dish_group", "Dish_group");
//$xmlExportObj->addColumn("Dish_name", "Dish_name");
//$xmlExportObj->addColumn("Dish_description", "Dish_description");
//$xmlExportObj->setMaxRecords("ALL");
//$xmlExportObj->setDBEncoding("UTF-8");
//$xmlExportObj->setXMLEncoding("UTF-8");
//$xmlExportObj->setXMLFormat("NODES");
//$xmlExportObj->setRootNode("menu");
//$xmlExportObj->setRowNode("dish");
//$xmlExportObj->Execute();
// End XMLExport Recordset1
?><!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=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
}
.style2 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	font-style: italic;
}
-->
</style>
</head>
 
<body>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><?php echo $row_Recordset1['Dish_group']; ?></td>
  </tr>
</table>
<?php do { ?>
  <form id="form1" name="form1" method="post" action="">
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><span class="style1"><?php echo $row_Recordset1['Dish_name']; ?></span></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input name="checkbox" type="checkbox" id="checkbox" value="yes" /></td>
      </tr>
      <tr>
        <td><span class="style2"><?php echo $row_Recordset1['Dish_description']; ?></span></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
  </form>
  <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  <form id="form2" name="form2" method="post" action="">
    <input type="submit" name="Submit" id="button" value="Submit" />
</form>
  <a href="export.php">Export
  </a>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Open in new window

0
Comment
Question by:cataleptic_state
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 250 total points
ID: 21823198
Hi,

Idealy you would have a single form, instead of dozens to achieve this.

<form>
  .. start of loop ..
  <checkbox ..
  .. end of loop
</form>

Then all checkboxes should all have a "value" attribute which is not just 'yes' but holds a reference to a specific recipy (possibly a primairy key, or another unique field?)

Like <input name="selectedRecipies[]" type="checkbox" id="checkbox" value="<?php echo $row_Recordset1['Recipy_Id']; ?>" />

When the form is submitted you could use the $_POST['selectedRecipies'] to see which recipies have been selected.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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