I am trying to fetch a row from a table in my database, and everything is retrieved successfully except for one column (page_content), whose data comes in partially. Here is the table creation code:
CREATE TABLE 'usol_site_page' (
'page_id' int(11) NOT NULL auto_increment,
'page_type_id' int(11) NOT NULL,
'page_menu_id' int(11) NOT NULL,
'page_name' varchar(100) NOT NULL,
'page_link' varchar(100) NOT NULL,
'page_heading' varchar(255) default '',
'page_content' text,
'page_title' varchar(255) default NULL,
'meta_keywords' mediumtext,
'keyword_description' text,
'pic_small' varchar(255) default NULL,
'pic_main' varchar(255) default NULL,
'pic_size' varchar(50) default NULL,
'pic_type' varchar(50) default NULL,
'display_order' int(11) NOT NULL,
'parent_page_id' int(11) NOT NULL,
'status' varchar(20) NOT NULL,
'creation_date' date NOT NULL,
'last_update_date' date NOT NULL,
PRIMARY KEY ('page_id'),
KEY 'Refusol_page_menu60' ('page_menu_id'),
KEY 'Refusol_page_type44' ('page_type_id'),
CONSTRAINT 'Refusol_page_menu60' FOREIGN KEY ('page_menu_id') REFERENCES 'usol_page_menu' ('page_menu_id') ON DELETE CASCADE,
CONSTRAINT 'Refusol_page_type44' FOREIGN KEY ('page_type_id') REFERENCES 'usol_page_type' ('page_type_id') ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=67 DEFAULT CHARSET=latin1
Does anyone know why page_content is not being fully retrieved?
here is the code the query :
$extendQry = "";
if($mode != "admin"){
$extendQry = "AND p.status='enable' ";
}
$qry = "SELECT p.page_id, p.page_link, p.page_name, p.page_heading, p.page_content, p.status, p.page_title,
p.meta_keywords, p.keyword_description, p.pic_main, p.pic_small, p.parent_page_id,
t.page_type_id, t.page_type, m.page_menu_id, m.menu_type
FROM usol_site_page p, usol_page_type t , usol_page_menu m
WHERE p.page_id = ".$pageId." $extendQry
AND t.page_type_id = p.page_type_id
AND m.page_menu_id = p.page_menu_id";
$result = mysql_query($qry);
return mysql_fetch_row($result);
fellas thank you very much for your quick responce sorry for my very unclear question, i got it solved by changing datatype of the column (page_content) from 'text' (64KB) to mediumtext(16MB). and it is working perfectly now. thank you all for your kind support you guyz are the best.
Related
Here is the structure of the database tables in quesiton.
Officials:
CREATE TABLE IF NOT EXISTS `officials` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`last` varchar(250) NOT NULL DEFAULT '',
`first` varchar(250) NOT NULL DEFAULT '',
`middle` varchar(250) NOT NULL DEFAULT '',
`address` varchar(250) NOT NULL DEFAULT '',
`city` varchar(250) NOT NULL DEFAULT '',
`state` varchar(250) NOT NULL DEFAULT '',
`zip` varchar(250) NOT NULL DEFAULT '',
`homeph` varchar(250) NOT NULL DEFAULT '',
`workph` varchar(250) NOT NULL DEFAULT '',
`cellph` varchar(250) NOT NULL DEFAULT '',
`main_phone` varchar(10) DEFAULT NULL,
`email` varchar(250) NOT NULL DEFAULT '',
`notes` text NOT NULL,
`blockreg` varchar(10) NOT NULL,
`inactive` varchar(10) NOT NULL,
`gender` varchar(100) NOT NULL,
`minority` varchar(100) NOT NULL,
`affiliate` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Is affiliate official? 0 = no. 1 = yes.',
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=14506 DEFAULT CHARSET=latin1;
Transactions (edited from original post to show foreign key constraints):
CREATE TABLE IF NOT EXISTS `transactions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`offid` int(11) NOT NULL,
`txn_id` varchar(64) NOT NULL,
`txn_time` varchar(24) NOT NULL,
`approval_code` varchar(24) DEFAULT NULL,
`amount` varchar(8) NOT NULL,
`result_message` varchar(100) NOT NULL,
`ch_phone` varchar(10) NOT NULL COMMENT,
`ch_card_type` varchar(4) NOT NULL,
`ch_address` varchar(50) NOT NULL,
`ch_state` varchar(15) NOT NULL,
`ch_last_name` varchar(50) NOT NULL,
`ch_email` varchar(100) NOT NULL,
`ch_zip` varchar(10) NOT NULL,
`ch_exp_date` varchar(4) NOT NULL,
`ch_city` varchar(50) NOT NULL,
`ch_first_name` varchar(30) NOT NULL,
`ch_transaction_type` varchar(15) NOT NULL,
`ch_card_number` varchar(18) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `txn_id` (`txn_id`) USING BTREE,
KEY `offid` (`offid`)
) ENGINE=InnoDB AUTO_INCREMENT=72 DEFAULT CHARSET=utf8mb4;
ALTER TABLE `transactions`
ADD CONSTRAINT `transactions_ibfk_1` FOREIGN KEY (`offid`) REFERENCES `officials` (`id`);
Transaction details (edited from original post to show foreign key constraints):
CREATE TABLE IF NOT EXISTS `transaction_details` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`xact_id` varchar(64) NOT NULL,
`detail_amount` float(5,2) NOT NULL,
`sport` varchar(10) NOT NULL,
`regyr` varchar(250) NOT NULL,
PRIMARY KEY (`id`),
KEY `xact_id` (`xact_id`)
) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8mb4;
ALTER TABLE `transaction_details`
ADD CONSTRAINT `transaction_details_ibfk_1` FOREIGN KEY (`xact_id`) REFERENCES `transactions` (`txn_id`) ON DELETE CASCADE ON UPDATE CASCADE;
Code that executes upon receiving the data from the credit card company where rows are inserted into the table:
// this creates the main transaction
$sql = "INSERT INTO transactions (offid, txn_id, txn_time, approval_code, amount, result_message, ch_phone,
ch_card_type, ch_address, ch_state, ch_last_name, ch_email, ch_zip, ch_exp_date, ch_city, ch_first_name,
ch_transaction_type, ch_card_number) VALUES ('$offid', '$txn_id', '$txn_time', '$approval_code', '$amount', '$result_message',
'$ch_phone', '$ch_card_type', '$ch_address', '$ch_state', '$ch_last_name', '$ch_email',
'$ch_zip', '$ch_exp_date', '$ch_city', '$ch_first_name', '$ch_transaction_type', '$ch_card_number')";
$result = mysqli_query($conn, $sql);
// this creates the detail transactions
if ($ssl_result == 0) {
$detail_sports = array('fb', 'vb', 'sb', 'bb', 'wr', 'sw', 'so', 'ba', 'tr');
foreach ($detail_sports as $sport) {
$var = $sport . 'total';
// cookie is set for fbtotal, vbtotal, etc. with an amount for that line item
if (isset($_COOKIE[$var])) {
$detail_amount = $_COOKIE[$var];
$sql = "INSERT INTO transaction_details (xact_id, detail_amount, sport, regyr) VALUES ('$txn_id', '$detail_amount', '$sport', '$regyear')";
$result = mysql_query($sql);
}
}
}
The transaction table has id numbers 1, 2, 3, 5, 6, 8, 9, 11, 12, 13, 15, 16, 17, etc. These should be consecutively numbered, but they aren't. It's almost as if they were written to the transaction (parent) table and then deleted. But the code doesn't delete a record.
The transaction detail table has a many-to-one relationship with transaction and all of its records contain consecutive ids.
Any idea what's going on?
I am working on creating table in to my database with mysql and here is my code:
mysqli_query($link, "CREATE TABLE IF NOT EXISTS `review` (
`clients_id` int(15) NOT NULL AUTO_INCREMENT,
`client_id` varchar(150) NOT NULL DEFAULT '',
`rating` tinyint(2) NOT NULL DEFAULT '0',
`proj_date` date NOT NULL DEFAULT '0000-00-00',
`proj_desc` text NOT NULL DEFAULT '',
`photoname` text NOT NULL,
`companyname` text NOT NULL,
`feedback` text NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '0',
`emailid` varchar(100) NOT NULL DEFAULT '',
`customratings` varchar(100) NOT NULL DEFAULT '',
`photo_option` varchar(100) NOT NULL DEFAULT '',
`title` varchar(100) NOT NULL DEFAULT '',
`citation` varchar(100) NOT NULL DEFAULT '',
`date_option` varchar(100) NOT NULL DEFAULT '',
`rating_option` varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (`clients_id`),
FULLTEXT KEY `feedback` (`feedback`)
) ENGINE=MyISAM AUTO_INCREMENT=1") or mysqli_error($link);
But this is not reflecting into my database ? Why were I may be going wrong ?
but I tried creating other table with the following code
mysqli_query($link, "CREATE TABLE IF NOT EXISTS `setting` (
`id` int(11) NOT NULL auto_increment,
`script_url` text NOT NULL,
`date` varchar(4) NOT NULL,
`rateing` varchar(4) NOT NULL,
`photo` varchar(4) NOT NULL,
`dateformat` varchar(4) NOT NULL,
`page_limit` int(4) NOT NULL,
`proj_desc` varchar(4) NOT NULL,
`companyname` varchar(4) NOT NULL,
`text_color` varchar(255) NOT NULL,
`citation_color` varchar(255) NOT NULL,
`bg_color` varchar(255) NOT NULL,
`border_color` varchar(255) NOT NULL,
`ratingsformat` varchar(250) NOT NULL,
`rating` varchar(250) NOT NULL,
`customratings` varchar(250) NOT NULL,
`speed` varchar(250) NOT NULL,
`pagination` varchar(250) NOT NULL,
`version` varchar(250) NOT NULL,
`global_option` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0;
") or mysqli_error($link);
it is being created correctly and both the tables are in the same file
No you cannot create table using an insert statement.
There are four types of SQL statements:
DML (DATA MANIPULATION LANGUAGE)
DDL (DATA DEFINITION LANGUAGE)
DCL (DATA CONTROL LANGUAGE)
TCL (TRANSACTION CONTROL LANGUAGE)
DML is your SELECT, INSERT, UPDATE and DELETE statements...
DDL is you your CREATE, ALTER and DROP statements.
See more info about types of SQL statements
In order to insert data in your table, first you need to create it.
How to create sql table from php
No. "INSERT INTO" used to insert the data to existing table only.You should create the table with respective column before try to insert the values.
Or you can check the table exist or not before going insert."If exists" u can insert the value else just create and insert the values.
This worked for me but I don't know how?
I just removed DEFAULT '' present while creating review table and table just got created
Here is edited code
mysqli_query($link, "CREATE TABLE IF NOT EXISTS `review` (
`clients_id` int(15) NOT NULL AUTO_INCREMENT,
`client_id` varchar(150) NOT NULL,
`rating` tinyint(2) NOT NULL,
`proj_date` date NOT NULL,
`proj_desc` text NOT NULL,
`photoname` text NOT NULL,
`companyname` text NOT NULL,
`feedback` text NOT NULL,
`status` tinyint(1) NOT NULL,
`emailid` varchar(100) NOT NULL,
`customratings` varchar(100) NOT NULL,
`photo_option` varchar(100) NOT NULL,
`title` varchar(100) NOT NULL,
`citation` varchar(100) NOT NULL,
`date_option` varchar(100) NOT NULL,
`rating_option` varchar(100) NOT NULL,
PRIMARY KEY (`clients_id`),
FULLTEXT KEY `feedback` (`feedback`)
) ENGINE=MyISAM AUTO_INCREMENT=1") or mysqli_error($link);
So I'm running a PDO update working, and for some reason it won't update the table...
$business_id = 9874128;
$hidden = 1;
$query = "UPDATE business_property_overrides SET hidden=? WHERE business_id=?";
try {
$stmt = $pdo->prepare($query);
$stmt->execute(array($business_id, $hidden));
}
For some reason this won't update, even though I get no errors. The existing tables schema looks like this, and the data is:
There is an existing data set with business_id = 9874128 and hidden set to 0, but it won't update when I run the above code.
CREATE TABLE `business_property_overrides` (
`business_id` int(11) NOT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(512) NOT NULL,
`apt_type` varchar(25) DEFAULT NULL,
`apt_num` varchar(9) DEFAULT NULL,
`street_address` varchar(255) DEFAULT NULL,
`city` varchar(255) DEFAULT NULL,
`state` varchar(255) DEFAULT NULL,
`zip` varchar(25) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`url` varchar(512) DEFAULT NULL,
`hours` varchar(100) DEFAULT NULL,
`openhours` varchar(100) DEFAULT NULL,
`location` point DEFAULT NULL,
`yelp` varchar(512) DEFAULT '0',
`twitter` varchar(512) DEFAULT '0',
`hidden` tinyint(1) DEFAULT '0',
`merged` int(11) DEFAULT NULL,
`closed` tinyint(1) DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `business_id` (`business_id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9874134 DEFAULT CHARSET=utf8;
The hidden is TINYINT 1 characters long, you are assigning it business_id which is 7 characters long, that is the error.
Change
$stmt->execute(array($business_id, $hidden));
To:
$stmt->execute(array($hidden,$business_id))
As I've already commented over here, or you can simply use the placeholders of taking no care about the occurence like as
$query = "UPDATE business_property_overrides SET hidden = :hidden WHERE business_id = :business_id";
try {
$stmt = $pdo->prepare($query);
$stmt->execute(array(":business_id" => $business_id, ":hidden" => $hidden));
}
I have a lead table that contains data which also contains information which user has entered this data. Now I want to create a filter that when selecting a particular user only his data is displayed. How to do this in cakephp. Please help.
Thanks in advance
User database
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`fname` varchar(100) DEFAULT NULL,
`lname` varchar(100) DEFAULT NULL,
`username` varchar(100) NOT NULL,
`password` varchar(50) NOT NULL,
`email` varchar(100) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`role` varchar(100) NOT NULL,
`created` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
lead table
CREATE TABLE IF NOT EXISTS `leads` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`account_id` int(11) NOT NULL,
`name` varchar(200) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`board_number` varchar(11) DEFAULT NULL COMMENT 'board number',
`mobile_number` varchar(11) DEFAULT NULL COMMENT 'mobile number',
`requirements` varchar(1000) DEFAULT NULL,
`total_price_quoted` int(11) DEFAULT NULL COMMENT 'total price quoted',
`our_price` int(11) DEFAULT NULL COMMENT 'our price',
`margin` int(11) DEFAULT NULL,
`closing_month` varchar(100) DEFAULT NULL COMMENT 'closing month',
`probablity` varchar(100) DEFAULT NULL,
`status_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`date_added` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;
Controller Code LeadController.php
public function user_filter() {
//$this->render('filter');
$this->loadModel('User');
$this->User->recursive = 0;
$userFilter = $this->User->find('all',array(
'fields' => array('User.username')
));
$this->set('userFilter', $userFilter);
return $userFilter;
}
// View/filterMenu.ctp
//here a dropdown menu of listed user
<?php
$userFilters = $this->requestAction(
array(
'controller' => 'leads',
'action' => 'user_filter'
)
);
?>
<ul class="dropdown-menu">
<?php foreach ($userFilters as $userFilter): ?>
<li>
<?php
echo $this->Html->link($userFilter['User']['username'],array(
'controller'=>'leads',
'action'=>'user_filter'
));
echo "<\n>";
?>
</li>
<?php endforeach; ?>
</ul
I want to create view of that particular user.
you cannot provide links through dropdown, you must use javascript to direct to page.
to display all the leads from particular user, pass the user id to the function and fetch data using user id.
public function user_filter($id = null) {
if ($id){
$leads = $this->Lead->find('all', array('conditions' => array('Lead.user_id' => $id)));
}else{
$leads = $this->Lead->find('all');
}
$this->loadModel('User');
$this->User->recursive = 0;
$userFilter = $this->User->find('all',array(
'fields' => array('User.username')
));
$this->set('leads', $leads);
$this->set('userFilter', $userFilter);
return $userFilter;
}
Hope this will help you.
I have got a problem with two tables:
CREATE TABLE IF NOT EXISTS `addresses` (
`adr_id` int(11) NOT NULL auto_increment,
`per_id` int(11) NOT NULL,
`adr_street` varchar(50) NOT NULL,
`adr_houseno` int(11) default NULL,
`adr_housenoadd` varchar(10) default NULL,
`adr_postalcode` varchar(25) NOT NULL,
`adr_city` varchar(20) NOT NULL,
`adr_type` varchar(45) default NULL,
`cnt_id` int(11) NOT NULL,
`adr_date` date default NULL,
`sys-mut-dt` timestamp NULL default NULL,
`sys-mut-user` varchar(20) default NULL,
`sys-mut-id` int(11) NOT NULL default '0',
PRIMARY KEY (`adr_id`),
KEY `per_id` (`per_id`),
KEY `cnt_id` (`cnt_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
--
-- RELATIES VOOR TABEL `addresses`:
-- `cnt_id`
-- `countries` -> `cnt_id`
-- `per_id`
-- `persons` -> `per_id`
--
CREATE TABLE `events` (
`evt_id` int(11) NOT NULL auto_increment,
`evt_name` varchar(50) NOT NULL,
`evt_description` varchar(100) default NULL,
`evt_startdate` date NOT NULL,
`evt_enddate` date default NULL,
`evt_starttime` time default NULL,
`evt_endtime` time default NULL,
`evt_amtpersons` int(11) default NULL,
`sts_id` int(11) NOT NULL,
`adr_id` int(11) default NULL,
`evt_amtPersonsSubs` tinyint(4) NOT NULL default '0',
`evt_photo` varchar(50) default NULL,
`sys-mut-dt` timestamp NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`sys-mut-user` varchar(20) default NULL,
`sys-mut-id` int(11) NOT NULL default '0',
PRIMARY KEY (`evt_id`),
KEY `sts_id` (`sts_id`),
KEY `adr_id` (`adr_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The problem is, when i try to delete a record from address table I get the following error
DELETE
FROM addresses
WHERE per_id = 45
1451 - Cannot delete or update a parent row: a foreign key constraint fails (`site/events`, CONSTRAINT `adr_id` FOREIGN KEY (`adr_id`) REFERENCES `addresses` (`adr_id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ;
The weird thing is that there is no record with the same per_id or adr_id in the events table.
So what's going on over here?
How Can I solve this? ;-)
/* I think it means "How can I solve this?" */
It may sound stupid, but are you absolutely sure there are no child rows?
Could you please run this:
SELECT e.*
FROM addresses a
JOIN events e
ON e.adr_id = a.adr_id
WHERE a.per_id = 45