LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-04-2007, 07:47 AM   #1
ChrisScott
Member
 
Registered: Nov 2006
Location: St Albans, England
Distribution: Fedora c3/5, Suse pro 10/openSuse 10.2, RHES, Zenwalk.....
Posts: 97

Rep: Reputation: 15
php: echo command behaviour


Hi All,

I've just started trying to teach myself php. I've come across a problem where 'echo' does not seem to stop at the semi-colon i.e.

Code:
                <?php
		
		$username="root";
		$password="*********";
		$database="testdb";

                mysql_connect(pandaemonium,$username,$password);
		@mysql_select_db($database) or die( "Unable to select database");

		$query = "SELECT title FROM page WHERE ref = 1";
		$result = mysql_query($query);

		mysql_close();
		
		echo "<h2>$result</h2>";
		?>
is displayed in the browser as:
"$result"; ?>"

The predeclared css for h2 does not appear to have any effect on it. Do I need a '?php h2:' css entry?

Also, If I view source in firefox it shows the full php - including my MySQL password - I was not expecting that. Has the php been executed at all?

In MySQL the query correctly returns a string. This is what I want displayed.

Any tips would be appreciated.

Thanks,

Chris.

Last edited by ChrisScott; 08-04-2007 at 07:48 AM.
 
Old 08-04-2007, 12:30 PM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 112Reputation: 112
$result is what php calls a resource. I don't know the internal details of this resource because I have never attempted to actually look at it.

It would appear though that echo is bombing on the content of this resource.

You are supposed to pass the resource to one of the php commands that processes it, such as mysql_fetch_array, or mysql_fetch_row, or one of the others. You can then print the results of the fetch. Visit php.net to learn more.
 
Old 08-04-2007, 07:28 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
You can also think of it as a ptr or handle if that helps.
Basically, it's just an address, not the actual (data) value.
HTH
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
echo command s_hcl Linux - General 1 09-06-2006 05:27 AM
echo current user with PHP genderbender Programming 1 05-10-2006 06:03 PM
echo does not work in php code suchi_s Programming 3 10-21-2004 03:39 AM
using 'echo' in a system statment in php evilchild Programming 3 09-23-2004 02:27 PM
behaviour of echo with ? (the question mark) in gnome-terminal fsbooks Programming 1 01-08-2004 12:41 PM


All times are GMT -5. The time now is 06:43 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration