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
https://forums.phpfreaks.com/topic/115442-multiple-sql-select-commands/
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";

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());
?>

<?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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.