Jump to content

Recommended Posts

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:

 

 

Link to comment
https://forums.phpfreaks.com/topic/240189-select-a-column-value/
Share on other sites

<?php

// $connection should be populated correctly first

 

$sql="select name from members where member_id = 1";

$result=($sql,$connection);

if($result){

  $row=mysql_fetch_array($result);

}else{

  echo "no entry found";

  exit();

}

// now you can show the field 'name' from your table:

echo "Name: ".$row['name'].'<br/>';

?>

 

the following example solved the problem. thanks for you response.

Example #1 mysql_result() example

 

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);

?>

<?php

// $connection should be populated correctly first

 

$sql="select name from members where member_id = 1";

$result=($sql,$connection);

if($result){

  $row=mysql_fetch_array($result);

}else{

  echo "no entry found";

  exit();

}

// now you can show the field 'name' from your table:

echo "Name: ".$row['name'].'<br/>';

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.