Question

mysql to print php output file

Asked by: peter2001

Hi
i have a rss feed that i want to output like this in a php file so when i go to the say video.php
it will print this in the browser (without the commented bits)





<ratings>
<video file="www.mysite/vids/11.flv">                                       // i'll add this manually for now in the php file
<title>funny Commercials - Ikea - </title>                                   // $description = $results['description'];
<runtime>00:30</runtime>                                                   // i'll add this manually for now
<author>silent</author>                                                           // .$results[username].
<rating>5</rating>                                                                 // I'll add maually for now in the php file
<views>20</views>                                                                   // i'll add this manually for now in the php file
<key>aa6e02c990b0a82652dc</key>                                        // .$results['vkey'];
<link>testtest</link>       //  $video      =$config['BASE_URL']."/view_video.php?viewkey=".$results['vkey'];
</video>
<video file="10.flv">
<title>funny Commercials - Ikea - Balls</title>
<runtime>00:32</runtime>
<author>test</author>
<rating>5</rating>
<views>22</views>
<key>44259755d38e6d163e82</key>
<link>testtest</link>
</ratings>








I have been tring for sometime and having no look in making it work
below is the rss.php i am tring to convert to make it print out like above most of the info i need is there i'll add the bit maually till i find the
right tables for the other info

could someone help me try and make a sample if only to make the php print out the author and the title just as a guide to get me going




<?php

include("include/dbconfig.php");
include("include/config.php");

if ($_GET[type] == "new")
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.VID desc LIMIT 10";
  $titel = "[20 Newest videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."";
}
elseif ($_GET[type] == "views")
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.viewnumber desc LIMIT 10";
  $titel = "[20 Most Viewed videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."";
}
elseif ($_GET[type] == "comments")
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.com_num desc LIMIT 10";
  $titel = "[20 Most Commented videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."";
}

else
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.VID desc LIMIT 20";
  $titel = "[20 Newest videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."";
}


header("Content-Type: text/xml");
header("Expires: 0");
print "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
print "<!DOCTYPE rss >\n";
print "<rss version=\"2.0\" xmlns:prc=\"http://purl.org/dc/elements/1.1\">\n";
print "<channel>\n";
print "<title>".$config['site_name']."</title>\n";
print "<link>".$url."</link>\n";
print "<description>".$titel."</description>\n";
print "<copyright>Copyright (c) 2006-2007 by ".$config['site_name']." - All rights reserved.</copyright>\n";
print "<image>\n";
print "<url>".$config['BASE_URL']."/images/11.jpg</url>\n";
print "<title>".$config['site_name']."</title>\n";
print "<link>".$config['BASE_URL']."</link>\n";
print "</image>\n";
 
$db=mysql_connect ($DBHOST,$DBUSER,$DBPASSWORD) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($DBNAME);
 
$num_rows = mysql_num_rows(mysql_query("select * from media"));
 
$result = mysql_query($query) or die ('Query Error: ' . mysql_error());
while ($results = mysql_fetch_array($result))
{
  $photo       = $config['BASE_URL']."/thumb/1_".$results['VID'].".jpg";
  $video       = $config['BASE_URL']."/view_video.php?viewkey=".$results['vkey'];
  $description = $results['description'];
  $description = str_replace ("&amp","",htmlspecialchars(stripslashes($description)));
  $photo       = str_replace ("&amp","&amp",htmlspecialchars(stripslashes($photo)));


print "<item>\n";

print "  <title>".$results['title']."</title>\n";

print "  <description>\n";

print "    <![CDATA[";

print "<img src=\"$photo\" align=\"right\" border=\"0\" width=\"174\" height=\"130\" vspace=\"4\" hspace=\"4\" />

 

       

".$description."</p>

".$key."</p>

       

Added by: <a href=\"$config[BASE_URL]/uprofile.php?UID=".$results[UID]."\">".$results[username]."</a>
 

       Tags: ";



  $tok = strtok($results[keyword], " ");

  while ($tok !== false)

  {

    print "<a href=\"$config[BASE_URL]/search_result.php?search_id=".$tok."\">".$tok."</a> ";

    $tok = strtok(" ");

  }

print "
Date: ".$results[adddate]."
</p>
<hr>";

print "    ]]>\n";



print "  </description>\n";


print "</item>\n";





}

mysql_close();

print "</channel>";

print "</rss>";

?>


regards

pete

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-02-21 at 03:16:34ID22403092
Tags

php

,

cdata

,

feed

,

print

Topic

PHP and Databases

Participating Experts
2
Points
0
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. XML (RSS feed) from MySQL data
    Dear people, I have some information in a MySQL table and I want to build a XML file with it in order to make a RSS feed. Funny me, I though I could use my PHP knowledge and do it easily. The code below is what I have done so far. If you go through it, you'll find th...
  2. RSS Feeds
    Hey guys, I want to put some RSS feeds onto my website and don't really know where to start. I have found that i can either do it JS or PHP but PHP is better as spiders can crawl it. So - I downloaded rss2html.php and the RSS feed I want to get information from is : htt...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: davebytesPosted on 2007-02-21 at 10:29:46ID: 18580740

Can you be clearer as to what is/isn't working?  What's it doing right now?

 

by: peter2001Posted on 2007-02-21 at 15:12:28ID: 18583145

hi yeah reading back on my post i see what you mean not very clear


well all i really want to do is be able to pull some info from the a mysql database and output it in a
php file or even a xml file

so it reads like this

<ratings>
<video file="11.flv">
<title>The title of my video</title>
<runtime>00:30</runtime>
<author>pete</author>
<rating>5</rating>
<views>20</views>
<key>aa6e02c990b0a82652dc</key>
<link>www.somesite.com</link>
</video>
</ratings>


so in the php file the info for the link would be
 $video  =$config['BASE_URL']."/view_video.php?viewkey=".$results['vkey'];

and that would put the link in the link tags

hope you understand what i mean

thanks
pete


 

by: davebytesPosted on 2007-02-21 at 16:25:40ID: 18583483

Ummm... that still didn't say what works and what doesn't.  And the original code is a mess.  But I'll take a quick shot at it.

Towards the end, you'll see:

print "  </description>\n";

AFTER that line, try adding:

print "  <link>\n";
print $video;
print "  </link>\n";

As an example.  You can easily add other fields, or wrap the whole thing in <ratings>, or wrap each item in <video> or something, if you want a custom format.  Obviously, the main code there is trying to output an RSS feed, so I'm not sure if you want an RSS feed, or a completely custom format that isn't a feed.

-d

 

by: peter2001Posted on 2007-02-22 at 02:21:10ID: 18586162

hi
the code works fine for the rss feed
i just thought it might help show how i was getting the info from the database


right it does not need to be a xml or a rss feed

i tried what you said and yes it will print out the video link but i need to actually see when i look at the page it formated like the example in my last post at the minute  it just prints out the link

ie

http://www.mysite.com/home/view_video.php?viewkey=d5072bb1864cdee4d3d6

but when i look at the page i need to see

<link>http://www.mysite.com/home/view_video.php?viewkey=d5072bb1864cdee4d3d6</link>


if i look at the source to the page i can see it says that but i need it to be visible when its viewed with a browser

thanks

pete

 

by: peter2001Posted on 2007-02-22 at 02:33:38ID: 18586236

this  was the code i used to make it print out the link

<?php


include("include/dbconfig.php");
include("include/config.php");


if ($_GET[type] == "new")
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.VID desc LIMIT 10";
  $titel = "[20 Newest videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."";
}


else
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.VID desc LIMIT 20";
  $titel = "[20 Newest videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."";
}

 
$db=mysql_connect ($DBHOST,$DBUSER,$DBPASSWORD) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($DBNAME);
 
$num_rows = mysql_num_rows(mysql_query("select * from media"));
 
$result = mysql_query($query) or die ('Query Error: ' . mysql_error());
while ($results = mysql_fetch_array($result))
{
  $photo       = $config['BASE_URL']."/thumb/1_".$results['VID'].".jpg";
  $video       = $config['BASE_URL']."/view_video.php?viewkey=".$results['vkey'];
  $description = $results['description'];
  $description = str_replace ("&amp","",htmlspecialchars(stripslashes($description)));
  $photo       = str_replace ("&amp","&amp",htmlspecialchars(stripslashes($photo)));



print "<link>\n";
print $video;
print "</link>\n";



}

mysql_close();



?>

 

by: peter2001Posted on 2007-02-22 at 11:03:40ID: 18590392

hi

ok i have come up with another way of doing it so it writes the information to a xml file
which works fine but only prints the first results instead of the first 20

how would i change this so it writes the first 20 results to the xml file and not just one


<?php

//include("include/dbconfig.php");
include("include/config.php");

if ($_GET[type] == "new")
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.VID desc LIMIT 10";
  $titel = "[20 Newest videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."/rss/new/";
}
elseif ($_GET[type] == "views")
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.viewnumber desc LIMIT 10";
  $titel = "[20 Most Viewed videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."/rss/views/";
}
elseif ($_GET[type] == "comments")
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.com_num desc LIMIT 10";
  $titel = "[20 Most Commented videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."/rss/comments/";
}

else
{
  $query = "SELECT A.*,B.UID,B.username FROM media A, signup B WHERE A.UID=B.UID AND A.type = 'public' ORDER BY A.VID desc LIMIT 20";
  $titel = "[20 Newest videos on ".$config['site_name']."]";
  $url   = $config['BASE_URL']."/rss/new/";
}



$db=mysql_connect ($DBHOST,$DBUSER,$DBPASSWORD) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($DBNAME);
 
$num_rows = mysql_num_rows(mysql_query("select * from media"));
 
$result = mysql_query($query) or die ('Query Error: ' . mysql_error());
while ($results = mysql_fetch_array($result))
{

  $photo       = $config['BASE_URL']."/thumb/1_".$results['VID'].".jpg";
  $video       = $config['BASE_URL']."/view_video.php?viewkey=".$results['vkey'];
  $Key         = $results['vkey'];
  $description = $results['description'];
  $description = str_replace ("&amp","",htmlspecialchars(stripslashes($description)));
  $photo       = str_replace ("&amp","&amp",htmlspecialchars(stripslashes($photo)));
  $filename1   = "file1";
  $Runtime     = "00.30";
  $videofile   = "<video file='11.flv'>";
  $author      = $results['username'];      
  $rating      = "4";
  $views       = "2";
  $xmlfileName = $filename1;
  $Title1      = $description;
  $key1        = $Key;
  $xml_dec     = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";


        $rootELementStart = "<ratings>";
        $rootElementEnd = "</ratings>";

        $xml_doc=    $xml_dec;

        $xml_doc .=  $rootELementStart;
      
      $xml_doc .=  "$videofile";
      
        $xml_doc .=  "<title>";
        $xml_doc .=  $Title1;
        $xml_doc .=  "</title>";

      $xml_doc .=  "<runtime>";
      $xml_doc .=   $Runtime;      
      $xml_doc .=  "</runtime>";

      $xml_doc .=  "<author>";
      $xml_doc .=   $author;
      $xml_doc .=  "</author>";

      $xml_doc .=  "<rating>";
      $xml_doc .=   $rating;
      $xml_doc .=  "</rating>";

      $xml_doc .=  "<views>";
      $xml_doc .=  $views;
      $xml_doc .=  "</views>";

        $xml_doc .=  "<key>";
        $xml_doc .=  $key1;
        $xml_doc .=  "</key>";      

        $xml_doc .=  "</video>";
      

        $xml_doc .=  $rootElementEnd;

        $default_dir1 = "xml_files/";

        $default_dir1 .= $xmlfileName .".xml";


}
mysql_close();

$fp = fopen($default_dir1,'w');

            $write = fwrite($fp,$xml_doc);



?>

regards

pete

 

by: peter2001Posted on 2007-02-25 at 16:51:11ID: 18606733

admin could you refund my points please as i have just about sorted it

thanks

and you can close question

 

by: Vee_ModPosted on 2007-08-13 at 04:13:15ID: 19682805

Closed, 500 points refunded.
Vee_Mod
Community Support Moderator

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...