Akenatehm Posted November 23, 2008 Share Posted November 23, 2008 Hey Guys, I need a bit of help with tweaking this script: <?PHP $link = mysql_connect("localhost","username","password"); mysql_select_db("kaurlcom_messenger"); $query = 'SELECT * FROM users'; $results = mysql_query ($query); echo "<?xml version=\"1.0\"?>\n"; echo "<users>\n"; while ($line = mysql_fetch_assoc($results)) { echo "<username>" . $line["username"] . "</username>\n"; } echo "</users>\n"; mysql_close($link); ?> I currently get the following output: test, test2 and test3 (the current username rows in the mysql database) I want it to produce the following output in this format: <?xml version="1.0" encoding="utf-8"?> <users> <test> <id> 1 </id> <name> test </name> <password> test </password> <email> [email protected] </email> <picture> <img src="http://url.url"> </picture> </test> <test2> <id> 2 </id> <name> test2 </name> <password> test2 </password> <email> [email protected] </email> <picture> <img src="http://url.url"> </picture> </test2> </users> Any help with this would be extremely helpful. Thanks in Advanced Akenatehm Link to comment https://forums.phpfreaks.com/topic/133842-help-tweaking-a-php-script/ Share on other sites More sharing options...
redarrow Posted November 23, 2008 Share Posted November 23, 2008 u get the drift good luck ....... <?php $link = mysql_connect("localhost","username","password"); mysql_select_db("kaurlcom_messenger",$link); $query ="SELECT * FROM users"; $results = mysql_query($query)or die(mysql_error()); echo "<?xml version=\"1.0\"?>\n"; echo "<users>\n"; while($rec=mysql_fetch_assoc($results)) { echo" <test> <id> ".$rec['id']." </id> <name> ".$rec['name']." </name> <password> ".$rec['password']." </password> <email> ".$rec['email']." </email> <picture> <img src='http://".$rec['url']."'> </picture> </test> } echo "</users>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/133842-help-tweaking-a-php-script/#findComment-696889 Share on other sites More sharing options...
redarrow Posted November 23, 2008 Share Posted November 23, 2008 tried agin lol WHY DOES THE CODE SHOW NON HIGHTLIGHTED SYNTEX GRRRRRRRRRR <?php $link = mysql_connect("localhost","username","password"); mysql_select_db("kaurlcom_messenger",$link); $query ="SELECT * FROM users"; $results = mysql_query($query)or die(mysql_error()); echo "<?xml version=\"\1.0\"?>\n"; echo "<users>\n"; while($rec=mysql_fetch_assoc($results)) { echo" <test> <id> ".$rec['id']." </id> <name> ".$rec['name']." </name> <password> ".$rec['password']." </password> <email> ".$rec['email']." </email> <picture> <img src='http://".$rec['url']."'> </picture> </test>"; } echo "</users>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/133842-help-tweaking-a-php-script/#findComment-696891 Share on other sites More sharing options...
revraz Posted November 23, 2008 Share Posted November 23, 2008 Probably because it sees the ?> after the xml and thinks the php code tag has ended. Link to comment https://forums.phpfreaks.com/topic/133842-help-tweaking-a-php-script/#findComment-697018 Share on other sites More sharing options...
flyhoney Posted November 23, 2008 Share Posted November 23, 2008 <?php $link = mysql_connect("localhost","username","password"); mysql_select_db("kaurlcom_messenger",$link); $query ="SELECT * FROM users"; $results = mysql_query($query)or die(mysql_error()); ?> <?xml version="1.0"?> <users> <?php while($rec=mysql_fetch_assoc($results)): ?> <test> <id><?php echo $rec['id'] ?></id> <name><?php echo $rec['name'] ?></name> <password><?php echo $rec['password'] ?></password> <email><?php echo $rec['email'] ?></email> <picture><img src="http://<?php echo $rec['url'] ?>"> </picture> </test> <?php endwhile; ?> </users> Link to comment https://forums.phpfreaks.com/topic/133842-help-tweaking-a-php-script/#findComment-697021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.