PHP PDO MySql query results not updated - php

hopefully I can explain this clearly enough.
On my profile page (let's call it profile.php), I am including a header file (header.php) that contains all the HTML header code and menu, as well as some queries to show stats to a user (how many surveys they have completed, and rewards earned). There are multiple queries on this page, but all work as expected, such as
header.php
<h3>
<?php
$whereCnt = array(
array('svy_end_status','=',1),
array('svy_end_mem_id','=',$member_id)
);
$svycnt = DB::getInstance()->get( 'COUNT(*) AS Count', 'survey_end', $whereCnt );
echo $svycnt->first()->Count;
?>
</h3>
Back in profile.php I have another query to get all the user profile information:
$wheremem = array(
array( 'member-uid', '=', $member_id ));
$completeprofileqry = DB::getInstance()->get('*','members',$wheremem);
NOTE: This is using a DB class based from Codecourse's Login/Register tutorial but is using PDO as the method.
Now, when I do a
if ($completeprofileqry->count()){
echo '<pre>';
print_r($completeprofileqry->first());
echo '</pre>';
I get as the output:
stdClass Object
(
[Count] => 2
)
This output directly correlates with the first query from the included header file, rather than the new query.
Is this due to the 'instance' still being the same?
I should also note, that on my index.php page, I am doing other queries, as well as using the same included header.php, but I am having NO issues with these query results.
Can anyone help narrow down where the problem might be?
EDIT: I am an idiot
It was meant to be 'member_uid' NOT 'member-uid' (underscore not hyphen !!!)

Related

Moodle Course ID always equals to 1

I am trying to get a Moodle Course ID in a php script shown below.
I have tested it in different courses and different accounts and it always gives me the ID of 1. Why is that and how to get the correct ID?
<?php
require('./config.php');
global $PAGE;
echo $PAGE->course->id;
?>
Moodle only knows which course your page is meant to be part of if you tell it (you could have arrived on your page by following a link from any course on the site). When you create a link to your page you need to include a parameter of some kind that will tell your page what course it should be considered part of, e.g. $url = new moodle_url('/blocks/myblock/mypage.php', ['id' => $PAGE->course->id]); echo html_writer($url, 'Look at my page');
Then, once you follow the link, gather the param using required_param() and use require_login() to set up the page. E.g
$courseid = required_param('id', PARAM_INT);
$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
require_login($course);
After that, $PAGE->course will be configured.

Vtiger custom link with $current_user variable

I am trying to add a custom link to a custom page using the vtiger_link table, with 2 parameters; 1 is the trouble ticket id which works fine:
This is in the URL field in the database:
modules/Helpdesk%20Info/index.php?ticketid=$RECORD$"target='helpdeskinfo'
and 2 is the id of the logged in user ($current_user) but it doesn't work:
modules/Helpdesk%20Info/index.php?ticketid=$RECORD$&$user=$current_user"target='helpdeskinfo'
It shows the page just as it should, but the variable $user gets the value '$current_user':
http://localhost:8888/modules/Helpdesk%20Info/index.php?ticketid=135409&$user=$current_user
I wanted to post a picture of the table, but I don't have enough reputation for that.
I have tried many things, but I am clearly doing something wrong.
Any help would be much appreciated.
I did not need to put the variable in the URL,
the reason I could not use the $current_user variable is because it didn't exist in "detailview.php" which is where the link ends up.
I used:
echo "<pre>";
print_r($GLOBALS);
echo "</pre>";
to view all globals, there I found the authenticated_user_id
Knowing I could use this I was able to access the global from my file without the URL:
$current_user = $_SESSION["authenticated_user_id"];
I would like to thank STT LCU for his advice, as he was the only one who helped me through this problem, which took me a full week in total.

How to modify data for a SugarCRM SubPanel using PHP?

Is there anyway to modify the content shown in a SugarCRM Subpanel without relying on Action Hooks?
Right now to edit content for a Subpanel field I have to use the hooks like this...
$hook_array['process_record']
And in the Class method that I assign the Hook to call I can then change a field in the Subpanel like this...
$bean->name = '<a href="/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3Dproje_Web_Project_Tasks%26action%3DDetailView%26record%3D'
.$bean->id.'" rel="popover" data-content="'
.$bean->description.'" data-original-title="">'.$bean->name.'</a>';
The main and major problem we have with this method is it works great until you do either of these actions....
Add an item using the Quick Create form
Change a page using the Subpanel paging buttons
In either case, it reloads the Subpanel data without running this hook code on the data, so the result is pretty major as the Subpanel fields that you have edited are no longer edited and show up as normal.
Here is a basic example...this shows 2-3 fields that have been edited using the Hook method above...
Now after paging or quick-creating a new record in the Subpanel, it reloads the Subpanel data and does not apply the Hooked code so you can see the result looks like this...
I know that ListView has a much more reliable and flexible method for editing it's content using the get_list_view_data() method I am able to apply the same edits and have them work all the time!
So I am hoping there is a similar method to edit Subpanel data and have it always apply the edits to that data? From what I have seen in my research so far, the only solution that will work as expected all the time, is to make a completely new Custom Field Type!
I am really hoping that is not the ONLY way as that is a major pain to do that for each type of field that I need to edit in the Subpanels and just doesn't feel right when there are easy ways to edit everything else except SubPanel data.
Does anyone have any ideas, suggestions, tips, help, please do share with me on this matter as it is the main problem I have had since I started developing with SugarCRM in the past few months?
You can change the data by writing a custom query to get data for your subpanel.
So inside your bean (this case Contacts) do a functions:
function get_project_list() {
$query = "SELECT project, info, matching, column, names FROM projects WHERE contact_id = '" . $this->id . "' AND deleted = 0"
return $query;
}
and then in subpanel definition set the data source like this:
$layout_defs["Contacts"]["subpanel_setup"]['projects'] = array(
'order' => 10,
'sort_order' => 'desc',
'sort_by' => 'name',
'title_key' => 'LBL_PROJECTS_TITLE',
'subpanel_name' => 'contact_projects',
'module'=>'projects',
'get_subpanel_data' => 'function:get_project_list',
'function_parameters'=>array('type'=>'urgent'), // this is optional if you decide to sent parameters to the function if do this dont forget to define your function with function get_project_list($params)
'top_buttons' => array (... buttons that you need go here..),
);
Since sql is quite powerful you can modify your subpanel data any way you like, well more or less :)

Extracting data from a Magento collection. I have it broken down to an array but trying to call it breaks the page

I'm working on a script that will give a Magento user directions after selecting warehouse pickup (a plugin option). I already have the rest built. I'm simply missing one variable I need to call on success.phtml (the warehouse ID). The variable is tied to orders via stock_id.
This produces an array: I'm using $order successfully to pull the rest of the info I need for the script.
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getItemsCollection();
A shortened version of this array: can be printed with print_r($items->getData());
Array
(
[0] => Array
(
[item_id] => 223
[stock_id] => 15
[base_discount_refunded] =>
)
)
When I try to pull the data that I want out:
echo $items[0]['stock_id']; //the page breaks here and stops the page abruptly...
the page breaks and any logic that should take place after is ignored. What would cause this? I tried braking variables I'm calling in other similar arrays. None of my tests have replicated the page breaking. Why is this specific one breaking the page instead of returning 15?
You might try enumerating $items using var_export in your page, instead of print_r so you can see them as they truly exist:
foreach ($items as $item)
{
var_export($item->debug());
}
This will provide you with the results. Items is an object populated with more objects, not an array and should be treated as such. Try using
$itemId = $item->getStockId();
or
$itemId = $item->getData('stock_id');
Both accomplish the same thing.
FYI.. the debug() function shows relevant info and its built into magento for use with all mage objects.
EDIT: Try this:
echo $items[0]->getData('stock_id');
Well, $items is not an array, it is an object of Mage_Sales_Model_Resource_Order_Item_Collection. This should work:
$data = $items->getData();
echo $data[0]['stock_id'];
But using the enumeration interface of the collection, like already mentioned, would be much cleaner. Take a look at http://alanstorm.com/magento_collections.
You should also check your PHP configuration, to get more information on such errors. Take a look at http://alanstorm.com/magento_exception_handling_developer_mode.

Is there a cleaner way to write this avoiding includes

I'm writing a project in php that will basically give me a webpage with links to things like:
a page containing my favorite youtube videos stored in a mysql db
a page with all my favorite games
and music ect
All will be embeded directly inside the webpage rather than linking to the site.
To simplify this I've made a master template "index.php" and then using $_GET I pass pages and other info through to the template which is then handled by a page check script which performs a number of ifs to determine what php script to load into the website.
Where my question lies is whats the prefered method for loading theese scripts into the website as my current method is
if ($_GET["page"] == "videos"){
include ("dynapage/scripts/videos/videos.php");
}
if ($_GET["page"] == "music"){
include ("dynapage/scripts/music/music.php");
}
ect
Is using includes to add this code into my template a good thing to do or is there a better method you can suggest?
note: checks for isset are already included in the checks and aditional pbs are availble on request.
Use an array which has the $_GET["page"] value as key and the php filename as value. You then only need to check if it is inside the array and if so, include it. You then write the values into the array instead of writing many if clauses.
The following code example shows this, additionally it has a function to load a page because so the included script does not set variables in the context it gets included into by accident.
$pages = array(
'videos' => 'videos/videos.php',
'music' => 'music/music.php',
);
/**
* include a page template
*/
function load_page(array $pages, $page, $path = 'dynapage/scripts')
{
if (isset($pages[$page])) return;
include ($path.'/'.$pages[$page]);
}
if (isset($_GET['page']))
{
load_page($pages, $_GET['page']);
}
Maybe Something like this:
$config = array(
'videos' => 'dynapage/scripts/videos/videos.php',
'music' => 'dynapage/scripts/music/music.php'
);
if(isset($config[$_GET['page']])) {
include($config[$_GET['page']]);
}
is a bit better, then writing many if clauses (;
Looks like you can just do:
if( file_exists($fn = "dynapage/scripts/".$_GET['page']."/".$_GET['page'].".php"))
include($fn);

Categories