Donno stolz, a snippet of a script does not work for me , i am kind of a newbie, but a quick learner.
I have following now, but it doesnt work ? Anyone ?
It does not display anthing , i tried to put it here : http://www.camchoice.com/randompic.php , with no result
<?
Database Definitions
$dbhost = "";
$dbname = "";
$dbuser = "";
$dbpass = "";
Default Connection String
$connection = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Unable to connect to MySQL server." . mysql_error());
$db = mysql_select_db($dbname, $connection) or die ("Unable to select database: " . mysql_error());
$cat = "image";
function get_total($cat, $db) {
mysql_select_db($db);
$sql = "SELECT count(*)AS total FROM searchidx WHERE cat_id = '$cat'";
if(!$result = mysql_query($sql)) {
return("ERROR: MYSQL [QUERY] ERROR");
}
if(!$myrow = mysql_fetch_array($result)) {
return("0");
} else {
return($myrow['total']);
}
}
if (isset($_GET['cat'])) {
$cat = $_GET['cat'];
} else { // no GET METHOD [cat] (VALUE)
// assign a default one [cat = (VALUE)]
$cat = "image";
}
$total = get_total($cat, $db);
if (preg_match("/[0-9]/", $total)) {
if ($total > 0) {
$sql = "SELECT * FROM images WHERE cat_id = '$cat' ORDER BY RAND() LIMIT 1";
if (!$result = mysql_query($sql)) {
// return a sql error or do (something else [error related])
} else { // if no sql query error was returned
// convert the results
$img = mysql_fetch_array($result);
// should use strip/add_slashes (ALWAYS)
$path = $img[img_path];
$name = $img[img_name];
$height = $img[img_height];
$size = $img[img_size];
$by = $img[img_by];
$date = $img[img_date];
// show the random image/info result!
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"400\">\n";
echo "<tr><td class=\"title\" width=\"400\">Created By: ".$by."</td></tr>\n";
echo "<tr><td class=\"title\" width=\"400\">Date Added: ".$date."</td></tr>\n";
echo "<tr><td class=\"title\" width=\"400\">Image Size: ".$size."</td></tr>\n";
echo "<tr><td class=\"title\" width=\"400\">Image Name: ".$name."</td></tr>\n";
echo "<tr><td class=\"img\" width=\"400\">";
echo "<img src=\"".$path."/".$name."\" HEIGHT=\"".$height."\" WIDTH=\"".$width."\" TITLE=\"".$name." (SIZE: ".$size.")\"></td></tr>\n";
echo "</table>\n";
}
} else { // if total not greater than [0] (NO [DB RESULTS])
// no images found for this catagory
}
} else { // get_total() did not return a [numeric value]
// return the sql error or do (something else [error related])
}
?>