Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7632957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:45:30+00:00 2026-05-31T06:45:30+00:00

Firstly, I do not want an alternative code, I only want help to make

  • 0

Firstly, I do not want an alternative code, I only want help to make this work.
Using the code below I want to write out the data from the database table to the xml file but I am only getting the “john” and “123” with out the correct xml tags and my second foreach() doesnt work, but the first foreach() to display the table works.

<?php

$dbhandle = sqlite_popen("propertydb", 0666, $err_msg);
if(!$dbhandle) die("Could not open the database");

$query = "CREATE TABLE property(pCode VARCHAR(8), price VARCHAR(6), 
iFile VARCHAR(15),          visits VARCHAR(3))";
if(!sqlite_query($dbhandle, $query)){ echo "table not created (maybe already
created)";
} 

$query = sqlite_query($dbhandle, 'SELECT * FROM property');  
$result = sqlite_fetch_all($query, SQLITE_ASSOC);  

foreach ($result as $arow) {
echo '<br> Postcode:  ' . $arow['pCode'] . '  Price:  ' . $arow['price'] . 
' Image  File:  ' . $arow['iFile'] . ' Visits:  ' . $arow['visits'];
}

$outfilepointer = fopen("property.xml","w");
$outtext = "<estateagent> \n";
$outtext .= "<agentname>john</agentname> \n";
$outtext .= "<agentphone>123</agentphone> \n";
foreach ($result->property as $oneproperty)
{
$propertyname = $oneproperty->propertyname;
outtext .= '<property><postcode> $arow["pCode"] </postcode>
<price> $arow["price"]</price> <imagefile> $arow["iFile"] </imagefile> <visits>
$arow["visits"] 
</visits>    </property> \n';
}
$outtex .= "</estateagent>";
fwrite($outfilepointer, $outtext);
fclose($outfilepointer);
sqlite_close($dbhandle);
?>

This is what my output should be…

<estateagent>
<agentname></agentname>
<agentphone></agentphone>
<property>
<postcode></postcode><price></price><imagefile></imagefile><visits></visits>
</property>
<property>...</property>
<property>...</property>
</estateagent>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:45:31+00:00Added an answer on May 31, 2026 at 6:45 am

    I just tried using your code and the XML tags do show up. Try opening it in notepad to see.

    As for your foreach loop, you need to concatenate your strings.

    outtext .= '<property><postcode> $arow["pCode"] </postcode> 
    <price> $arow["price"]</price> <imagefile> $arow["iFile"] </imagefile> <visits> 
    $arow["visits"]  
    </visits>    </property> \n'; 
    

    For the foreach, my understanding is that sqlite_fetch_all returns an array. You are treating it as a variable.

    Try using: foreach ($result as $oneproperty). As I am not sure how your database is structured, if that does not work for you, post the output of $result using var_dump($result).

    The above means that the literal string will be outputted and no variables will be inserted. You need to do this:

    outtext .= '<property><postcode>'. $arow["pCode"]. '</postcode> 
    <price>'. $arow["price"].'</price> <imagefile>'. $arow["iFile"].' </imagefile> <visits>'. 
    $arow["visits"].'
    </visits>    </property> \n'; 
    

    Finally, instead of creating your tags manually with strings, consider using the XML Writer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, I do not have any malicious intent out of this question. I would
Firstly, I want to apologize for my English, not my strongest side. To the
Ok, firstly this is not about forms this is about consistent layout as a
Firstly: I am totally a newbie for this kind of work. I have a
Firstly, I have migrated my CVS repository into SVN repository. I checked out this
Firstly, this DB question could be a bit DB agnostic, but I am using
Firstly I just want to say I'm not an ASP developer, I'm PHP through
Firstly I want to say I know little english. I have seeking about this
(Firstly, as a disclaimer, this is related to an assignment. I'm not asking anyone
firstly, pardon my pseudo-code, i think in this case it is more legible than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.