Solved

Printing PHP value on page

Posted on 2013-01-25
5
221 Views
Last Modified: 2013-01-25
Hi all,

This is simple question but I think using the PHPfox it might be causing some issues.

I am using this SQL statement to get a value (it will be either no value or 1 value) from the DB:

	$query = mysql_query("SELECT question FROM cometchat_question WHERE userid = '$username' ");

Open in new window


I want to print this on a form on the page. How do I do this?

Thanks,

D
0
Comment
Question by:TLN_CANADA
  • 3
  • 2
5 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38821011
$query in that statement will only be a resource identifier, not the data you are looking for.  You still need to use mysql_fetch_array() or one of the other methods to get the actual data, even if it is only one item.  http://us2.php.net/manual/en/function.mysql-fetch-array.php
0
 

Author Comment

by:TLN_CANADA
ID: 38821026
Here is what I have but it's giving an error:

$query = mysql_query("SELECT question FROM cometchat_question WHERE userid = '$username' ");
	$row = mysql_fetch_array($query)
	echo $row ;

Open in new window


Parse error: syntax error, unexpected T_ECHO in /home/clear555/public_html/dyadmenu.php on line 48
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38821050
You need a semi-colon ';' at the end of the second line.  Like...
$row = mysql_fetch_array($query);

Open in new window

0
 

Author Comment

by:TLN_CANADA
ID: 38821075
Thanks, it's strange when I run the sql statement in the db it returns the result correct but when I print the array like this on the page it comes up blank. The username prints correct so it is connecting to the DB.

It would be a varchar format the question field that I am trying to fetch.

In this case the correct result from the db would be "Hello World"

$username = Phpfox::getUserBy('user_id'); 
	echo $username ;
	
	// Check for question
	$query = mysql_query("SELECT question FROM cometchat_question WHERE userid = '$username' ");
	$row = mysql_fetch_array($query) ;
	echo $row ;

Open in new window

0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 38821173
$row is an array in this case.  Your last line needs to be:
echo $row['question'];

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now