To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Coding

Coding Help with PHP coding

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-03-2009, 12:37 PM   #1
Razorster
Junior Member
 
Join Date: Nov 2009
Posts: 5
Exclamation MySQL Query In PHP to get a field out of a table..

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/cal...h=11&year=2009

Its not quite right. The image field is called "promoimage" which is part of every record in the table of events. This is a URL. My code is as follows:

PHP Code:
<?

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)) . "&nbsp;" . $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.

Last edited by bradgrafelman; 11-06-2009 at 03:28 AM. Reason: bbcode tags edited
Razorster is offline   Reply With Quote
Old 11-04-2009, 03:13 AM   #2
toxic_brain
Oops !
 
toxic_brain's Avatar
 
Join Date: Jun 2005
Location: Hell
Posts: 136
Quote:
Its not quite right
Quote:
I think my coding is wrong.
Please mention what is the expected result and the actual result.
__________________
toxic_brain
toxic_brain is offline   Reply With Quote
Old 11-04-2009, 07:25 AM   #3
Razorster
Junior Member
 
Join Date: Nov 2009
Posts: 5
Hi there mate,

The expected output is for each day to show its image URL - logo. The first 14 show, but they are shifted to the right (wrong order). Then last 7 should show, but they do not.

Any ideas?
Razorster is offline   Reply With Quote
Old 11-04-2009, 06:10 PM   #4
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,128
PHP Code:
      $promoimage=mysql_result($result, $i, "promoimage");
One problem I see is that you've forgotten that result row numbers start from 0, while $i starts from 1.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 11-04-2009, 06:56 PM   #5
Razorster
Junior Member
 
Join Date: Nov 2009
Posts: 5
hi mate,

thanks for your reply! I appreciate it.

$i starts from 1 because if it were to start from 0 the first date of the month would be the 0st, which doesnt exist lol. I am so confused! PHP is not my expertise, any other ideas mate?
Razorster is offline   Reply With Quote
Old 11-04-2009, 09:06 PM   #6
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,128
mysql_result
Quote:
Row numbers start at 0.
So .... ooh, this is difficult ....
PHP Code:
$promoimage=mysql_result($result, $i - 1, "promoimage");
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 11-05-2009, 05:12 AM   #7
Razorster
Junior Member
 
Join Date: Nov 2009
Posts: 5
thank you! that didnt seem to solve it though? it didnt change anything.
Razorster is offline   Reply With Quote
Old 11-07-2009, 02:04 PM   #8
Razorster
Junior Member
 
Join Date: Nov 2009
Posts: 5
anyone?
Razorster is offline   Reply With Quote
Old 11-08-2009, 03:56 PM   #9
woodeye
Member
 
Join Date: Oct 2007
Posts: 50
I'm trying to figure out how you have your database set up. From what it looks like, unless your database has an entry for EVERY day, then it's not going to work.

Have you tried looking the results from the query? What is the result if you do this:

PHP Code:
$query= 'SELECT * FROM calendar_event ORDER BY day';
$result=mysql_query($query);

print
"<pre>";
print_r($result);
print
"</pre>";
I'm thinking that the result of the query isn't what you're expecting.
woodeye is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 04:29 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.