PDO gather BLOB files - pdo

I'm trying to find a way to output whatever BLOB files are inserted into a silly database. In my code when I query the CV column I get all sorts of weird symbols. Can you guys please help me fix my code?
$crud->dataview($query);
}else{
$query = "SELECT id, from_unixtime(cheie_wp) as `datetime`, nume, prenume, email, telefon, oras, denumiri_job, cv FROM jobselection_data_old ORDER BY id DESC";
$records_per_page=10;
$newquery = $crud->paging($query,$records_per_page);
$crud->dataview($newquery);
public function dataview($query)
{
$stmt = $this->db->prepare($query);
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
$date_in = $row['datetime'];
$date_out = explode(' ', $date_in);
?>
<tr>
<td><?php echo $date_out[0]; ?></td>
<td><?php print($row['nume']); ?></td>
<td><?php print($row['prenume']); ?></td>
<td><?php print($row['email']); ?></td>
<td><?php print($row['telefon']); ?></td>
<td><?php print($row['oras']); ?></td>
<td><?php print($row['denumiri_job']); ?></td>
<td align="center"><?php
if($row['cv'] != NULL) { ?>
view
<?php }else{
echo '-';
}
?></td>
<td align="center">
<i class="glyphicon glyphicon-edit"></i>
</td>
<td align="center">
<i class="glyphicon glyphicon-remove-circle"></i>
</td>
</tr>
<?php
}
}else{ ... }
}
EDIT
I have modified my code and added view.php with this code:
if(isset($_GET['id']))
{
$stmt = $DB_con->prepare("SELECT cv FROM jobselection_data_old WHERE id=:id");
$stmt->execute(array(":id"=>$_GET['id']));
$stmt->bindColumn(1, $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
header('content-type: image/jpeg');
echo $lob;
}
?>
The problem is that it does not generate the image file I have uploaded to the database.
You can check it at https://ns.jobselection.ro/db/
user/pass: test
I added a screen capture of my database as well: https://ns.jobselection.ro/db/screen.png . I only added one row for testing purposes!

Wow, this is really weird. I found what the issue was. I had my require configuration files in a separate php block of code in the same file. Until I placed them both in the same block of code it did not work!

Related

Error number: 1052. Column 'id' in field list is ambigious

I am trying to make a pagination table in codeigniter using php and bootstrap. As far as i want to run my code in browser i face the error subscribed in the title. I would be very pleasant and grateful if anyone could help me. Here is my code.
employees_model.php
<?php
class employees_model extends CI_Model{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
//fetch department details from database
function get_employees_list($limit, $start)
{
$sql = 'select (id, employee_emer, mbiemer, adresa, email), department_emer from employee, department where department.id = employee.id_departament order by employee_emer limit ' . $start . ', ' . $limit;
$query = $this->db->query($sql);
return $query->result();
}
}
?>
employees.php
<?php
class employees extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->database();
$this->load->library('pagination');
//load the department_model
$this->load->model('employees_model');
}
public function index()
{
//pagination settings
$config['base_url'] = site_url('employees/index');
$config['total_rows'] = $this->db->count_all('employee');
$config['per_page'] = "5";
$config["uri_segment"] = 3;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = floor($choice);
//config for bootstrap pagination class integration
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
//call the model function to get the department data
$data['emplist'] = $this->employees_model->get_employees_list($config["per_page"], $data['page']);
$data['pagination'] = $this->pagination->create_links();
//load the department_view
$this->load->view('employees_view',$data);
}
}
?>
employees_view.php
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP CodeIgniter Pagination with Bootstrap Styles | Example</title>
<!--link the bootstrap css file-->
<link rel="stylesheet" href="<?php echo base_url("bootstrap/css/bootstrap.css"); ?>">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>Employee ID</th>
<th>Employee Number</th>
<th>Employee Name</th>
<th>Employee Surname</th>
<th>Employee Address</th>
<th>Employee Email</th>
</tr>
</thead>
<tbody>
<?php for ($i = 0; $i < count($emplist); ++$i) { ?>
<tr>
<td><?php echo ($page+$i+1); ?></td>
<td><?php echo $emplist[$i]->id; ?></td>
<td><?php echo $emplist[$i]->employee_emer; ?></td>
<td><?php echo $emplist[$i]->mbiemer; ?></td>
<td><?php echo $emplist[$i]->adresa; ?></td>
<td><?php echo $emplist[$i]->email; ?></td>
<td><?php echo $emplist[$i]->department_emer; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<?php echo $pagination; ?>
</div>
</div>
</div>
</body>
</html>
Please HELP ME. THANK YOU IN ADVANCE!
Try to alias Table names. check this
$sql = ' select employee.id, employee_emer, mbiemer, adresa, email, department_emer from employee, department
where department.id = employee.id_departament order by employee_emer limit ' . $start . ', ' . $limit;
Or
$sql = ' select e.id, employee_emer, mbiemer, adresa, email, department_emer
from employee e inner join department d on d.department.id = e.id_departament
order by employee_emer limit ' . $start . ', ' . $limit;

Auto Text field values from Database in yii

I have a form with fields like pincode,village,district etc. auto fill these values when I enter pincode. Please provide a sample code for achieving this.
thanks in advance.
<tr>
<div class="row">
<td><?php echo $form->labelEx($model,'pin'); ?></td>
<td><?php echo $form->textField($model,'pin',array('size'=>6,'maxlength'=>6,'style'=>'height:34px;')); ?>
<?php echo $form->error($model,'pin'); ?></td>
</div>
<tr>
<div class="row">
<td><?php echo $form->labelEx($model,'street'); ?></td>
<td><?php echo $form->textField($model,'street',array('size'=>25,'maxlength'=>25,'style'=>'height:34px;')); ?>
<?php echo $form->error($model,'street'); ?></td>
</div>
<tr>
<div class="row">
<td><?php echo $form->labelEx($model,'village'); ?></td>
<td><?php echo $form->textField($model,'village',array('size'=>25,'maxlength'=>25,'style'=>'height:34px;')); ?>
<?php echo $form->error($model,'village'); ?></td>
</div>
thanks in advance.
I am assuming your table name is areas, and Areas is Model for that table.
Bellow i am repeating(not exactly) view code from your question and i am attaching ajax call on your pincode field and class property on your other text fields.
<?php echo $form->labelEx($model,'pin'); ?>
<?php echo $form->textField($model,'pin',array(
'size'=>6,
'maxlength'=>6,
'style'=>'height:34px;',
//Ajax call to get the pin related values, onBlur.
'ajax' => array
(
'type' => 'POST',
'dataType'=>'JSON',
'url' => CController::createUrl('site/getValuesByPincode'),
'success'=>'js:function(output){$(".setVillage").val(output.village); $(".setStreet").val(output.street);}'
)
)); ?>
<?php echo $form->error($model,'pin'); ?>
<br/><br/>
<?php echo $form->labelEx($model,'street'); ?>
<?php
//adding a class
echo form->textField($model,'street',array('size'=>25,'maxlength'=>25,'style'=>'height:34px;','class'=>'getStreet'));
?>
<?php echo $form->error($model,'street'); ?>
<br/><br/>
<?php echo $form->labelEx($model,'village'); ?>
<?php
//Ading a class
echo $form->textField($model,'village',array('size'=>25,'maxlength'=>25,'style'=>'height:34px;','class'=>'getVillage'));
?>
<?php echo $form->error($model,'village'); ?>
And i am creating an action getValuesByPincode in my controller(ex: site controller) to serve my ajax call.
public function actionGetValuesByPincode()
{
$pincode = $_POST['Areas']['pin'];
$data = Areas::model()->find('pin=:pin', array(':pin' => $pincode));
$output = array();
if (count($data) > 0)
{
$output['village'] = $data->village;
$output['street'] = $data->street;
echo json_encode($output);
}
}

How to make this SELECT query sort alphabetically. Drop down menu. Order by

I have this query
`$optnamear = tep_db_query("SELECT `products_options_values_name` from `products_options_values` WHERE `products_options_values_id`='$id[products_options_values_id]' ") ;`
And I want it to sort the products_options_values_name in the drop down menu alphabetically. How do I do this?
I have been trying to use "order by" but I am clueless about it, any help appreciated
this is the all the code if its needed? Like I said, clueless....
$mainhtml = ""; //the var to hold all of the html
foreach ( $opts as $opt => $name) {
unset($html);
$html = "<tr><td width='125px'>
$name
</td></tr>
<tr><td>
<SELECT name='$opt' onchange='document.m_srch.submit();'>
<OPTION value='not'>---</OPTION>";//print the name of the box and start the drop down
$sql = "SELECT `products_options_values_id` from `products_options_values_to_products_options` WHERE `products_options_id`='$opt'";
$res = tep_db_query($sql);// get the values of all the options for that catagory
while($id = tep_db_fetch_array($res)){
$optnamear = tep_db_query("SELECT `products_options_values_name` from `products_options_values` WHERE `products_options_values_id`='$id[products_options_values_id]' ") ;
$optname = tep_db_fetch_array($optnamear);
//create the dropdown
$html .= "<OPTION value='$id[products_options_values_id]' ";
if($_GET[$opt] == $id['products_options_values_id']){
$html .= "selected='selected'"; // if the product has already been selected keep it selected!
}
$html .= ">$optname[products_options_values_name]</OPTION>";
}
$mainhtml .= $html."</SELECT></td></tr>";
}
echo "<tr><td>
<table border='0' width='100%' cellspacing='0' cellpadding='0'>
<tr>
<td height='14' class='infoBoxHeading'><img src='images/infobox/corner_left.gif' border='0' alt='' width='11' height='14'></td>
<td width='100%' height='14' class='infoBoxHeading'>$heading</td>
</tr>
</table>
<table border='0' width='100%' cellspacing='0' cellpadding='1' class='infoBox'>
<tr><td>
<table class='infoBoxContents'>
<FORM name='m_srch' action='advanced_search_result.php' method='get'>
<INPUT type='hidden' value='1' name='m_op'> <INPUT type='hidden' value='1' name='keywords'> \n
$mainhtml
</table>
</td></tr>
</FORM>
</table>
</td></tr>";
?>
Use a join in your query.
SELECT products_options_values_id, products_options_values_name
FROM products_options_values_to_products_options
INNER JOIN products_options_values
ON products_options_values.products_options_values_id = products_options_values_to_products_options.products_options_values_id
WHERE products_options_values_to_products_options.products_options_id='$opt'
ORDER BY products_options_values.products_options_values_name
And iterate on this.
Instead of:
SELECT products_options_values_id
from products_options_values_to_products_options
WHERE products_options_id='$opt'`
and then iterating
SELECT products_options_values_name
from products_options_values
WHERE products_options_values_id='$id[products_options_values_id]

php mysql database not updating

can you check my code..my database wont update....when you click the confirm user..the database is not updating..i need help..please
<?php
include('connection.php');
if(isset($_POST['id']))
{
if($_POST['status']=='confirmed')
{
$uid=$_POST['id'];
$sql_update=mysql_query("UPDATE `tmc` SET `status`='confirmed' WHERE (`mem_id`='$uid')");
}
}
$sql=mysql_query("SELECT * FROM member WHERE status='pending'");
echo "<table>";
while($result=mysql_fetch_array($sql))
{
$id=$result['mem_id'];
$username=$result['username'];
echo "<tr>
<td>
".$id."
</td>
<td>
".$username."
</td>
<td>
<a href='?id=".$id."&status='confirmed''>Confirm User</a>
</td>
</tr>";
}
?>
Try this:
....
if(isset($_GET['id']))
{
if($_GET['status']=='confirmed')
{
$uid=$_GET['id'];
$sql_update=mysql_query("UPDATE `tmc` SET `status`='confirmed' WHERE (`mem_id`='$uid')");
}
}
....

Simple Pie "set_item_limit" doesn't

I'm struggling to get set_item_limit to work. The feed comes in fine, but just renders every post. Here's the code I'm using:
// Make sure SimplePie is included. You may need to change this to match the location of autoloader.php
// For 1.0-1.2:
#require_once('../simplepie.inc');
// For 1.3+:
require_once('php/autoloader.php');
// process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process. http://simplepie.org/blog/feed/
$feed->set_feed_url('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=Tweet_Yourself');
// Run SimplePie.
$feed->set_item_limit(5);
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
And here's the HTMLy bit:
<?php
//loop through all of the items in the feed, and $item represents the current item in the loop.
foreach ($feed->get_items() as $item): ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" align="left"><img src="sitewise/Tweet_Yourself_avatar.gif" alt="TweetYourself Twitter Feed" /></td>
<td>
<div class="item">
<h3><i><?php echo $item->get_title(); ?></i></h3>
<?php echo $item->get_description(); ?>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
<hr />
</div>
</td>
</tr>
</table>
<?php endforeach; ?>
The table isn't the issue!
Any ideas?
The issue is
$feed->set_item_limit(5);
Is for merging feeds and not for a single feed.... you need to
change
foreach ($feed->get_items() as $item): ?>
to
foreach ($feed->get_items(0, 5) as $item): ?>
This would limit it to 5 items
SimplePIE Get_ITEMS