Dear all,
new to php, so here a very easy thing which, I couldn't do.
i want to select a column value from a table. for example: select name from members where member_id = 1; for this in pl/sql the code is look like: select name into v_name from members where member_id =1;
the column value will be stored in v_name variable, now please guide me how it can be done in php. I want to display user name on page.
Regards:
select a column value
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: select a column value
You are almost there :nadeem14375 wrote:for example: select name from members where member_id = 1;
Code: Select all
<?php
$query = "SELECT name FROM members WHERE member_id = '1' ";
$sql = mysql_query($query);
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
nadeem14375
- Forum Newbie
- Posts: 23
- Joined: Sat Oct 30, 2010 2:11 am
Re: select a column value
Example #1 mysql_result() example
the following example solved the problem. thanks for you response.
http://php.net/manual/en/function.mysql-result.php
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('database_name')) {
die('Could not select database: ' . mysql_error());
}
$result = mysql_query('SELECT name FROM work.employee');
if (!$result) {
die('Could not query:' . mysql_error());
}
echo mysql_result($result, 2); // outputs third employee's name
mysql_close($link);
?>
the following example solved the problem. thanks for you response.
http://php.net/manual/en/function.mysql-result.php
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('database_name')) {
die('Could not select database: ' . mysql_error());
}
$result = mysql_query('SELECT name FROM work.employee');
if (!$result) {
die('Could not query:' . mysql_error());
}
echo mysql_result($result, 2); // outputs third employee's name
mysql_close($link);
?>