# Getting mysql table values into an php array

**URL:** <https://forum.kirupa.com/t/getting-mysql-table-values-into-an-php-array/266042>\
**Category:** programming\
**Created:** [July 15, 2008, 7:16pm UTC](https://forum.kirupa.com/t/getting-mysql-table-values-into-an-php-array/266042 "2008-07-15T19:16:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shdt](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@shdt](https://forum.kirupa.com/u/shdt)\
**Post date:** [July 15, 2008, 7:16pm UTC](https://forum.kirupa.com/t/getting-mysql-table-values-into-an-php-array/266042/1 "2008-07-15T19:16:29Z")

</div>

Look at the code below. I want to pull the values that are in **xyz** column of **abc** table into the **os** variable. The **db** is connected through **connection.php.**

I need the php code for **$os** , presently it is **$os= array(“11”, “18”, “22”, “27”);**

here is the full code:

* * *

\<?php  
include “connection.php”;  
//This gets today’s date  
$date =time () ;  
//This puts the day, month, and year in seperate variables  
$day = date(‘d’, $date) ;  
$month = date(‘m’, $date) ;  
$year = date(‘Y’, $date) ;  
//Here we generate the first day of the month  
$first\_day = mktime(0,0,0,$month, 1, $year) ;  
//This gets us the month name  
$title = date(‘F’, $first\_day) ;  
//Here we find out what day of the week the first day of the month falls on  
$day\_of\_week = date(‘D’, $first\_day) ;  
//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero  
switch($day\_of\_week){  
case “Sun”: $blank = 0; break;  
case “Mon”: $blank = 1; break;  
case “Tue”: $blank = 2; break;  
case “Wed”: $blank = 3; break;  
case “Thu”: $blank = 4; break;  
case “Fri”: $blank = 5; break;  
case “Sat”: $blank = 6; break;  
}  
//We then determine how many days are in the current month  
$days\_in\_month = cal\_days\_in\_month(0, $month, $year) ;  
//Here we start building the table heads  
echo “\<table border=1 width=294\>”;  
echo “\<tr\>\<th colspan=7\> $title $year \</th\>\</tr\>”;  
echo “\<tr\>\<td width=42\>S\</td\>\<td width=42\>M\</td\>\<td width=42\>T\</td\>\<td width=42\>W\</td\>\<td width=42\>T\</td\>\<td width=42\>F\</td\>\<td width=42\>S\</td\>\</tr\>”;  
//This counts the days in the week, up to 7  
$day\_count = 1;  
echo “\<tr\>”;  
//first we take care of those blank days  
while ( $blank \> 0 )  
{  
echo “\<td\>\</td\>”;  
$blank = $blank-1;  
$day\_count++;  
}  
//sets the first day of the month to 1  
$day\_num = 1;  
$today = date(j);  
$os = array(“11”, “18”, “22”, “27”);

//count up the days, untill we’ve done all of them in the month  
while ( $day\_num \<= $days\_in\_month )  
{

if (in\_array($day\_num, $os))  
{  
$bg =“cccccc”;  
}  
elseif ($day\_num\<=$today)  
{  
$bg =“cccccc”;  
}  
else  
{  
$bg = “”;  
}  
echo “\<td bgcolor=$bg\> $day\_num \</td\>”;  
$day\_num++;  
$day\_count++;  
//Make sure we start a new row every week  
if ($day\_count \> 7)  
{  
echo “\</tr\>\<tr\>”;  
$day\_count = 1;  
//}  
}  
}  
//Finaly we finish out the table with some blank details if needed  
while ( $day\_count \>1 && $day\_count \<=7 )  
{  
echo “\<td\> \</td\>”;  
$day\_count++;  
}  
echo “\</tr\>\</table\>”;  
?\>
