b3ta.com qotw
You are not logged in. Login or Signup
Home » Question of the Week » Off Topic » Post 538602 | Search
This is a question Off Topic

Are you a QOTWer? Do you want to start a thread that isn't a direct answer to the current QOTW? Then this place, gentle poster, is your friend.

(, Sun 1 Apr 2001, 1:00)
Pages: Latest, 836, 835, 834, 833, 832, ... 1

« Go Back | See The Full Thread

Nononononononon....NO.
Don't put the connection function into the dj function. Every time it's called, it'll create a new connection to the DB.

///// Put this in something like "lib/settings.php" /////
$settings['host'] = "localhost";
$settings['user'] = "username";
$settings['pass'] = "password";
$settings['dbname'] = "dbname";

///// Put this in your "lib/head.php" file //////

include_once('settings.php');
include_once('functions.php');
$con = mysql_connect($settings['host'],$settings['user'],$settings['pass']);
if (!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db($settings['dbname'], $con);

////// Put this in 'lib/functions.php' /////////
function getLatestDJ(){
global $con;
$result = mysql_query("SELECT DJ from dj_schedule order by dj_schedule_id desc limit 1");
$row = mysql_fetch_assoc($result);
return $row;
}

////// Put this in your front page.

include('lib/head.php');
// put this where you want.
$x = getLatestDJ();
echo "Next DJ is ".$x['DJ']." <img src=\"".$x['']."\" />";
(, Tue 13 Oct 2009, 18:15, 1 reply, 16 years ago)
indeed.
but I believe he'd only need it once.

Yours is, however, far more elegant. I'd rushed mine off the top of my head to point in the right direction.
(, Tue 13 Oct 2009, 18:53, Reply)

« Go Back | See The Full Thread

Pages: Latest, 836, 835, 834, 833, 832, ... 1