PHP display data from mysql columns

Code with C | Programming: Projects & Source Codes Forums PHP PHP display data from mysql columns

This topic contains 4 replies, has 1 voice, and was last updated by  SapnaVishwas 2 years, 6 months ago.

  • Author
  • #10998

    I wanna display all data from MySql columns named BOOK and LINK

    And in text

    Only display One record. How to do that?

  • #10999


    First, you might want to check out the proper MySQL syntax. Secondly, I hope you’re doing some security with $myusername. Thirdly, variables in single quotation marks (”) won’t be parsed. Finally, I’d do some MySQLi research.

  • #11000


    Useful link:

    Might not be too pretty but this will work:

    You need to make sure that $myusername is safe from SQL injection.

    You stated it only displays one record, that is because in your code you are setting $book to $column[‘book’], which does not tell it to loop thru all of the data and display it.

    Hope this helped. Also I thought I would mention, if this is for a project that will be online for a while, keep in mind that as of PHP 5.5 the mysql_ commands are deprecated.

  • #11001


    I suggest using PDO instead of the mysql_* functions, they are not being maintained anymore. PDO offers a FETCH constant to fetch a column – PDO::FETCH_COLUMN. That’s exactly the one you need. Visit the link provided by

    If you don’t want to move to PDO, then this is the mysql_ function you need:

  • #11002


    The mysql_fetch_assoc is handy if you extract your data and want access to them by the row-name. eg. Say result is the returned result of your query on a table containing name and age
    data=mysql_fetch_rowresult; will be an array on which your data can be accessed as data0 and data1

    data=mysql_fetch_assocresult; will be an array on which your data can be accessed as dataname and dataage

    I hope this will help you solve the problem.

You must be logged in to reply to this topic.