Click here to Skip to main content
15,894,314 members

fetching data from backend, only single character and adding data

nischalinn asked:

Open original thread
SQL
create table test
(
	name varchar(20),
	gender varchar(20),
	salary varchar(20)
);

insert into test values ('nm1','male','20000');
insert into test values ('nm2','female','85000');
insert into test values ('nm3','male','1000');
insert into test values ('nm4','unknown',NULL);


I am new to PHP, just learning.

I've a sample data of my table. While showing data in front, for gender I've to show
only the first character i.e. m/f/u and for salary I've to sum the total amount from front i.e
by using PHP.

also in my table salary is in varchar would I've to parse it as number?

PHP
<pre lang="xml"><?php
        include('conn.php');
        $result =mysql_query("select * from test")
            or die(mysql_error());

        echo "<table cellpadding = '10'>";
        echo "<tr>
                <th>name:</th>
                <th>gender:</th>
                <th>total salary:</th>
            </tr>";

        while($row = mysql_fetch_array($result))
        {
            echo "<tr>";
            echo '<td>'.$row['name'].'</td>';
            echo '<td>'.$row['gender'].'</td>';
            echo '<td>'.$row['salary'].'</td>';
        }
    ?>
Tags: PHP

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900