I have an excel file that have first data in cell B4, this is the first of the content area. The content area range is B4:D9.
How can I get the B4?
I used this code but it is not getting the b4,
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$data = array();
$highestNum = 0;
for ($row = 1; $row <= $highestRow; $row++){
$data[] = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
"",
TRUE,
FALSE);
$columns[] = PHPExcel_Cell::stringFromColumnIndex($row-1);
$highestNum = $row;
}
Related
I'm trying to insert a new table row into a custom wpdb table. The data is coming from a form posted to a script.
I'm declaring global $wpdb at the start of the script, and inserting into the db, but for some reason it doesn't like the query function, which WordPress recommends to use in the codex.
i got this error Fatal error: Call to a member function query()
this is my code:
<?php
global $wpdb;
if($_POST){
$post_id = $_POST['post_id'];
$name = $_POST['name'];
$email = $_POST['email'];
$city = $_POST['city'];
$tell = $_POST['tell'];
$date_m = $_POST['date_m'];
$date_y = $_POST['date_y'];
$consent = $_POST['consent'];
$check_error = 0;
if (!isset($name) || $name == ''){
echo "empty";
$check_error = 1;
}
elseif (!isset($email) || $email == ''){
echo "empty";
$check_error = 1;
}
$name = mysql_real_escape_string($name);
$email = mysql_real_escape_string($email);
$city = mysql_real_escape_string($city);
$tell = mysql_real_escape_string($tell);
$date_m = mysql_real_escape_string($date_m);
$date_y = mysql_real_escape_string($date_y);
$consent = mysql_real_escape_string($consent);
$query = "INSERT INTO {$wpdb->prefix}kishvote SET ";
$query .= "post_id = '" . $post_id . "', ";
$query .= "date_timevote = '" . date( 'Y-m-d H:i:s' ) . "', ";
$query .= "u_name = '" . $name . "', ";
$query .= "u_city = '" . $city . "', ";
$query .= "u_mail = '" . $email . "', ";
$query .= "u_tell = '" . $tell . "', ";
$query .= "date_m = '" . $date_m . "', ";
$query .= "date_y = '" . $date_y . "', ";
$query .= "consent = '" . $consent . "', ";
$success = $wpdb->query( $query );
if ($success) {
$error = 0;
echo "submit";
} else {
$error = 1;
echo 'eror dade';
}
}
?>
I have a very simple custom report in Google Analytics that lists Date, Visits, Unique Visitors and Pageviews for a certain month.
I am trying to duplicate this very simple report using GAPI, but I cannot find a simple way to add Unique Visitors to my table.
See my code below. How can I modify this code to show Unique Visitors?
$profile_id = "xxxxxxxx";
$report_id = "xxxxxxxx";
$dimensions = array('date');
$metrics = array('pageviews','visits');
$sort_metric = array('date');
$filter = null;
$start_date = '2013-02-01';
$end_date = '2013-02-28';
$start_index = 1;
$max_results = 10000;
echo '<table>';
echo '<tr>';
echo '<th>Date</th>';
echo '<th>Visits</th>';
echo '<th>Unique Visitors</th>';
echo '<th>Page Views</th>';
echo '</tr>';
$ga = new gapi('xx#xxxxxxxxx.com','xxxxxxxx');
$ga->requestReportData($profile_id, $dimensions, $metrics, $sort_metric, $filter, $start_date, $end_date, $start_index, $max_results);
foreach($ga->getResults() as $result)
{
echo '<td>' . $result->getDate() . '</td>';
echo '<td>' . $result->getVisits() . '</td>';
echo '<td>' . '?' . '</td>';
echo '<td>' . $result->getPageviews() . '</td>';
echo '</tr>';
}
echo "</table>";
The metric is called visitors and no visitor and you have to change the dimension to userDefinedValue
$profile_id = "xxxxxxxx";
$report_id = "xxxxxxxx";
$dimensions = array('userDefinedValue');
$metrics = array('pageviews','visits','visitors');
$sort_metric = array('date');
$filter = null;
$start_date = '2013-02-01';
$end_date = '2013-02-28';
$start_index = 1;
$max_results = 10000;
The metric is called "visitor". Try adding it to your report.
$profile_id = "xxxxxxxx";
$report_id = "xxxxxxxx";
$dimensions = array('date');
$metrics = array('pageviews','visits','visitors');
$sort_metric = array('date');
$filter = null;
$start_date = '2013-02-01';
$end_date = '2013-02-28';
$start_index = 1;
$max_results = 10000;
Ok... I got another WP problem now.
For my WP theme, i have some special things. For example, i have a table containing some stuff.
when i insert (in this case update) to this table i use $wpdb, like the code below:
$sql = $wpdb->prepare("UPDATE $table_name SET
`title` = '$title',
`text` = '$text',
`image` = '$image',
`thumbnail` = '$thumb',
`show` = $sql_show,
`order` = $order,
`language` = '$language',
`type` = '$type'
WHERE `id` = $id
;");
$wpdb->query($sql);
I have also tried this:
$sql = $wpdb->prepare("UPDATE $table_name SET
`title` = %s,
`text` = %s',
`image` = %s,
`thumbnail` = %s,
`show` = %d,
`order` = %d,
`language` = %s,
`type` = %s
WHERE `id` = $id
;", $title, $text, $image, $thumb, $show, $order, $language, $type);
Both of them works, EXCEPT when the $text contains a "%". If it contains this, the $sql is blank. Of coure i could change all the "%" to "percent", but that resolution is not acceptable! ;)
% has to be escaped with a percent, so replace a single percent with a double percent in $text: $text = str_replace('%', '%%', $text)
I need to rewrite pagerquery, i have tried out several options adding tags, extend(PagerDefault) but nothing worked for me:
Please help.
My version 6 code is:
$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;
$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.uid = %d AND n.type = "case" AND n.status = 1';
$args = array('uid' => $user->uid);
$sql = db_rewrite_sql($sql);
$sql_count = db_rewrite_sql($sql_count);
if ($pager) {
$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
dsm($result);
}
else {
$result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
}
$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows = TRUE;
}
Without knowing the name of your join table this isn't complete, but should get you started:
$query = db_select('node', 'n')
->fields('n', array('nid', 'sticky', 'title', 'created'))
->condition('n.uid', $user->uid)
->condition('n.type', 'case')
->condition('n.status', 1)
->extend('PagerDefault')
->limit(variable_get('default_nodes_main', 10))
->addTag('node_access')
->orderBy('col_name');
$query->join('table_to_join', 'table_alias', 'table_alias.nid = n.nid');
foreach ($query->execute() as $row) {
// Do what you need to
}
if ($vidw == 'my_cases' or $vidw == 'my') { // including private
switch ($sort_by) {
case 'rated':
$order = 'n.sticky DESC, vc.value DESC';
$sort_join = 'LEFT OUTER JOIN {votingapi_cache} vc ON n.nid = vc.content_id AND vc.content_type = "node" AND vc.function = "average"';
break;
case 'discussed':
$order = 'n.sticky DESC, nc.comment_count DESC';
$sort_join = 'LEFT OUTER JOIN {node_comment_statistics} nc ON n.nid = nc.nid';
break;
case 'viewed':
$order = 'n.sticky DESC, nc.totalcount DESC';
$sort_join = 'LEFT OUTER JOIN {node_counter} nc ON n.nid = nc.nid';
break;
case 'recent':
default:
$order = 'n.sticky DESC, n.created DESC';
$sort_join = '';
break;
}
// from taxonomy_select_nodes
$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;
$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.uid = %d AND n.type = "case" AND n.status = 1';
$args = array('uid' => $user->uid);
$sql = db_rewrite_sql($sql);
$sql_count = db_rewrite_sql($sql_count);
if ($pager) {
$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
}
else {
$result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
}
// $output .= taxonomy_render_nodes($result);
$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows = TRUE;dsm($output);
}
if ($num_rows) {
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
}
else {
$output .= '<p>'. t('There are currently no visible cases in this category.') .'</p>';
}
}
In above drupal 6 code, i have updated the query which gives me result but node_view() and theme() does not work.
Im trying to make a class to help with SEO and also compare google API with actual results
class:
<?php
class true_seo {
public $string, $amount;
private $arr;
public function __construct(){}
public function set_g_key( $key ) {
$this->g_key = $key;
}
public function set_phrase( $string ){
if( is_string ( $string ) ) {
$string = array( $string );
}
if( is_array ( $string ) ) {
$this->phrases = $string;
}else{
Throw new exception("incorect input for phrase, string or array");
}
}
public function get_sites_use_spider( $amount ) {
require "simple_html_dom.php";
$main_result = array();
foreach( $this->phrases as $phrase ) {
$APIparams = array("key" => $this->g_key, "q" => $phrase, "start" => 0, "maxResults" => $amount, "filter" => true, "restrict" => "", "safeSearch" => false, "lr" => "lang_en", "ie" => "", "oe" => "");
$data = true_seo::google_search_api( $APIparams, 'http://www.google.co.uk/search', false );
new simple_html_dom();
$html = str_get_html( $data );
$result = array();
foreach( $html->find('li.g h3 a') as $g ) {
$data = $g->parent()->nextSibling();
$other = $data->find('span a');
$x = 0;
foreach( $other as $d ) {
( $x == 0 ? $cache = $d->href : $simular = $d->href );
$x++;
}
$excess_span = $data->find('span',0)->outertext;
if( isset( $data->find('div',0)->tag ) ) {
$excess_div = $data->find('div',0)->outertext;
$title = str_replace( array( $excess_span, $excess_div, '<em>', '</em>', '<br>', '<b>', '</b>' ), array( '','','','','','','' ), $data->outertext );
}else{
$title = str_replace( array( $excess_span, '<em>', '</em>', '<br>', '<b>', '</b>' ), array( '','','','','','' ), $data->outertext );
}
$result[] = array( 'link' => $g->href, 'title' => strip_tags( $title ), 'cache' => $cache, 'simular' => 'http://www.google.co.uk' . $simular );
}
$main_result[$phrase] = $result;
$html->clear();
}
$this->non_api_data = $main_result;
}
public function get_sites_use_api( $amount ) {
$arr = array();
foreach( $this->phrases as $phrase ) {
if( $amount > 4 ) {
$times = $amount / 4;
}else{
$times = 1;
}
$arg = array();
for($x = 0; $x < $times; $x++ ) {
$APIparams = array("key" => $this->g_key, "q" => $phrase, "start" => ($x * 4), "maxResults" => 4, "filter" => true, "restrict" => "", "safeSearch" => false, "lr" => "lang_en", "ie" => "", "oe" => "");
if( $data = true_seo::google_search_api( $APIparams, 'http://ajax.googleapis.com/ajax/services/search/web' ) ) {
$arg = array_merge($arg, $data->responseData->results);
}else{
Throw new exception("Request error: no results returned from Google.");
}
}
$arg = array_reverse( $arg );
$remove = $amount % 4;
if( $amount < 4 ) {
$remove = 4 - $amount;
}
for( $x=0; $x < $remove; $x++ ) {
unset( $arg[$x] );
}
$arg = array_reverse( $arg );
foreach( $arg as $g ) {
$result = array( 'link' => $g->url, 'title' => strip_tags( $g->content ), 'cache' => $g->cacheUrl, 'simular' => 'na' );
$arr[$phrase][] = $result;
}
}
$this->api_data = $arr;
}
public function google_search_api($args, $url, $api = true){
if ( !array_key_exists('v', $args) ) {
$args['v'] = '1.0';
}
$url .= '?'.http_build_query($args, '', '&');
if( $result = #file_get_contents($url) ) {
if( $api == true ) {
return json_decode($result);
}else{
return $result;
}
}else{
Throw new exception("No data returned from url: $url");
}
}
public function set_get_actual( $string ) {
$this->actual->name = $string;
$this->actual->data = file_get_contents( $string );
}
public function get_actual_description(){
require_once "simple_html_dom.php";
new simple_html_dom();
$html = str_get_html( $this->actual->data );
return $html->find('head meta[name=description]',0)->content;
$html->clear();
}
}
?>
called by :
<?php
try{
require "./classes/class_true_seo.php";
$seo = new true_seo();
$seo->set_g_key('ABQIAAAAsWzmZ4RXdIk0a-LqpqKCBRSl_WmKnmsXGmN0kkjN2wkrfEOY-hT2sL-_x5v4NtT3DgElKNsR7FDJDQ');
$seo->set_phrase(array("web design mansfield"));
$seo->get_sites_use_api(10);
ob_start();
foreach( $seo->api_data as $key => $phrase_return ){
echo "<h2>" . $key . "</h2>";
foreach( $phrase_return as $rank => $results ){
$seo->set_get_actual( $results['link'] );
echo "<p class=\"link-head\"><strong>#" . ( $rank + 1 ) . "</strong> " . $results['link'] . "</p>";
echo "<p>" . $results['title'] . "</p>";
#echo "<p>" . $seo->get_actual_title() . "</p>";
echo "<p>" . $seo->get_actual_description() . "</p>";
#echo "<p>" . $seo->get_actual_amount_of('p') . "</p>";
#echo "<p>" . $seo->get_actual_amount_of('h2') . "</p>";
}
}
$api_return = ob_get_clean();
ob_start();
$seo->get_sites_use_spider(10);
foreach( $seo->non_api_data as $key => $phrase_return ){
echo "<h2>" . $key . "</h2>";
foreach( $phrase_return as $rank => $results ){
echo "<p class=\"link-head\"><strong>#" . ( $rank + 1 ) . "</strong> " . $results['link'] . "</p>";
echo "<p>" . $results['title'] . "</p>";
}
}
$non_api_return = ob_get_clean();
}catch(Exception $err){
$error = $err->getMessage();
}
?>
My problem being that I keep getting the error:
Fatal error: Cannot redeclare file_get_html() (previously declared in C:\wamp\www\seo\classes\simple_html_dom.php:37) in C:\wamp\www\seo\classes\simple_html_dom.php on line 41
which is due to the last function in the class get_actual_description().
Can anyone see where im cocking up?
regards,
Phil
put require_once "simple_html_dom.php" outside of function