Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display dynamic Data as XML 1

Status
Not open for further replies.

tshey

Technical User
Dec 28, 2005
78
AU
Hi, I want to output a mysql table cutomers as xml.
What am I doing wrong. For this example i am using two fields.
<?php require_once('Connections/conn_members.php'); ?>
<?php
//this line selects all from the table customers
$result = mysql_query("SELECT * FROM customers");
// And now we need to output an XML document
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<customers>';
echo '<label>';
echo '<brides_fullname="Brides Name" />';
echo '<grooms_fullname="grooms_name" />';

//this is a loop that will fetch all entries
while($row=mysql_fetch_array($result)){
$line = '<brides_name="'.$row[brides_fullname].'"/>';
$line = '<brides_name="'.$row[grooms_fullname].'"/>';
echo $line;
}
echo '</label>';
echo '</customers>';
?>
 
What am I doing wrong
Tell us what you are expecting to get, and then explain to us what you actually get.

There are errors I can see in your loop:
Code:
//this is a loop that will fetch all entries
while($row=mysql_fetch_array($result)){
    $line = '<brides_name="'.$row[brides_fullname].'"/>';
    $line [!].[/!]= '<[!]groom[/!]s_name="'.$row[grooms_fullname].'"/>';
    echo $line;
}
Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
I get a message,
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.

I am trying to display a mysql table in xml, so that users can select specific rows and cells to save or cut and paste into a program like excell. Is this even the right way about acheiving this? Do you require more info? What would you like to know?
 
Please Help Me! Why is it not displaying?
 
Your query is not execting correctly. Add some error checking on connecting to the database and executing the query and report the mysql error that appear.
 
Is this better, sorry for being so slow, I am sooo new to php and am still getting a grasp on things. Thankyou for your patience. What am I doing wrong, the only message that appears is as mentioned before.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in cust.php on line 17

<?php require_once('Connections/conn_members.php'); ?>
<?php
mysql_select_db($database_conn_members, $conn_members);
$query_customers = "SELECT * FROM customers";
$customers = mysql_query($query_customers, $conn_members) or die(mysql_error());
$row_customers = mysql_fetch_assoc($customers);
$totalRows_customers = mysql_num_rows($customers);
?>
<?php
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<customers>';
echo '<label>';
echo '<brides_fullname="Brides Name" />';
echo '<grooms_fullname="grooms_name" />';

//this is a loop that will fetch all entries
while($row=mysql_fetch_array($result)){
$line = '<brides_fullname="'.$row[brides_fullname].'"/>';
$line .= '<grooms_fullname="'.$row[grooms_fullname].'"/>';
echo $line;
}
echo '</label>';
echo '</customers>';
?>

<html>
<head>
<title>Untitled Document</title>
</head>

<body>

</body>
</html>
<?php
mysql_free_result($customers);
?>
 
On line 17 you're fetching an array of something that is $result, while $result does not exist in your code. You have this line [tt]$row_customers = mysql_fetch_assoc($customers);[/tt] before in your code that already reads the first line. So it will throw off anything else. Move this line to the loop and you should be good:
Code:
while ($row = mysql_fetch_assoc($customers)) {
    $line = '<brides_fullname="'.$row['brides_fullname'].'"/>';
    $line .= '<grooms_fullname="'.$row['grooms_fullname'].'"/>';
    echo $line;
}
Make sure that the same call to mysql_fetch_assoc no longer exists above the while loop.
 
thankyou so much, however it does not display anything? I have checked the connection to the database, the table name etc. What are some scenarios?
 
I dont think it likes the '<>' . Could this be an echo prob?
 
might be but it's more likely to be your doctype declaration as php assumes you are going to use transitional if you have not explicitly set anything yourself. you can change the default in php.ini or change your page design to push out the right doctype in the header.

or if you want both the html and xml to be displayed on the same page wrap your xml declarations with "htmlentities()"

e.g.
Code:
echo htmlentities($line);

 
what if I use an escape sequence like this?
&#60;xml version="1.0" encoding="iso-8859-1"&#62;
&#60;waiq_members&#62;
&#60;customers&#62;<br>

<?php
//this is a loop that will fetch all entries
do
{?>
&#60;brides_fullname=&#34; <?php echo $row_customers['brides_fullname']; ?> &#34;&#47; &#62;
&#60;grooms_fullname=&#34;<?php echo $row_customers['grooms_fullname']; ?>&#34;&#47;&#62;<br>
<?php }while ($row_customers = mysql_fetch_assoc($customers)); ?>



&#60;customers&#62;
&#60;waiq_members&#62;

Will this still display it as xml? Is there any problems doing it like this?
 
sorry - can you post with
Code:
tags? it's difficult to derive what you meant in your post otherwise.
 
you might also consider checking out this faq: faq434-5576
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top