Re: Stupid newbie looping MySQL question
| From: | Lynn Siprelle | Date: | Mon, 08 Jan 2001 18:14:32 +0000 |
| Subject: | Re: Stupid newbie looping MySQL question | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-5713@lists.php.net to get a copy of this message | ||
>Not sure this fixes everything, but it should be really close.
Once I cleaned up a last small error that had nothing to do with what we've been discussing,
yes, it works! Thank you SO much.
If anyone runs a phorum installation and wants to show new messages within the last 24 hours on a
different page, here is a piece of code that will do it:
<?
//new.php: Try to pull out the new posts in the last 24 hours, limited to 10 per topic.
//You will need to change $myquery's call to the table "forums" to whatever you have
//named the table that holds info about all the forums in your installation.
//the one function from the main phorum scripts you need;
//I've changed the formatting to 12-hr w/am-pm from 24-hr
//which is the standard phorum formatting
function date_format($datestamp){
$tzoffset = 0;
if ($datestamp == "0000-00-00") {
$datestamp = "0000-00-00 00:00:00";
}
list($date,$time) = explode(" ",$datestamp);
list($year,$month,$day) = explode("-",$date);
list($hour,$minute,$second) = explode(":",$time);
$hour = $hour + $tzoffset;
$tstamp = mktime($hour,$minute,$second,$month,$day,$year);
$sDate = date("m-d-y g:i a",$tstamp);
return $sDate;
}
//Either define these next variables yourself or or plug your info in here. Or, if you're
interested in how
//I've gotten phorum to work with a portal program called Just for You that requires folks
//to register before they can post to phorum, drop me a line. These variables are set
//by Just for You in the page this script is included in.
$link = mysql_connect($mysql_hostname, $mysql_username, $mysql_password) or DIE("Unable to
connect to database");
@mysql_select_db("$mysql_database",$db) or die("Unable to select $mysql_database
database");
$myquery="SELECT table_name, id, name FROM forums";
$result = mysql_query($myquery);
while($row=mysql_fetch_object($result)) {
$fid = $row->id;
$tname = $row->table_name;
$name = $row ->name;
$mynextquery ="SELECT id, datestamp, thread, subject, author FROM $tname ORDER BY datestamp
ASC LIMIT 0, 20";
$result2 = mysql_query($mynextquery);
if ($result2) $row2 = mysql_fetch_object($result2);
else continue;
if (!$row2) {
print ("<!--nothing today for $name-->");
} else {
print ("<b>In <a
href=\"/phorum/list.php?f=$fid\">$name</a></b>:</br>\n");
do {
print ("<font size=-1>" . date_format($row2->datestamp, '%b %e,
%Y') . ": <a
href=\"/phorum/read.php?f=$fid&t=$row2->thread&i=$row2->id#i$row2->id\">$row2->subject</a>--$row2->author</font><br>\n");
} while($row2 = mysql_fetch_object($result2));
}
}
?>
Many thanks to everyone who helped me! I hope someone else gets some benefit from this as well;
I'll be posting it at phorum.org too.
Lynn
--
Lynn Siprelle, Siprelle & Associates: Web Construction and Publishing
Chief Assoc. Josephine b. 9/9/97 * New Assoc. Louisa due 5/1/01
Business: lynn@siprelle com | Personal: lynsa@siprelle.com
The New Homemaker: http://www.newhomemaker.com/