I'm using the couch calendar, but I need to populate it with data from another table (fortunately in the same database). I got it to work, but it loads very slowly. I think it's because I connect and disconnect to the database for each day of the month. I thought I'd be smart and pull the first part of the code (to connect) out of the days loop, but I get an error. Also, since couch is already logging into the database, do I even need to do it here again?
This code works:
But if I split my php/mysql code, I get this error:
Here is the code where I get the error:
This code works:
- Code: Select all
<cms:calendar >
<table class="calendar_big">
<tr>
<th colspan="7"><cms:date k_calendar_date format='F Y' /></th>
</tr>
<tr>
<cms:repeat count='7'>
<td class="months_heading"><cms:zebra 'Su' 'M' 'T' 'W' 'Th' 'F' 'S'/></td>
</cms:repeat>
</tr>
<cms:weeks>
<tr>
<cms:days >
<cms:if k_timeline_position='present'>
<cms:set tdclass='today' />
<cms:else />
<cms:set tdclass='' />
</cms:if>
<cms:if k_position='current_month' >
<td class='<cms:show tdclass />' >
<cms:else />
<td class='other_month'>
</cms:if>
<cms:show k_day />
<br />
<cms:php>
$servername = 'mysql.wwwwwwww.com';
$username = 'xxxxxxx';
$password = 'yyyyyy';
$dbname = 'zzzzzzz';
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Database csr_scheule Connection failed: " . $conn->connect_error);
}
$sql = 'SELECT * FROM csr_schedule WHERE idate = "<cms:show k_date />"';
$result = $conn->query($sql);
if ($result->num_rows > 0) { // output data of each row
while($row = $result->fetch_assoc()) {
echo $row["idesc"];
}
}
$conn->close();
</cms:php>
</td>
</cms:days>
</tr>
</cms:weeks>
</table>
</cms:calendar>
But if I split my php/mysql code, I get this error:
- Code: Select all
Fatal error: Call to a member function query() on a non-object in /home/uniguy/skintown.com/couch/tags.php(2866) : eval()'d code on line 3
Here is the code where I get the error:
- Code: Select all
<cms:calendar >
<cms:php>
$servername = 'mysql.wwwwwwww.com';
$username = 'xxxxxxx';
$password = 'yyyyyy';
$dbname = 'zzzzzzz';
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Database csr_scheule Connection failed: " . $conn->connect_error);
}
</cms:php>
<table class="calendar_big">
<tr>
<th colspan="7"><cms:date k_calendar_date format='F Y' /></th>
</tr>
<tr>
<cms:repeat count='7'>
<td class="months_heading"><cms:zebra 'Su' 'M' 'T' 'W' 'Th' 'F' 'S'/></td>
</cms:repeat>
</tr>
<cms:weeks>
<tr>
<cms:days >
<cms:if k_timeline_position='present'>
<cms:set tdclass='today' />
<cms:else />
<cms:set tdclass='' />
</cms:if>
<cms:if k_position='current_month' >
<td class='<cms:show tdclass />' >
<cms:else />
<td class='other_month'>
</cms:if>
<cms:show k_day />
<br />
<cms:php>
$sql = 'SELECT * FROM csr_schedule WHERE idate = "<cms:show k_date />"';
$result = $conn->query($sql);
if ($result->num_rows > 0) { // output data of each row
while($row = $result->fetch_assoc()) {
echo $row["idesc"];
}
}
</cms:php>
</td>
</cms:days>
</tr>
</cms:weeks>
</table>
<cms:php>
$conn->close();
</cms:php>
</cms:calendar>