Code for if statement

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

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

It would be

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

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

---



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

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
---



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

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

'category = "news"',

---



Peace and Long Life

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

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.

---



Peace and Long Life