FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


MySQL and PHP Question





GameFreak
Hi,

I'm a beginner at MySQL though I'm a bit advanced in PHP.

I had a question.

Say, supposing I had a couple of rows in a table called "test_table" in my database (which has one integerical field).

Now, I want to display double the amount of the integerical values. So, how do I do that?

Thanks
Rhysige
intergerical o_0
hexkid
GameFreak wrote:
I want to display double the amount of the integerical values. So, how do I do that?

You multiply the original value by 2
Code:
<?php
// ...

$double_value = $original_value * 2;
echo $double_value;
## or you could do it without the temporary variable
## echo $original_value * 2;

// ...
?>
Bejeweledhorses
if you use phpMyAdmin, just add "X" amount more of rows/columns to the table..........

with phpMyAdmin, it does things automatically so you dont have to write out the actual code....

did answer your question? Question

good luck! Wink
GameFreak
I know how to multiply it. I just don't know how to display it.

You know, how to make the value an integerical value. Please create a PHP Code of an entire web page showing the connections to the database, etc.

Thanks
hexkid
GameFreak wrote:
I know how to multiply it. I just don't know how to display it.


echo (and print()) works for me.
Would you please show some code?
GameFreak
I don't think you are understanding my problem.

I have a table in my database called "test_table".

It has two fields.

The first field is "test_var" and the second is "test_no".

The "test_no" field is what I am talking about.

I have 1 record in which the value of "test_no" is say "14". It is an INT datatype.

I want to display double of it("28")t on a page called "index.php". How do I do that? That's what I want to know.
hexkid
Code:
<?php
### ZEROTH STEP: Define constants used throughout the code
### Better if you place them in a separate file and
### require it
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_DATA', 'database');

### FIRST STEP: Connect to the database
$con = mysql_connect(DB_HOST, DB_USER, DB_PASS);
if (!$con) {
  exit('There was an error connecting to the database.<br>The error was: ' . mysql_error());
}
if (!mysql_select_db(DB_DATA)) die('There was an error selecting the database.<br>The error was: ' . mysql_error());

### SECOND STEP: Get data from the table
$sql = 'select test_no from test_table';
$res = mysql_query($sql);
if (!$res) {
  exit('There was a query error.<br>The error was: ' . mysql_error());
}
while ($row = mysql_fetch_row($res)) {
  ### THIRD STEP (inside the loop): print the data
  echo 'The double of the value is ', 2*$row[0], ".<br>\n";
}

### FOURTH STEP: release resources
mysql_free_result($res);

### FIFTH STEP: close the database
mysql_close($con);
?>
GameFreak
Thanks a lot.

I really appreciate it.

That's exactly what I needed.

This topic can be locked.
Related topics
Seeking MySQL-php-Apache installer for WinXP
mysql/php help please
a grouping question?
PHP MySQL Commands Question
PHP question
server with ready PHP
MySQL, PHP and APACHE
A quick PHP Question! You know the answer! Answer ASAP .
Mysql 101 question
[ Newbie; Makin pages, mySQL, PHP, etc ]
[ Newbie; Makin pages, mySQL, PHP, etc ]
Is mySQL/php in safe mode on Frihosting?
MySQL [php Mail()] and FriHost Mass mail rules
PHP question about passing variables (noob)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.