Jump to content

Help Tweaking a PHP Script


Akenatehm

Recommended Posts

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

 

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";


?>

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";


?>

<?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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.