Pass variable to PHP file which creates XML

Posted on 2010-01-01
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.

$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); 



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"?>'); ?>


  <?php if ($totalRows_rsAll > 0) { // Show if recordset not empty ?>

  <?php do { ?>


                <?php foreach ($row_rsAll as $column=>$value) { ?>

                <<?php echo $column; ?>><![CDATA[<?php echo $row_rsAll[$column]; ?>]]></<?php echo $column; ?>>

                <?php } ?>


    <?php } while ($row_rsAll = mysql_fetch_assoc($rsAll)); ?>

        <?php } // Show if recordset not empty ?>





Open in new window

Question by:DanielAttard
    LVL 70

    Expert Comment

    by:Jason C. Levine
    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.

    Author Comment

    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.  
    LVL 70

    Accepted Solution

    >> 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:


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

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    731 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

    15 Experts available now in Live!

    Get 1:1 Help Now