• Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp

Posts tagged Web Development

Web Dev> Handling dynamically created checkboxes

May02
2012
Written by Scott Rowley

Ok, so let’s say I have a list of users in a database. I want to get that list out on the screen and allow someone to be able to use checkboxes to do something with each of those users. In this example we’re going to say we are deleting any users that have been checked. If you are not already familiar with building dynamic output from mysql then I suggest you first read over Web Dev> Populate PHP/HTML table from MySQL database

First we’ll build our form to show our users, in this example I’m actually building my list of users from a query to a mail server which gets returned to me first as a string. I need to change this into an array so I’m going to use explode(). I’ll go through this all step by step so it’s easy to follow along and you can skip whatever parts you feel you are already familiar with.

So lets say the mail server returns this string to me of users:

$members_string = 'Bruce Chuck Jackie Jet';
echo "Members string is '$members_string'";

Which gives us an output of

Members string is 'Bruce Chuck Jackie Jet'

Since I want to loop through each of these members I need to first create an array that I can loop through, this is where explode() comes in.

// Members are separated by spaces, so explode on spaces
$members = explode(' ',$members_string);

READ MORE »

Posted in PHP - Tagged checkbox, dev, dynamic, form, php, web, web dev

Web Dev> PHP function, check if a MySQL table exists

May01
2012
Written by Scott Rowley

Note: This is NOT original sudobash.net code. This has been copied over from ElectricToolBox.com, full credit goes to him/her (I couldn’t find a name anywhere).

The PHP function below gets passed in a tablename and an optional database name. If the database name is not passed in then it retrieves it using the MySQL function SELECT DATABASE(). It then queries the MySQL information schema to see if the table exists and then returns either true or false.

function table_exists($tablename, $database = false) {
if(!$database) {
$res = mysql_query("SELECT DATABASE()");
$database = mysql_result($res, 0);
}
$res = mysql_query("
SELECT COUNT(*) AS count
FROM information_schema.tables
WHERE table_schema = '$database'
AND table_name = '$tablename'
");
return mysql_result($res, 0) == 1;
}

The PHP MySQL functions are used in the above example. A database connection is assumed and there is no error checking, but you can modify it to utilise whatever database library / abstraction layer you are using in your project and improve how you see fit.

To use the function you’d do something like this:

if(table_exists('my_table_name')) {
// do something
}
else {
// do something else
}

and if you wanted to specify the database name as well (perhaps you are needing to query if the table exists in multiple databases other than the one you are currently connected to), you’d do this:

if(table_exists('my_table_name', 'my_database_name')) {
// do something
}
else {
// do something else
}
Posted in MySQL, PHP - Tagged check, database, dev, exists, function, MySQL, php, table, web

WebDev> CSS Stylings

Jan25
2012
Written by Scott Rowley

Just starting to make a note of some of my CSS creations:

Informational Box

SudoBash is proud to announce our newest office location

123 Kittens Street conveniently located 1 mile from LOLcat lane.

<style>
.info {
border: 2px solid #D8D8D8;
margin: 10px 0px;
background-repeat: no-repeat;
padding: 10px 0 10px 150px;
background-position: 10px center;
color: #00529B;
background-color: #E0E0E0;
background-image: url('/images/info.png');
}
</style>
<div class="info"><strong>SudoBash is proud to announce our newest office location</strong><br><br>
123 Kittens Street conveniently located 1 mile from LOLcat lane.</div>
Tagged css, dev, development, html, info, information, web

Web Dev> CGI-based redirect

Oct26
2010
Written by Scott Rowley

Recently I replaced an old .cgi file with a shiny new .php page. I realize everyone is still linking to the old .cgi file so I had need to forward them all onto the sexy new page. This can be accomplished as easily as the following:

Simply replace (after backing up) your .cgi file with the following contents

#!/path/to/perl
print "Location: http://domain.com/newpage.php\n\n";
Tagged cgi, code, Perl

Javascript> Reference Javascript (.js) file

Oct26
2010
Written by Scott Rowley

Sometimes we have so much javascript code in our files that it just becomes bulky and gets in the way. Instead of including it all in your file, save it all to a seperate file that can be referenced in your page (or better yet multiple pages).
Simply place the following within your <head> tags:

<script language="javascript" src="/path/to/file.js"></script>
Posted in Javascript - Tagged code, Javascript, reference

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Advertisement

Sudo Bash
By Geeks - For Geeks

Back to Top