My page loads a random background image every time it loads:
<?php
$input = array(1, 2, 3, 4, 5, 6, 7, 8);
$num = array_rand($input, 1);
$bg = "img/bg" . $num . ".jpg";
?>
But I want it to do that only once. I want the image to remain the same after a visitor submits a form, for example, thereby reloading the page.
I've tried if($bg=NULL) etc, but to no avail - I guess $bg becomes null again every time the page reloads.
Many thanks in advance!
You can use Session variable or cookies if is not set, you choose a background, if is set, you do nothing
Got it (thanks to Ricardo):
<?php
session_start();
if (!isset($_SESSION['num'])) {
$input = array(1, 2, 3, 4, 5, 6, 7, 8);
$_SESSION['num'] = array_rand($input, 1);
}
$bg = "img/bg" . $_SESSION['num'] . ".jpg";
?>
Related
I am trying to load an image from oracle database Blob file. To load image i am using the following code
$COM_CODE = 'O003';
$sql = 'select DIGI_SIGN from LC_BLOCK_LIST_TECH_PERS where COM_CODE :COM_CODE';
$s = oci_parse ($c, $sql);
oci_bind_by_name($s, ':COM_CODE', $COM_CODE);
oci_execute($s, OCI_NO_AUTO_COMMIT);
$arr = oci_fetch_assoc($s);
$result = $arr['DIGI_SIGN']->load();
$pdf->Cell(40,5,$result,0,1,'L',0);
Nedd to show the image in a cell. In last cell i am not able to show the image instead binary value shows up.
what am i doing wrong here?
from here, it looks like you need to first create a file, then use standard procedure to write the image to the pdf:
$result = $arr['DIGI_SIGN']->load();
// Here: new question: [php] how to write image file from Oracle BLOB?
// $result goes to a file on server: "/var/appli/img/products/image1.jpg"
$image1 = "/var/appli/img/products/image1.jpg";
$pdf->Cell( 40, 5, $pdf->Image($image1, $pdf->GetX(), $pdf->GetY(), 30), 0, 1, 'L', 0);
Hope it helps.
I have a QTableWidget filled with different QWidgets such that whenever I get a message from the server to add/update them I do so like this:
ui->tableWidget->setRowCount(data.count());
ui->tableWidget->setCellWidget(data.count() - 1, 0, new QCheckBox("Enabled"));
ui->tableWidget->setCellWidget(data.count() - 1, 1, new QLineEdit("ADD" ));
ui->tableWidget->setCellWidget(data.count() - 1, 2, new QComboBox( ));
ui->tableWidget->setCellWidget(data.count() - 1, 3, new QLineEdit("232434" ));
ui->tableWidget->setCellWidget(data.count() - 1, 4, new QComboBox( ));
Then with those widgets I signal/slot connect them in the next method like this:
for (int i = 0; i < TW_CNT; i++)
{
connect(((QComboBox*)ui->tableWidget->cellWidget(cnt, i)), SIGNAL(currentIndexChanged(int)), this, SLOT(cboxchanged(int)));
if( i == 0)
{
//stuff
connect((QCheckBox*)ui->tableWidget->cellWidget(cnt, i), SIGNAL(stateChanged(int)), this, SLOT(checkchanged(int)));
}
if( i == 1)
{
//stuff
connect(((QComboBox*)ui->tableWidget->cellWidget(cnt, i)), SIGNAL(currentIndexChanged(int)), this, SLOT(cboxchanged(int)));
connect(((QComboBox*)ui->tableWidget->cellWidget(cnt, i)), SIGNAL(currentTextChanged(QString)), this, SLOT(cboxedited(QString)));
}
//....
}
Later when I want to remove stuff from tableWidget, I do so by calling removeRow on the row I no longer need. The issue here is that these widgets still seem to stay children of the ui->tableWidget->viewport() and they never get deleted even if I call ->deleteLater() on them. Deleting them with delete just causes my program to crash, and adding more rows after each row removal is causing my memory usage to skyrocket.
I've been stuck on this for a few days, so any help is appreciated!
currently i using multiple datepicker (http://keith-wood.name/datepick.html). I need to pass dates from MySQL table with PHP (reservations) to calendar and change CSS style for show state.
occupied - red
pending - yellow
free - grey
preview on another site: http://www.chata-vysocina.eu/en/rezervace/
Anyone have some tips how to do that?
Thank you,
Tomas
Ok, i resolved my problem with following lines.
<script>
var dates = [
[2013, 12, 24],
[2013, 12, 25]
];
var today = new Date();
$('#reserve').multiDatesPicker({
firstDay: 1,
numberOfMonths: 4,
dateFormat: "dd-mm-yy",
altField: '#dates',
minDate: 0,
beforeShowDay: function (date){
var year = date.getFullYear(), month = date.getMonth(), day = date.getDate();
// see if the current date should be highlighted
for (var i=0; i < dates.length; ++i)
if (year == dates[i][0] && month == dates[i][1] - 1 && day == dates[i][2])
return [false, 'booked'];
return [false];
}
});
</script>
The idea is quite simple: I have 2 comboboxes. The second one should refreseh its values depending on the chose from the first one.
# combobox 1:
$shape = TkVariable.new
$combobox_1 = Tk::Tile::Combobox.new(parent) { textvariable $shape; values ['IPE', 'HEA']}
# combobox 2:
$size = TkVariable.new
$combobox_2 = Tk::Tile::Combobox.new(parent) { textvariable $size; values $size_list}
# action
$combobox_1.bind("<ComboboxSelected>") {
case $shape
when 'IPE' then $size_list = [80, 100, ...]
when 'HEA' then $size_list = [90, 130, ...]
end
}
But nothing happens. combobox 2 doesn't seem to realize that its values have been changed. how can I solve this problem?
This will not work, you used this variable to create the combo box, but changing it will not change the combobox.
I suppose what you are looking for is set
when 'IPE' then $combobox_2.values([80, 100, ...])
I have a problem with using use_page_numbers config set to true in my pagination class!
When I click on the link of page 2, the number of rows it retrieves from database is correct, but the problem is that:
the first row of page 2 is the third row of page one ! It means that page 2 starts with the same row from the database which has been retrieved in the first page in the third row. for example :
Page 1: 10, 11, 12, 13, 14
Page 2: 12, 13, 14, 15, 16
and of course the page 3 starts from the second row of page 2 :
Page 3: 13, 14, 15, 16, 17
This is the code I have :
function get_brands_list($options = array())
{
//Pagination config
$config['base_url'] = base_url() . 'admin/brands/page/';
$config['total_rows'] = $this->db->get('mg_brands')->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 4;
$config['uri_segment'] = 4;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$offset = $this->uri->segment(4, 0);
$this->db->order_by('brand_Sort', 'ASC');
$query = $this->db->get('mg_brands', $config['per_page'], $offset);
if(isset($options['brand_Id']) || isset($options['brand_Name']))
return $query->row(0);
return $query->result();
}
You have a problem in calculation of offset variable.... Try this one:
$page_num = $this->uri->segment(4, 0);
$offset = ($page_num - 1) * $config['per_page'];