Code for if statement

12 posts by 4 authors in: Forums > CMS Builder
Last Post: September 25, 2013   (RSS)

By dlsweb - September 20, 2013

Not knowing php...
For
list($newsRecords, $newsMetaData) = getRecords(array(
  'tableName'   => 'news',
  'perPage'     => '15',

What code do I include to display only "visible" articles set in a field called "status"

Thanks

By dlsweb - September 20, 2013

It would be

  list($newsRecords, $newsMetaData) = getRecords(array(
    'tableName'   => 'news',
    'where'       => "status = 'visible'",
    'perPage'     => '15',

By jenolan - September 20, 2013

list($newsRecords, $newsMetaData) = getRecords( array( 'tableName'   => 'news',
  'perPage'     => '15',
  'where'       => 'visible = 1' ) );

---
<?= "Jenolan(Larry) :: Coding Since 1973" ?>
Peace and Long Life

By dlsweb - September 21, 2013 - edited: September 21, 2013

Unfortunately 'where'       => 'visible = 1'gets     MySQL Error: Unknown column 'visible' in 'where clause'

and'where'       => 'status = 1'
gets no record found  ( I have 2 articles, one marked visible, another marked pending )

and    'where'       => "status = 'visible'"

lists both articles (visible and pending)

any help is much appreciated

By jenolan - September 21, 2013

The second part of the where ie;

visible = 1

visible needs to be the field in the table that decides visibility, and the bit after the '=' needs to be what is in the row when the row is visible.

If you want further help .. send me an email to help@jenolan.org .. I will need

  • ftp access
  • file to edit (including directory)
  • db access detail ie localhost, db_name, db_user, db_password (to save looking it up)
  • db & table name
  • either a dump of the table or I will just use a utility to look at the table
---
<?= "Jenolan(Larry) :: Coding Since 1973" ?>
Peace and Long Life

By Daryl - September 23, 2013

Hi dlsweb,

If you still need help with this, can you please post a screenshot of the 'status' field in section editor showing your list options?

Thanks,

Daryl

Daryl Maximo
PHP Programmer - interactivetools.com

By dlsweb - September 23, 2013

I saw what jenolan was saying and changed my field name to visible, and made it a checkbox (so a yes/no option )

Now it works fine where my original way did not.

But here is the same situation with a field named "category"
For "category" I have a list- news, community, sports.

So this coding

  list($newsRecords, $newsMetaData) = getRecords(array(
    'tableName'   => 'news',
    'perPage'     => '10',
    'where'       => 'visible = 1',    
//    'where'       => 'category = news',

gets this page   http://bainbridgega.com/bnews/news-list.php

I uncomment the where
  list($newsRecords, $newsMetaData) = getRecords(array(
    'tableName'   => 'news',
    'perPage'     => '10',
    'where'       => 'visible = 1',    
    'where'       => 'category = news',

and gets this page   http://bainbridgega.com/bnews/news-list-2.php
saying   MySQL Error: Unknown column 'news' in 'where clause'

Thnaks

By dlsweb - September 23, 2013 - edited: September 25, 2013

thank you

now  http://bainbridgega.com/bnews/news-list-.php  gets no record found even though you can see
at  http://bainbridgega.com/bnews/newslist.php   that one article is "news"

Tks

By jenolan - September 23, 2013

They come up as 'page not available' in the table it is 'news' not 'News' ??  Could be an issue depending on your collation for the table.

---
<?= "Jenolan(Larry) :: Coding Since 1973" ?>
Peace and Long Life