[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Pass variable to PHP file which creates XML

Posted on 2010-01-01
3
Medium Priority
?
488 Views
Last Modified: 2013-12-12
The code below selects all records from the specified table, and outputs the results to XML.  I use the following constructor in HTML to create a dataset from these records:

var myDataset = new Spry.Data.XMLDataSet("xml/myTable.php", "root/record");

My question is, how can I pass a variable from the constructor line into the PHP file which will act as a filter?  What if I only want a subset of records from the underlying table?  Thanks for your help.
<?php
$hostname_conn = "localhost";
$database_conn = "myDB";
$username_conn = "root";
$password_conn = "root";
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
<?php
mysql_select_db($database_conn, $conn);
//$query_rsAll = "SELECT * FROM myTable";
$rsAll = mysql_query($query_rsAll, $conn) or die(mysql_error());
$row_rsAll = mysql_fetch_assoc($rsAll);
$totalRows_rsAll = mysql_num_rows($rsAll);
 
// Send the headers
header('Content-type: text/xml');
header('Pragma: public');        
header('Cache-control: private');
header('Expires: -1');
?>
<?php echo('<?xml version="1.0" encoding="utf-8"?>'); ?>
<root>
  <?php if ($totalRows_rsAll > 0) { // Show if recordset not empty ?>
  <?php do { ?>
        <record>
                <?php foreach ($row_rsAll as $column=>$value) { ?>
                <<?php echo $column; ?>><![CDATA[<?php echo $row_rsAll[$column]; ?>]]></<?php echo $column; ?>>
                <?php } ?>
        </record>
    <?php } while ($row_rsAll = mysql_fetch_assoc($rsAll)); ?>
        <?php } // Show if recordset not empty ?>
</root>
<?php
mysql_free_result($rsAll);
?>

Open in new window

0
Comment
Question by:DanielAttard
  • 2
3 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 26159984
Hi again Daniel,

You need to decide how the variable is going to be passed to the script.  You then re-do the Dreamweaver Recordset Wizard and choose the appropriate filter option.  DW will build the code for you.
0
 

Author Comment

by:DanielAttard
ID: 26160001
Ok thanks.  I'll take a look and let you know how I make out.  Just getting started with DW CS4.  It's all new to me.  
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 2000 total points
ID: 26160019
>> I'll take a look and let you know how I make out.

Sounds good.

For instance, let us assume this script is xml.php and you want to filter it by name=something.

One way to do it is to put the name in the url:

xml.php?filter=something

You then rerun the recordset wizard and select filter by URL Parameter and match it to the name column in the table...
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 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