0

I am fetching data from mysql to a page, i am not sure if the way im doing it is appropiate. I am having trouble with fetching values into sections of the page.

<?php
    // Connect to database server
    mysql_connect("localhost", "xxx", "xxx") or die (mysql_error ());

    // Select database
    mysql_select_db("xxx") or die(mysql_error());

    // SQL query
    $strSQL = "SELECT * FROM news";

    // Execute the query (the recordset $rs contains the result)
    $rs = mysql_query($strSQL);

    // Loop the recordset $rs
    // Each row will be made into an array ($row) using mysql_fetch_array
    while($row = mysql_fetch_array($rs)) {

       // Write the value of the column FirstName (which is now in the array $row)
      echo $row['editor_name'] . " " . $row['news_desc'];
  echo "<br />";
  }

    // Close the database connection
    mysql_close();
    ?>

</div>  <!-- content #end -->

the database; db

the above yields;

news

I want to do the following; BY: Fadi

echo 'BY' $row['editor_name'] . " " . $row['news_desc'];
      echo "<br />";

but it isn't working :( any tips

David Garcia
  • 3,056
  • 18
  • 55
  • 90
  • search for "php mysql charset utf-8" – dynamic Apr 01 '12 at 20:18
  • possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – dynamic Apr 01 '12 at 20:18
  • 1
    `echo 'BY' $row['editor_name'] . " " . $row['news_desc']; echo "
    ";` should be `echo 'BY' . $row['editor_name'] . " " . $row['news_desc']; echo "
    ";`
    – Jack Apr 01 '12 at 20:24

3 Answers3

1

You are missing a concat operator after 'BY'. Should be

echo 'BY' . $row['editor_name'] . " " . $row['news_desc'];
echo "<br />";

OR tidier:

echo "BY {$row['editor_name']} {$row['news_desc']}<br/>";
PorridgeBear
  • 1,183
  • 1
  • 12
  • 19
0

If you want to return associative array you can try using this line:

...

while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
...
dAm2K
  • 9,923
  • 5
  • 44
  • 47
0

You forgot one dot after 'BY'

echo 'BY' . $row['editor_name'] . ' ' . $row['news_desc'] . '<br />';
Gabriel Santos
  • 4,934
  • 2
  • 43
  • 74