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

3
  • search for "php mysql charset utf-8" Commented Apr 1, 2012 at 20:18
  • possible duplicate of UTF-8 all the way through Commented Apr 1, 2012 at 20:18
  • 1
    echo 'BY' $row['editor_name'] . " " . $row['news_desc']; echo "<br />"; should be echo 'BY' . $row['editor_name'] . " " . $row['news_desc']; echo "<br />"; Commented Apr 1, 2012 at 20:24

3 Answers 3

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/>";
Sign up to request clarification or add additional context in comments.

Comments

0

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

...

while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
...

Comments

0

You forgot one dot after 'BY'

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

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.