echo() versus print() syntax

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
okelly
Forum Commoner
Posts: 29
Joined: Thu Feb 23, 2006 2:18 pm

echo() versus print() syntax

Post by okelly »

hello all

my articles database referred below has php code snippets which I want to retrieve using the mysql_query string and append to my code to complete.
Can somebody correct my incorrect echo command (or printf) on line8 below to achieve this.

thanks very much
Conor

Code: Select all

 
<?php
  require_once("../rss/rsslib.php");
   include ('../admin/config.php');
// fetch the code from articles table in articles db based on the ID
    $result = mysql_query("SELECT article.ArticleID, articles.snippet FROM articles WHERE ArticleID='2' ", $dblink);
//now add the retrieved code snippets to my php string to complete the php code
    echo $result,"snippet");
?>
        
 
 
 
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: echo() versus print() syntax

Post by jaoudestudios »

Code: Select all

 
// should be...
echo $result['snippet']";
 
How were you able to code the rest and not that line?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: echo() versus print() syntax

Post by Eran »

Only without the trailing double-quotes, and with mysql_fetch_assoc:

Code: Select all

 
// should be...
$row = mysql_fetch_assoc($result);
echo $row['snippet'];
 
Last edited by Eran on Sun Aug 03, 2008 5:45 am, edited 1 time in total.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: echo() versus print() syntax

Post by jaoudestudios »

oops, cheers, dont know where they came from :(
okelly
Forum Commoner
Posts: 29
Joined: Thu Feb 23, 2006 2:18 pm

Re: echo() versus print() syntax

Post by okelly »

thanks both. enjoy your Sunday morning!

jaoudestdio- to answer your question..I downloaded and ran it on an old Apache1, Php4 instance and am re-using the code for a new app. - this time on Apache2, Php5
Post Reply