开发者

Retrieving text from a mysql database

开发者 https://www.devze.com 2023-01-22 15:49 出处:网络
I am sure this is a stupid question but I can\'t figure out how to do it.I need t开发者_如何学JAVAo retrieve a large block of text that is stored in a database.I know how to connect to the database an

I am sure this is a stupid question but I can't figure out how to do it. I need t开发者_如何学JAVAo 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());


Using mysql_fetch_array()

  while( $row = mysql_fetch_array($result) ){
    $meaning = $row["meaning"];
    echo $meaning;
    }


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


<?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'];
    }
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消