RedCoupe

Web design / development

Get dropdown list label value

by on Jun.09, 2011, under Web design / development

I was working on a couple of web pages this morning to allow completion of a course booking form, user then submits to a thankyou page, confirmation emails are sent etc.

The problem I faced was that only the course ID was being passed to the thankyou page so in the emails that are generated, it displays Course Details: 7 , instead of Course Details: 12/12/2011 PHP Basics.

So my initial thought was to create a hidden field just before the end form tag together with some javascript that gets the relevant label value:

document.getElementById('coursedetails').value = document.getElementById('training_id')[document.getElementById('training_id').selectedIndex].innerHTML;

Then in the thankyou page I just got Request.Form(“coursedetails”), this is in ASP VBScript just in case you were wondering. Works like a charm.

Since doing this is I should have done it a much easier way and not have to rely on JavaScript being enabled. I already had the value because I was already using it to display the dropdown list label. So the hidden field could have just contained the default value of the currently selected item.

Leave a Comment : more...

MS SQL Server – get second from last record

by on May.18, 2011, under Web design / development

Using MS SQL Server, I’ve been trying to get the second from last record that had been created because I want to do some comparison code to display what has been changed.

Anyway just form future reference here’s the SQL I used:

SELECT TOP 1 *
FROM dbo.tbl_MailList_Items
WHERE item_id < (SELECT MAX(item_id) FROM dbo.tbl_MailList_Items)
ORDER BY item_id DESC

This works perfectly for my situation and doesnt rely on just subtracting 1 from the id column because my id column is not fully incremental due to records being deleted etc.

Leave a Comment : more...

Ubuntu subdomains on Apache2

by on Sep.21, 2010, under Web design / development

From a standard Apache2 install I created a folder in /var/www/ called ‘testsite’ (without the quotes).

Go to the following folder:

/etc/apache2/sites-available

…and create a file called something suitable, for this purposes of this blog post I’ll just call my file testsite, It’s contents should be:

<VirtualHost *:80>
  DocumentRoot /var/www/testsite/
  ServerName testsite.localhost
  ServerAlias testsite.myubuntubox
  <Directory /var/www/testsite/>
    Options Indexes FollowSymLinks MultiViews +Includes
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>
</VirtualHost>

Then run the following command:

sudo a2ensite testsite

Edit your /etc/hosts file and add the following lines:

127.0.0.1 testsite.localhost
127.0.0.1 testsite.myubuntubox
192.168.0.6 testsite.myubuntubox

Obviously the ip address 192.168.0.6 may be different depending on your network setup.

Restart Apache:

sudo /etc/init.d/apache2 reload

I also had to edit my c:\windows\system32\drivers\etc\hosts file on my other PC to make sure that when I visit http://testsite.myubuntubox/ it resolves correctly, so I now have the following:

127.0.0.1 localhost
192.168.0.6 myubuntubox
192.168.0.6 testsite.myubuntubox

That’s it, all working, now I can develop multiple websites locally using subdomains. Personally I would rather do it this way than putting websites into folders, seems to work better with Dreamweaver.

Leave a Comment : more...

Change date/time format from MySQL

by on Sep.17, 2010, under Web design / development

Format was: 2010-09-17 12:09:01

But wanted to display like: 17-09-2010 12:09:01

<?php echo date('d-m-Y H:m:s', strtotime($row_Recordset1['datetimeval'])); ?>

Related links:

Leave a Comment :, more...

PHP replace crlf in a textarea with br

by on Sep.09, 2010, under Web design / development

I had a textarea value which was obtained from a MySQL database and it contained many instances of crlf or \n. To display correctly on a web page I wanted to convert those to <br /> so I used the following code:

<?php echo nl2br($myrecorsetvalue); ?>

Obviously you would need to replace the $myrecorsetvalue with whatever recordset variable you are using.

Leave a Comment :, more...

Random rows in MySQL

by on Sep.08, 2010, under Web design / development

A competition has been running on a website and all the entries were stored in a MySQL table.

Had to get a random record to pick a winner once the closing date had passed.

Here’s the SQL I used:

SELECT *
FROM t_tablename
ORDER BY RAND()
LIMIT 1

If I had wanted to pick out 5 random winners, then change the LIMIT value to LIMIT 5.

Leave a Comment : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!