Jump to content

Recommended Posts

Hi there,

Got a system where pages within my CMS have 'flags' and so, in the database there is a single field for all of these flags. The flags basically decipher things like whether a page is a draft or not, whether it should be displayed in the nav-bar, whether it should be displayed in the sidebar and whether it should appear in search results. Each numeric input is delimited by commas (e.g. 0,0,1,1).

 

Initially it was simple, all I had to do for one page request is find that page (using the pID in the DB as it's WHERE field), explode the flags field via commas and it was easy to process from there for one page, however the nav-bar display one is a tricky one (likewise with the search & sidebar). What I will need to do is find every field that has a 1 for the second & third items in each array for every exploded field in the table. I would imagine MySQL isn't capable of this, so I guess its down to PHP, however I am no good with the more technical loops.

 

here's some example data:

Table name = fs_pages
pgID, pgURI, pgName, pgSummary, pgBody, pgUser, pgTimestamp, pgFlags

 

Grab all of the info using MySQLi Query (the easy bit) unless you can explode fields with a query.

Loop through all of the rows, exploding the pgFlags fields and finding all of the rows where $examplearray[1] == 1

 

Thanks in advance,

Dan ;)

I'm not much of a MySQL person if I'm honest, Never realised how powerful MySQL is, but a lot of people say try to utilise mysql's features before calling upon php to haul the workload.

 

Could you explain how this query would be written, and yes the numbers are always single digits. Remember I'll need to loop through each row using this substring thing.

Okay say your string is

 

0,1,1,3,2

 

with mysql's substring, the first character position in the string is 1 (not 0 like with most things).  So you know that your numbers will be in positions 1,3,5,7,9,etc... so if you want to select all rows where the 2nd and 3rd numbers are 1 (from your OP), you would do something like this:

 

select * from fs_pages where substring(pgFlags,3,1) = 1 and substring(pgFlags,5,1) = 1

 

 

 

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.