Esato Mobile
General discussions : Non mobile discussion : MySQL and RSS help
> New Topic
> Reply
< Esato Forum Index > General discussions > Non mobile discussion > MySQL and RSS help Bookmark topic
Page12>

Jim Posts: > 500

Hi all,

I need some help from experienced webmasters on mysql, I try to create a rss feed based on a mysql table but I suck in mysql. Here is the code

Code:
header("Content-Type: text/xml;charset=utf-8");

include('conf/db.php');

if (!$db)
{
error_log("Error: Could not connect to database in rss.php.");
exit;
}

mysql_select_db("mydatabase");

$query1 = ("select * from annuaire_sites where valid='1' limit 10");
$result1 = mysql_query($query1);

echo <<<END
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>My title</title>
<link>My link</link>
<description>My description</description>
<language>en-us</language>
<docs>My doc</docs>
<generator>My generator</generator>
END;

$row = mysql_fetch_array($result1);
$title = $row["nomsite"];
$link = $row["url"];
$description = $row["description"];

echo <<<END

<item>
<title>$title</title>
<description>$description</description>
<link>$link</link>
</item>
END;


echo <<<END

</channel>
</rss>
END;

?>

Nothing shows up, only <html><body/></html> which makes no sence at all. I guess that my sql coding is bad and that it can't get the results.

Can anybody please help me ? I don't wanna ask to those php/mysql guru sites cause they will have explanation that I don't understand.

Many thanks
_________________
K700 - T610 themes site

[ This Message was edited by: Jim on 2005-03-31 23:27 ]
--
Posted: 2005-04-01 00:26:00
Edit : Quote

Krubach Posts: > 500

First, try the SQL command directly in MySQL.
See what's the result recordset.
If it's empty, there's a problem in the query.
If not, there's a problem binding the recordset columns to the variables.
--
Posted: 2005-04-01 01:44:19
Edit : Quote

Cycovision Posts: > 500

Usually when you assign a database query to a variable in PHP, you don't put the MySQL query in brackets, so:

$query1 = ("select * from annuaire_sites where valid='1' limit 10");

Should be:

$query1 = "SELECT * FROM annuaire_sites WHERE valid='1' limit 10";

Note the capitalisation, it's not strictly necessary but it is the standard way of writing MySQL queries so it's probably best to user it.

Not sure if that'll solve all of the problem but it'll hopefully get the script a bit further
--
Posted: 2005-04-01 10:01:45
Edit : Quote

Jim Posts: > 500

Hi and many thanks, the query is correct as the sql gives me results but it seems that I can't call the values from my php file, I'm lost.

Btw I searched on the mysql manual but I can't find how to return the last 10 results and not the first 10
--
Posted: 2005-04-01 11:54:24
Edit : Quote

Krubach Posts: > 500

Sort them the other way around and get the first ten...
--
Posted: 2005-04-01 12:33:03
Edit : Quote

Jim Posts: > 500

Good idea
--
Posted: 2005-04-01 12:43:18
Edit : Quote

Krubach Posts: > 500

Have you tried what Cyco proposed?

[EDIT]

I'm not much into PHP programming, but in all other languages it goes like this:
- You fetch the recordset
- You position in the 1st row
- You cycle through all rows until you get to the end.

I can't see point's 1 & 2 in your code.

(but maybe i'm wrong)

_________________
Stop looking at me. I don't like people looking at me like that.

[ This Message was edited by: Krubach on 2005-04-01 12:05 ]
--
Posted: 2005-04-01 13:02:08
Edit : Quote

Jim Posts: > 500

Yeah it's the same, for point 1 and 2 it's the $query and $row no ?
--
Posted: 2005-04-01 13:16:51
Edit : Quote

Jim Posts: > 500

Well I found it out, was really simple actually but didn't pay attention where I should

The rss feed works with my mysql database.

Thanks again guys
--
Posted: 2005-04-06 15:05:58
Edit : Quote

Krubach Posts: > 500

So, what was it?
--
Posted: 2005-04-07 02:37:32
Edit : Quote
Page12>

New Topic   Reply
Forum Index

Esato home