Jump to content

MySQL Query In Php to get a field out of a table..


Razorster

Recommended Posts

Hi there,

 

I am in need of desperate help. I am using a PHP calendar script. I am trying to display an image for each date in the calendar.

 

See my attempt here:

 

http://proudcabaret.com/calendar/calendar.php?month=11&year=2009

 

Its not quite right. The image is called "promoimage" in the table. My code is as follows:

 

<?

include('admin/dbconn.php');
include('functions/functions.php');

include('header.php');

$query= 'SELECT * FROM calendar_event ORDER BY day';
$result=mysql_query($query);
$num=mysql_numrows($result);

$type = CAL_GREGORIAN;

$month = $_GET['month'];
if(!$_GET['month']) { $month = date('n'); } // Month ID, 1 through to 12.

$year = $_GET['year'];
if(!$_GET['month']) { $year = date('Y'); } // Year in 4 digit 2009 format.

$today = date('Y/n/d');

$day_count = cal_days_in_month($type, $month, $year); // Get the amount of days in the chosen month to give to our function.

echo "<div id='calendar'>";
echo "<div id='calendar_wrap'>";

// Function for year change. //

$last_month = $month - 1;
$next_month = $month + 1;

$last_year = $year - 1;
$next_year = $year + 1;

if($month == 12) { 
$change_year = $year; 
$change_month  = $last_month;
} elseif($month == 1) { 
$change_year = $last_year;
$change_month  = '12'; 
} else { 
$change_year = $year; 
$change_month  = $last_month;
}

if($month == 1) { 
$change_year_next = $year; 
$change_month_next  = $next_month;
} elseif($month == 12) { 
$change_year_next = $next_year;
$change_month_next  = '1'; 
} else { 
$change_year_next = $year; 
$change_month_next  = $next_month;
}

// Do NOT edit the above. // 

	echo "<div class='title_bar'>";

	echo "<a href='/calendar/calendar.php?month=". $change_month ."&year=". $change_year ."'><div class='previous'></div></a>";
	echo "<a href='/calendar/calendar.php?month=". $change_month_next ."&year=". $change_year_next ."'><div class='next'></div></a>";
	echo "<h2 class='month'>" . date('F',  mktime(0,0,0,$month,1)) . " " . $year . "</h2>";


	echo "</div>";

for($i=1; $i<= $day_count AND $num; $i++) { // Start of for $i

$date = $year.'/'.$month.'/'.$i;

$get_name = date('l', strtotime($date));
$month_name = date('F', strtotime($date));
$day_name = substr($get_name, 0, 3); // Trim day name to 3 chars 
$day_st = date('S', strtotime($date));

$count = count_events($i, $month,$year);

echo "<a href='day_view.php?day=$i&month=$month&year=$year' title='$i $month_name' rel='day_view'>";
echo "<div class='calwrap'>"; // wrapper
echo "<div class='cal_day'>"; // Calendar Day

	echo "<div class='day_heading'>" . $day_name . "</div>";

	if($today == $date) { 
		echo "<div class='day_number today'>" . $i . $day_st ."</div>";
	} else { 
		echo "<div class='day_number'>" . $i . $day_st ."</div>";
	}	

	$promoimage=mysql_result($result, $i, "promoimage");

	if($count >= 1) { 

		if (empty($promoimage)) {  
			echo "<span class='event'>Event</span>";

		} else {
		    echo "<span class='event'><img src='". $promoimage ."'></span>"; }

	}

echo "</div>";
echo "</div>";
echo "</a>";

} // EOF for $i

echo "</div>";
?>

<script type="text/javascript">
$(document).ready(function(){ $("a[rel='day_view']").colorbox({width:"500px", height:"450px", iframe:true}); });
</script>

 

If anyone can help, id be eternally greatful. I think my coding is wrong.

Link to comment
Share on other sites

Hi Razorster,

 

You're trying to output $promoimage using the following code:

 

echo "<span class='event'><img src='". $promoimage ."'></span>"; 

 

What does $promoimage contain?  It should contain something like:

 

"images/image.jpg"

 

For your code to work.

 

Hope this helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.