On Mon, 1 Apr 2002, Jay Fitzgerald wrote:

> I have created a database called friends with four columns:
> Name / Address / City / State
> 
> I also made an XML file to coincide with those variables:
> <test>
>          <contacts>
>                  <friends>
>                          <name>Friend 1</name>
>                          <address>999 Foo Avenue</address>
>                          <city>Foo Town</city>
>                          <state>FO</state>
>                  </friends>
>          </contacts>
> </test>
> 
> The variables in the XML doc above are already in the database
> 
> 
> BUT - what I want to do - using PHP and MySQL - is something like this:
> 
> $connection = mysql_connect("localhost", "foo", "bar") or die ("Could not 
> connect to server.");
> $db = mysql_select_db("friends") or die ("Could not select database.");
> $sql = "select * from friends order by name asc";
> $sql_result = mysql_query($sql, $connection) or die ("Could not execute 
> query.");
> 
> echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
> echo "<?xml-stylesheet type=\"text/xsl\" href=\"friends.xsl\"?>\n\n";
> 
> echo "<test>\n";
> echo "\t<contacts>\n";
> echo "\t\t<friends>\n";
> 
> echo "\t\t\t<name>";
> echo "$name";
<SNIP>
> Can this be done and am I going about it the right way?

It's not clear what would be right in your case because you don't state what you'd 
like the code to do for you. But anyway, the extraction from the DB is not complete 
(neep more PHP code after you get the result handler). From the way that you have your 
SQL query, it seems that you have a table with columns name/address/city/state. If XML 
is not your only output format, then that's OK. But if this data will see the light of 
day only as XML, then you might as well store it as plain text in a single field. Of 
couse you won't be able to order by the name on the SQL side this way :-) But you can 
parse the entries on the PHP side after you retrieve them and then sort them.

Just my 2c.

cheers,
--thalis


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to