now i use this code:
$welcome_text = mysql_query("SELECT * FROM `text` WHERE `name` = 'welcome'");
while ($row = mysql_fetch_array($welcome_text, MYSQL_ASSOC)) {
echo $row['content'];
}
Is it possible to use it without WHILE if i know exactly which one column i need?
Something like this:
$welcome_text = mysql_query("SELECT 'content' FROM `text` WHERE `name` = 'welcome'");
echo $welcome_text;
Thanks
mysql_querymakes the query, returns a result set.mysql_fetch_arrayfetches the first row from the result set.Of course, you can shorten your code if you want, but this may make your code more difficult to debug and maintain.
Verbose, clear code > one-liner ‘show-off’ code.
Including ‘just-in-case’ checking:
Good practice to make doubly sure you have what you need before printing it.
Finally, please make sure you sanitize user-submitted data before it goes into your database. If you’re not going to use prepared statements, at least use mysql_real_escape_string.
Practice safe SQL, wear a prepared statement to prevent SQL Injections.