Jump to content

check column in database


ababba2

Recommended Posts

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.

Link to comment
Share on other sites

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 by ababba2
Link to comment
Share on other sites

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 by ababba2
Link to comment
Share on other sites

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 by maxxd
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.