Jump to content

Multiple SQL Select Commands


stublackett

Recommended Posts

Hi,

 

I've got a Calendar setup in the form of a HTML Table

 

The problem I have is, That for each td cell I am having to put PHP Code in each cell to pull the relevant data for that Day / Month / Year

 

Is there anyway to shorten the code so that I dont have to do it for each TD Cell

 

Here is my code

 

<td>1
<?php 
$day = 1;
$result = mysql_query("SELECT * FROM $db_table WHERE day = $day");
while($day = mysql_fetch_assoc($result))
                                                 
{//begin of loop
$title = $day['title'];
$id = $day['id'];
//now print the results:          
// Now print the options to view item
echo $title;
}//End While loop                    
?>
</td>

 

This is obviously repeated for day 2,3,4,5 etc is there anyway at all to prevent me constantly putting this into each <td> Cell!?

Link to comment
Share on other sites

Whats the best approach to get the actual date there JD* ?

 

I was just going to do it as 1 = January, 2 = February etc, But if theres an easier way I'll try that

 

I assume I'm doing something like this

 

for ( $day =1; $day<31; )
echo "<td>$day";

Link to comment
Share on other sites

Sorry to bump this up

 

I'm totally lost on the loop front

 

I need to get the date aswell as obviously produce the data that it pulls through from the Database for that date

 

I've got something like this so far

 

<?php 
$day=date();
do
  {
  $day++;
  echo "The date is " . $day . "<br />";
  }
while ($day<=date());
?>

Link to comment
Share on other sites

<?php 
$result = mysql_query("SELECT * FROM $db_table");
$arrTitles = array();
while($day = mysql_fetch_assoc($result)) {
  $arrTitles[$day['day']] = $day['title'];
}

$intDays = date('t');//no of days in current month

echo "<table><tr>";

for($intCount=1;$intCount<=$intDays;$intCount++) {
    echo "<td>".$arrTitles[$intCount]."</td>";
}
echo "</tr></table>";


?>

 

try this...code is not tested..

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.