Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Pulling individual 'page names' from a table for use in navigation

Featured Replies

Hey all, I've created a back end where customers can edit their content. The page content (just text) is currently in a table, which includes the meta tags and page name. I have been using the following code to get the specific content on each page using WHERE id = 1,2,3 etc

 

mysql_select_db($database_template, $template); 
$query_pages = "SELECT * FROM pages WHERE id = 1"; 
$pages = mysql_query($query_pages, $template) or die(mysql_error()); 
$row_pages = mysql_fetch_assoc($pages); 
$totalRows_pages = mysql_num_rows($pages);  

I now want to pull the page name from individual records so I can insert it into the navigation buttons. This way, if they change the page name from the back end, it will be reflected in the navigation buttons on every page. I don't want to use a while loop in the nav as some of the buttons are unique, like the active one has different properties and an arrow. What is the best way to pull individual bits of informationicon1.png from a table, so <?php echo $row_pages['pagename']; ?> where ID = 2. <?php echo $row_pages['pagename']; ?> where ID = 3 etc. I could duplicate the above 10 times on each page purely to get the page name but I guess there's a better way? Thanks in advance

You shouldn't be using mysql_* functions. They're deprecated. You should be using PDO. You're also writing procedural PHP, which generally isn't good practice for a web application that you're describing. For a CMS, you'd be better off working with a PHP framework.

 

It looks like you need to take a step back and learn a little more about the basics before attempting to build something of this scale. You'll get into bad habits otherwise.

 

With regards to your navigation question, I'm not sure I quite follow what you're trying to do. Manually echoing a finite set is rarely the solution to outputting information from arrays. Also, your query is already specifying "WHERE id = 1", so it should only return one result (assuming id is the primary key).

  • Author

Thanks for the advice. Yeah I can already feel myself picking up some bad habits and trying to find workarounds like the example above. The back end is very basic, just allowing customers to change website text so I've just been echoing and updating records so far. Can you recommend a simple framework? Thanks buddy

CodeIgniter is a popular and simple PHP framework. I've used it a few times for personal projects and found it very easy to pick up. It would work well for this mini-CMS you're creating.

 

It may be simple, what you're building, but that doesn't stop you building it using best practices. Hopefully you'll find that using a framework will open your eyes to the object-oriented approach.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.