show(print) value from the database

Security issues related to php and mysql usage. How to make your code secure? Security measures and configurations? It's all in here!

Moderators: macek, egami, gesf

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

show(print) value from the database

Postby gesf » Sat Feb 08, 2003 12:12 pm

Hi
Can anyone tell how can i show(print) a value from my db?
my field is int(10) and and using this code to show what is inside:

$test = mysql_query("SELECT myfield FROM mytable WHERE id = '1'");
echo "$test";

But it show '4' and not the value that is in that field.

I wanna know too, how can i show a value from the db with this format: 12.34567, using this code:
$test = number_format($test, 'something');

thanks

Mixamajic
New php-forum User
New php-forum User
Posts: 9
Joined: Sun Feb 02, 2003 6:54 pm
Location: Milwaukee
Contact:

You have the right idea

Postby Mixamajic » Tue Feb 11, 2003 5:45 am

Code: Select all

$test = mysql_query("SELECT myfield FROM mytable WHERE id = 1");
$row=mysql_fetch_array($test);

echo $row["NameofIntField"]; //Leave the quotes in when you substitute the name of your DB field.



The 4 you are getting I think is a result resource. There are a couple other ways to do what you need, but this is the most flexible in my opinion.

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Tue Feb 11, 2003 1:09 pm

Thanks a lot Mixamajic.


Return to “PHP & MySQL Security”

Who is online

Users browsing this forum: Bing [Bot] and 0 guests