Re: [PHP] mysql -> xml
Hello, "Snijders, Mark" <[EMAIL PROTECTED]> wrote: > hello, > > For connection data between my site, and another site, I need to export my > MySql data to a XML file. > > Does anybody know any excisting scripts for this? so I don't have to make it > all myself? Have you checked the latest version of phpMyAdmin? You can export to XML--check how it works :) - E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RE: PHP/MySQL/XML
One thing you need to thing about is if you are going to us DTDs. If you are and they specify that you need the elements then it is best to add a space when nothing is contained in $ext... Thank you, Ray Hunter Firmware Engineer ENTERASYS NETWORKS > -Original Message- > From: Erik Price [mailto:[EMAIL PROTECTED]] > Sent: Monday, April 01, 2002 4:12 PM > To: Jay Fitzgerald > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP] RE: PHP/MySQL/XML > > > > On Monday, April 1, 2002, at 05:09 PM, Jay Fitzgerald wrote: > > > OkThanks to all those who are helping me (sorry for > > cross-posting)... > > That's okay. This script looks a lot better -- because you > can actually > -do- something with the output! :) > > > My scripts are working great except for one thingwhen it queries > > the db there are some fields that have a NULL value, thus when it > > writes the XML file it does this: > > > > Yep. > > > What I would like to do is either place an in the > XML tags for > > all of these NULL fields - can I do an if / else statement > in the code > > I am using below?? > > Yep. But look at the point where you have placed your pseudo-if/else > statement. Read through this script as though you were the PHP > processor -- what would happen? Well, you'd open the file for > appending, you'd write your XML declaration and stylesheet PI, you'd > write a few element names, and then you'd write a name pulled > from your > database. Fine, everything looks good up to this point... (continued > below) > > > $phone_list = fopen("/usr/local/apache2/htdocs/test/phone_list.xml", > > "w+"); > > > > fwrite($phone_list, " > encoding=\"ISO-8859-1\"?>\n"); > > fwrite($phone_list, " > href=\"phone_list.xsl\"?>\n\n"); > > > > fwrite($phone_list, "\n"); > > fwrite($phone_list, "\t\n"); > > > > while ($row = mysql_fetch_array($sql_result)) > > { > > $name = $row["name"]; > > $ext = $row["ext"]; > > $title = $row["title"]; > > $home = $row["home"]; > > $pager = $row["pager"]; > > $cell = $row["cell"]; > > $email = $row["email"]; > > > > fwrite($phone_list, "\t\t\n"); > > fwrite($phone_list, "\t\t\t"); > > fwrite($phone_list, "$name"); > > fwrite($phone_list, "\n"); > > Here is where you're going to run into a problem. Take a > close look at > what would happen if there is an $ext, and what would happen > if there is > no $ext (in other words, simulate the if/else statement in your mind): > > > fwrite($phone_list, "\t\t\t"); > > // would need an if / else statement here > > fwrite($phone_list, "$ext"); > > // end if / else statement here > > fwrite($phone_list, "\n"); > > See what's wrong? Regardless of whether or not there is an if/else > statement, you are still going to do the following two lines of code: > > fwrite($phone_list, "\t\t\t"); > > fwrite($phone_list, "\n"); > > Because your if/else statement does not encompass these lines. What > will the effect of this be? I'll show you: > > if there is an $ext > 123 > if there is no $ext > > > So, even if you use the pseudo if/else statement, you will > still end up > with a possibly empty element. If you changed your if/else > statement to encompass this entire section of the code, however, then > you can write 123 if there is an $ext variable or you can > have nothing happen if there is no $ext. Here is what it would look > like in pseudocode: > > // would need an if / else statement here > fwrite($phone_list, "\t\t\t"); > fwrite($phone_list, "$ext"); > fwrite($phone_list, "\n"); > // end if / else statement here > > Does that make sense? This way, if there's no $ext variable, > you don't > end up writing the and element tags. So how do you > construct the actual statement? Well, to be honest wi
Re: [PHP] RE: PHP/MySQL/XML
On Monday, April 1, 2002, at 05:09 PM, Jay Fitzgerald wrote: > OkThanks to all those who are helping me (sorry for > cross-posting)... That's okay. This script looks a lot better -- because you can actually -do- something with the output! :) > My scripts are working great except for one thingwhen it queries > the db there are some fields that have a NULL value, thus when it > writes the XML file it does this: > Yep. > What I would like to do is either place an in the XML tags for > all of these NULL fields - can I do an if / else statement in the code > I am using below?? Yep. But look at the point where you have placed your pseudo-if/else statement. Read through this script as though you were the PHP processor -- what would happen? Well, you'd open the file for appending, you'd write your XML declaration and stylesheet PI, you'd write a few element names, and then you'd write a name pulled from your database. Fine, everything looks good up to this point... (continued below) > $phone_list = fopen("/usr/local/apache2/htdocs/test/phone_list.xml", > "w+"); > > fwrite($phone_list, " encoding=\"ISO-8859-1\"?>\n"); > fwrite($phone_list, " href=\"phone_list.xsl\"?>\n\n"); > > fwrite($phone_list, "\n"); > fwrite($phone_list, "\t\n"); > > while ($row = mysql_fetch_array($sql_result)) > { > $name = $row["name"]; > $ext = $row["ext"]; > $title = $row["title"]; > $home = $row["home"]; > $pager = $row["pager"]; > $cell = $row["cell"]; > $email = $row["email"]; > > fwrite($phone_list, "\t\t\n"); > fwrite($phone_list, "\t\t\t"); > fwrite($phone_list, "$name"); > fwrite($phone_list, "\n"); Here is where you're going to run into a problem. Take a close look at what would happen if there is an $ext, and what would happen if there is no $ext (in other words, simulate the if/else statement in your mind): > fwrite($phone_list, "\t\t\t"); > // would need an if / else statement here > fwrite($phone_list, "$ext"); > // end if / else statement here > fwrite($phone_list, "\n"); See what's wrong? Regardless of whether or not there is an if/else statement, you are still going to do the following two lines of code: fwrite($phone_list, "\t\t\t"); fwrite($phone_list, "\n"); Because your if/else statement does not encompass these lines. What will the effect of this be? I'll show you: if there is an $ext 123 if there is no $ext So, even if you use the pseudo if/else statement, you will still end up with a possibly empty element. If you changed your if/else statement to encompass this entire section of the code, however, then you can write 123 if there is an $ext variable or you can have nothing happen if there is no $ext. Here is what it would look like in pseudocode: // would need an if / else statement here fwrite($phone_list, "\t\t\t"); fwrite($phone_list, "$ext"); fwrite($phone_list, "\n"); // end if / else statement here Does that make sense? This way, if there's no $ext variable, you don't end up writing the and element tags. So how do you construct the actual statement? Well, to be honest with you, I don't think you want to use an if/else statement at all -- a simple if statement will do the trick. It works just like this: if (!empty($ext)) { fwrite($phone_list, "\t\t\t"); fwrite($phone_list, "$ext"); fwrite($phone_list, "\n"); } The empty() "function" (actually a language construct, but the difference isn't important) tests to see if there is actually any value attached to the $ext variable. And the exclamation point inverts the boolean value of the expression, meaning "if this is NOT true". So the if statement above simply says "if the value held by $ext is not empty, write three tabs + + $ext + to the file pointed to by $phone_list." The rest of your code looks good (closing the element tags and the file pointer). HTH, Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: PHP/MySQL/XML
OkThanks to all those who are helping me (sorry for cross-posting)... My scripts are working great except for one thingwhen it queries the db there are some fields that have a NULL value, thus when it writes the XML file it does this: What I would like to do is either place an in the XML tags for all of these NULL fields - can I do an if / else statement in the code I am using below?? $phone_list = fopen("/usr/local/apache2/htdocs/test/phone_list.xml", "w+"); fwrite($phone_list, "\n"); fwrite($phone_list, "\n\n"); fwrite($phone_list, "\n"); fwrite($phone_list, "\t\n"); while ($row = mysql_fetch_array($sql_result)) { $name = $row["name"]; $ext = $row["ext"]; $title = $row["title"]; $home = $row["home"]; $pager = $row["pager"]; $cell = $row["cell"]; $email = $row["email"]; fwrite($phone_list, "\t\t\n"); fwrite($phone_list, "\t\t\t"); fwrite($phone_list, "$name"); fwrite($phone_list, "\n"); fwrite($phone_list, "\t\t\t"); // would need an if / else statement here fwrite($phone_list, "$ext"); // end if / else statement here fwrite($phone_list, "\n"); } fwrite($phone_list, "\t\n"); fwrite($phone_list, ""); fclose($phone_list); ?> Should you have any questions, comments or concerns, feel free to call me at 318-338-2034. Thank you for your time, Jay Fitzgerald, Design Director - CSBW-A, CPW-A, CWD-A, CEMS-A == Bayou Internet..(888) 30-BAYOUhttp://www.bayou.com Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net Vicksburg Online..(800) MISSISSIPPIhttp://www.vicksburg.com == Tel: (318) 338-2034ICQ: 38823829 Fax: (318) 323-5053 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php