close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

retrieving a particular record from a database

Thread began 1/27/2015 10:44 am by Christopher West | Last modified 1/27/2015 12:47 pm by Jason Byrnes | 2308 views | 7 replies |

Christopher WestCommunity Expert

retrieving a particular record from a database

Hi, been some time, and just have a quick question, I have a table in the database called 'sitesettings' which store generic information such as website email address, phone number, address, meta title tag and meta description.

the table is as follows:

php:
<?php

$rsSiteSettings 
= new WA_MySQLi_RS("rsSiteSettings",$sitedb,1);
$rsSiteSettings->setQuery("SELECT * FROM settings");
$rsSiteSettings->execute();
?>



therefore the binding would be:

php:
<?php echo($rsSiteSettings->getColumnVal("settingscontent")); ?>



However how could I use the above binding so that for example in my HTML head I want place this binding inbetween: <title></title>

database table is:

settingsid
settingselement
settingscontent

and the first record the data is:
element = title
content = some random title for seo title demonstration



I tried doing it as an IF statement but even though it works when I used it for the title tag in my html, it doesnt work for the description metatag (is as though the record isnt moving onto the next so the IF statement lookup doesnt become true:

php:
<?php

  
if ("".($rsSiteSettings->getColumnVal("settingselement"))  ."" == "title") {  // WebAssist Show If
?>
<?php 
echo($rsSiteSettings->getColumnVal("settingscontent")); ?>
<?php
  
// ("".($rsSiteSettings->getColumnVal("settingselement"))  ."" == "title")
?>




Since I be using this database table to store quite a bit of information relating to the website, I be using this data quite a bit on the page so wondered if there is a shorthand approach when adding a record binding to my html?




Regards
Chris

Sign in to reply to this post

Jason ByrnesWebAssist

to move the recordset pointer to the next record, you need to use the moveNext function:

$rsSiteSettings->moveNext();

Sign in to reply to this post

Christopher WestCommunity Expert

ah ok. obviously if I have lots of data relating to the webpage stored in my table (for example lets say 100 records in the table) and I am displaying those 100 records in various places dotted around the webpage...doing 100 IF statements all over the place is quite messy...is there some kind of short hand approach to display this data?

Sign in to reply to this post

Jason ByrnesWebAssist

it sounds like a messy table structure

instead of a different record for each piece, use different column and one record.

that way you could output the title as:
<?php echo($rsSiteSettings->getColumnVal("title")); ?>

and the meta description tag as:
<?php echo($rsSiteSettings->getColumnVal("meta_description")); ?>

etc... no need for if statements.

Sign in to reply to this post

Christopher WestCommunity Expert

the problem with that approach is I be using the same type of approach for my main content....I have designed a one page website so on that one page is different sections (about us, booking, contact us etc)

So I wanted to store the data like so:
element
content

so the element is basically storing the location on the page (eg. about us, booking, contact us etc)

Sign in to reply to this post

Jason ByrnesWebAssist

then you are going to have to use the messy 100 if statements approach.

Sign in to reply to this post

Christopher WestCommunity Expert

Been speaking with Ray and he told me about a handy function inside MySQi so he gave me the solution to use that function. here is the workaround in case anyone else wants to find out how to store all different types of data in the same database table (this is particularly useful if you have a one page website with different sections (such as about us, services, blog, testimonials, contact us) and thus all share same layout, eg a section header, section content...

<?php $rsSiteSettings = new WA_MySQLi_RS("rsSiteSettings",$sitedb,0);
$rsSiteSettings->setQuery("SELECT * FROM settings");
$rsSiteSettings->execute();?>

Note: the 0 at the end of the first line is important so that it returns all rows.

and for my example I am stored for SEO purposes the title and description tag in my database table
(using element to store the location and content to store...um..the content)

<title><?php

$rsSiteSettings->moveFirst();
$rsSiteSettings->findRow('settingselement','title');
echo($rsSiteSettings->getColumnVal("settingscontent"));

?></title>
<meta name="description" content="<?php

$rsSiteSettings->moveFirst();
$rsSiteSettings->findRow('settingselement','description');
echo($rsSiteSettings->getColumnVal("settingscontent"));

?>" />

Sign in to reply to this post

Jason ByrnesWebAssist

That's helpfull, I wasn't aware of the findRow() function...

Thanks for posting that.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...