I run a high school site and am learning to use PHP/MySQL, and I have two problems that I cannot figure out.
- On our sports scoreboard, I have very repetative code, that I would like to make into a function.
I used Dreamweaver to query the info (I have 10 similar queries on this page)
mysql_select_db($database_wintersports, $wintersports);
$query_BVBB_Result = "SELECT * FROM0405
WHERE Level LIKE 'Varsity' AND Sport LIKE 'Basketball' AND Gender LIKE 'Boys' AND (Result != '' OR InvTotal > 0) ORDER BY 'Date' DESC";
$BVBB_Result = mysql_query($query_BVBB_Result, $wintersports) or die(mysql_error());
$row_BVBB_Result = mysql_fetch_assoc($BVBB_Result);
$totalRows_BVBB_Result = mysql_num_rows($BVBB_Result);
Here is the current code to display the info:
<?php
if ($row_BVBB_Result['Opponent'] != "" ){
echo '~ '.date('n/j',strtotime($row_BVBB_Result['Date'])) ?>
<br>
<?php if ($row_BVBB_Result['Location'] == "Away")
$vs = "@ ";
else
$vs = "vs. ";?>
<?php if ($row_BVBB_Result['InvPlace'] == 0)
echo $vs.($row_BVBB_Result['Opponent'])." ".($row_BVBB_Result['Result'])." ".($row_BVBB_Result['Pts'])."-".($row_BVBB_Result['Pts_Opp']); }?>
This works fine, but I would like to create function that will need just the sport, level, or gender as a variable to run the function. I have tried the following with no success.
<?php
function Results($Sport){
$Sport = '$row'.$Sport.'Result';
if ($Sport['Opponent'] != "" ){
echo '~ '.date('n/j',strtotime($Sport['Date'])).'<br>';
if ($Sport['Location'] == "Away")
$vs = "@ ";
else
$vs = "vs. ";
if ($Sport['InvPlace'] == 0)
echo $vs.($Sport['Opponent'])." ".($Sport['Result'])." ".($Sport['Pts'])."-".($Sport['Pts_Opp']);
echo "<br>".$Sport; }
}?>
The calling code is:
<?php $Sport="VBBB";
Results($Sport);
?>
When I run this and echo $Sport, it says $row_VBBB_result, which should work. Any suggestions?
- I want to make a Happy Birthday table that will pull a student's birthday from SQL and display their name.
I want to query today's date (but not year) from SQL using the field name BIRTHDAY. (I can set up the data type anyway I need to, including TEXT) Any ideas?