Brandrally
Brandrally

Reputation: 849

PHP to Array - Troubleshooting

I know I am making rookie errors here, and that I need to make a variable to pass forward - though I am not sure how to approach this one, and searching online tutes is not helping. If someone can steer me in the right direction I would be really grateful.

I would like to have the results echo into an array. That is; have 'xmlurl' row field from the 'xml' table display in the $rss array. I hope that makes sense.

// Get URLs from Database
$result = mysql_query("SELECT * FROM xml");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("'%s',", $row["xmlurl"]);
}
mysql_free_result($result);

// Take the URLs (xmlurl) and place them in an array
$rss = array(
'http://www.xmlurl.com.au',
'http://www.xmlurl.com.au'
);

Upvotes: 0

Views: 69

Answers (3)

random_user_name
random_user_name

Reputation: 26170

// Get URLs from Database
$result = mysql_query("SELECT * FROM xml");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $rss[] = $row["xmlurl"]);
}
mysql_free_result($result);

print_r($rss); // Outputs the $rss array, listing all of the xmlurls'

Upvotes: 2

deceze
deceze

Reputation: 522382

$rss = array();
while (...) {
    $rss[] = $row['xmlurl'];
}

Upvotes: 7

Ian Hunter
Ian Hunter

Reputation: 9774

Try this:

$rss = array();

$result = mysql_query("SELECT * FROM xml");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $rss[] = $row["xmlurl"];
}
mysql_free_result($result);

Upvotes: 3

Related Questions