ababba2 Posted January 22, 2016 Share Posted January 22, 2016 Hi guys, I need a php script that check if the column of a database is written.If there is something witten, then the php should echo what is written in the column.If the column is empty, then it should echo a blank space.Is it possible? How? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 22, 2016 Share Posted January 22, 2016 Of course it is. Write a query to select the specific RECORD that you are curious about and then retrieve the result (a row) and examine the column in that retrieved row. Do a little research in the php manual on how to use PDO as your db interface. (Or mysqlI, if PDO is n/a.). You'll need to setup a db connection, write a query, run the query and then fetch the result. (Be sure to write your script so that you do checks on each of those ops to ensure that they succeed before blindly moving to the next stage.) All good things to learn as you (apparently) begin your programmer training. Quote Link to comment Share on other sites More sharing options...
ababba2 Posted January 22, 2016 Author Share Posted January 22, 2016 (edited) I already tried. $ass = JURI::base() . "components/com_contushdvideoshare/$htmlVideoDetails->subtitle1"; In this way when I run $ass it execute that function.$htmlVideoDetails->subtitle1 grab the data from the database column.The problem is that if $htmlVideoDetails->subtitle1 have no data, then executing $ass I get http://example.com/components/com_contushdvideoshare/ And I have no idea what should I do for remove http://example.com/components/com_contushdvideoshare/ if and only if $htmlVideoDetails->subtitle1 is empty. Edited January 22, 2016 by ababba2 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 22, 2016 Share Posted January 22, 2016 huh? Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 22, 2016 Share Posted January 22, 2016 OP is using Joomla. OP, your better off finding a Joomla forum for help. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 22, 2016 Share Posted January 22, 2016 For those of us who can't recognize these outside products it would be nice if posters declared such things. Quote Link to comment Share on other sites More sharing options...
ababba2 Posted January 23, 2016 Author Share Posted January 23, 2016 (edited) 1. Even if is based on Joomla, this is a custom code, so it's nothing related to joomla. 2. The fact I'm using joomla doesn't matter in my problem. I just made a question about this custom code for check if the database column called "subtitle1" contains data. If contains data then it should run: JURI::base() . "components/com_contushdvideoshare/$htmlVideoDetails->subtitle1" but if not contains data then it shouldn't do nothing. Connection to database, etc are already made. And data in that column could be checked using $htmlVideoDetails->subtitle1.Doesn't seem too hard to understand. Also, Joomla is not based on an alien programming language. Edited January 23, 2016 by ababba2 Quote Link to comment Share on other sites More sharing options...
maxxd Posted January 23, 2016 Share Posted January 23, 2016 (edited) Use a ternary operator: $ass = empty($htmlVideoDetails->subtitile1) ? null : JURI::base()."components/com_contushdvideoshare/{$htmlVideoDetails->subtitle1}"; Of course Joomla's not based on an alien programming language, but it is - for lack of a better term - a dialect of PHP. Every framework has a different way of doing things. For instance, if the call to $htmlVideoDetails->subtitle1 hits the database or moves a SQL resource pointer forward in the result set, you'll not want to do it this way because you'll move past your intended data by doing the empty() check and return the second record, which may very well be null or empty. This is why it would be helpful to let people know what framework you're using; a 'bug' like this one isn't technically a bug, it's a logic flaw. Anyone who responds with the code above may lead you down a rabbit hole of hours or even days trying to figure out why the code "doesn't work", when it is, in fact, working perfectly. It's just that it's not returning what you expect it to return, and therefor looks like a bug. Hope that makes sense. Edited January 23, 2016 by maxxd Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.