How Do I Store Data From One Column Of One Row In A Var.?
Posted: Fri Apr 25, 2008 3:29 am
I am trying to display the contents of one specific row and column from a MySQL database. My table has two columns: 'DataName' and 'DataContent'. I would like to simply display the contents of column DataContent only where DataName equals a value.
This is what I have so far...the problem is that it displays both DataName and DataContent, I only want to display DataContent. I have tried just taking out the portion of the echo command that displays DataName, but I only get an error.
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test_db", $con);
// Get a specific result from the "data" table
$result = mysql_query("SELECT * FROM data
WHERE DataName='dyk1'") or die(mysql_error());
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table
echo $row['DataName']." - ".$row['DataContent'];
mysql_close($con);
?>
How can I display just one set of data from the column DataContent?
This is what I have so far...the problem is that it displays both DataName and DataContent, I only want to display DataContent. I have tried just taking out the portion of the echo command that displays DataName, but I only get an error.
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test_db", $con);
// Get a specific result from the "data" table
$result = mysql_query("SELECT * FROM data
WHERE DataName='dyk1'") or die(mysql_error());
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table
echo $row['DataName']." - ".$row['DataContent'];
mysql_close($con);
?>
How can I display just one set of data from the column DataContent?