View Single Post
Old 08-05-2007, 11:00 AM   #1 (permalink)
draven77
Recruit
 
Join Date: May 2005
Posts: 13
draven77 is on a distinguished road
Query from multiple tables

Hi all,
I know this is super easy, but I'm a designer mostly. Trying to learn something here

I'm writing this script for the band I'm in with my church. I want to write something that will look to see who's playing and send them a text message. I have most of it worked out, but can't seem to get the initial query working. Anything look immediately wrong with this?

Thanks in advanced for any tips!:

Code:
<?
// database connect function
mydbconnect();
// setup date
$today = date("Ymd");
$row_count = 0;
$color1 = " class=\"altrow\"";
$color2 = "";

if ($orderby=="") $orderby = "dates.dateDate";
	
	// Start query
	$result = mysql_query("
		SELECT *
		FROM roster, dates, members
		WHERE (
			(roster.rosterMemberID = members.memberID)
		AND
			(roster.rosterDateID = dates.dateID)
		
			)
		ORDER BY 
		".$orderby." DESC") or die ("no DB connection<br /><br />".mysql_error() );
	$number = mysql_numrows($result);
	
	if ($number < 1){print "<tr><td class=\"altrow\" colspan=\"7\">There are no items available at this time.</td></tr>";}
	else {
		echo "
		<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" class=\"table1\" width=\"540\">
		<tr>
			<th>Service</th>
			<th>Who's On</th>
			<th>Send a reminder</th>
		</tr>";
		
		while($r=mysql_fetch_array($result))
		{    
			// ESTABLISH FIELD NAMES
			$rosterID=$r["roster.rosterID"];
			$rosterDate=$r["dates.dateDate"];
			$firstname=$r["members.memberFname"];
			
			
			// Date formatting from yyyy-mm-dd
			$year = substr($dateDate, 2, 2); 
			$month = substr($dateDate, -5, 2);
			$day = substr($dateDate, 8, 9); 
			$formatted_date = $month ."/". $day ."/". $year;
			
			// This is the code for alternating row colors
			$row_color = ($row_count % 2) ? $color1 : $color2;
			
			// loop here
			echo "
				<tr>\n
					<td>".$rosterDate."</td>\n
					<td>".$firstname."</td>\n
					<td><img src=\"images/button.gif\" /></td>\n
				</tr>\n";
			
			$row_count ++;
		}
		echo "</table>";
	}

?>
draven77 is offline   Reply With Quote