0

I am sure this is a stupid question but I can't figure out how to do it. I need to retrieve a large block of text that is stored in a database. I know how to connect to the database and submit the sql query. What I can't figure out how to do is have it store that text in a string so I can have it echo later on the page.

What I have so far

$db_name = "j_db";
$table_name = "contacts";
$connection = @mysql_connect("localhost", "*****", "****") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());

$sql = "SELECT meaning 
          FROM $table_name 
         WHERE card = (php variable here)";

$result = @mysql_query($sql, $connection) or die(mysql_error());
1
  • 5
    Be careful not need show id and password on your posts. :D Commented Nov 1, 2010 at 3:36

3 Answers 3

3

Using mysql_fetch_array()

  while( $row = mysql_fetch_array($result) ){
    $meaning = $row["meaning"];
    echo $meaning;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

I suggest that, for posterity, this answer be updated to reference php.net/manual/en/book.mysqli.php rather than the mySQL extension
0

Look at the mysql_fetch_* functions. mysql_fetch_assoc is a popular choice.

Comments

0
<?php
    $url= '' ;
    $username = '' ;
    $password = '' ;
    $dbname = '' ;

    $connection = mysql_connect('$url' , '$username', '$password');
                  mysql_select_db('$dbname' , $connection);
    $result = mysql_query("SELECT textColumnName FROM tableName", $connection);

    while($row = mysql_fetch_array($result)){
         echo $row['textColumnName'];
    }
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.