Keep lines in a php array (with for()) - php

My Code:
$RuleNameArray = array();
$dbgetreportsrulename = new DB_MSSQL;
$dbgetreportsrulename->query("Select RulesID,RulesName_Lang_$languageid as RuleName from Main_Rules");
for ($igrn=0;$igrn < $dbgetreportsrulename->num_rows();$igrn++) {
if ($dbgetreportsrulename->next_record()){
$dbgetreportsrulename_RuleID = $dbgetreportsrulename->f('RulesID');
$dbgetreportsrulename_RuleName = $dbgetreportsrulename->f('RuleName');
}
$RuleNameArray = array($dbgetreportsrulename_RuleID => $dbgetreportsrulename_RuleName);
}
How i can keep all entry in $RuleNameArray, because now he keep only last entry.

If you want to keep your all entry then your $RuleNameArray should be :
$RuleNameArray[$dbgetreportsrulename_RuleID] = $dbgetreportsrulename_RuleName;

You can try like this also,
$RuleNameArray[] = array($dbgetreportsrulename_RuleID => $dbgetreportsrulename_RuleName);
^

Related

Multiple if statements with GET not outputting correctly in PHP with XPath

I'm trying to get the total times two authors have edited or coauthored books. (They are selected by a user using checkboxes, so I've used GET to see if the checkbox is selected).
I am cross referencing the authors 'a' (mj) and 'b' (ms) from 'a's' (mj) xml doc that features all their publishing information.
Currently I have this:
if ($_GET['author'] == 'mj55'){
$getMj = new DOMDocument();
$getMj->load("Margret-Jane.xml");
$mjxpath = new DOMXpath($getMj);
$mjAuth = $mjxpath->query("////author[#id = 'mj55']")->length;
$mjEdit = $mjxpath->query("////editor[#id = 'mj55']")->length;
$mjResult = ($mjAuth + $mjEdit);
if ($_GET['author'] == 'ms10' ) {
$mjmsA = $mjxpath->query("////author[#id = 'ms10']")->length;
$mjmsE = $mjxpath->query("////editor[#id = 'ms10']")->length;
$mjmsTotal = ($mjmsA + $mjmsE);
echo $mjmsTotal;
}
}
if I put an echo $mjResult at the end of the first if statement, I get the correct output. But I don't get any output at all from the echo $mjmsTotal
you used a nested if and that's why you are getting a result of only first if.. try to use both the if statement totally independent with each other. Here is an example-
$getMj = new DOMDocument();
$getMj->load("Margret-Jane.xml");
$mjxpath = new DOMXpath($getMj);
if ($_GET['author'] == 'mj55'){
$mjAuth = $mjxpath->query("////author[#id = 'mj55']")->length;
$mjEdit = $mjxpath->query("////editor[#id = 'mj55']")->length;
$mjResult = ($mjAuth + $mjEdit);
}
if ($_GET['author'] == 'ms10' ) {
$mjmsA = $mjxpath->query("////author[#id = 'ms10']")->length;
$mjmsE = $mjxpath->query("////editor[#id = 'ms10']")->length;
$mjmsTotal = ($mjmsA + $mjmsE);
echo $mjmsTotal;
}
You can reduce this to one condition, this saves having to hard code all of the different authors/editors.
First check if the author is set, then include this value in the XPath expressions...
if ( !empty($_GET['author'])) {
$getMj = new DOMDocument();
$getMj->load("Margret-Jane.xml");
$mjxpath = new DOMXpath($getMj);
$mjAuth = $mjxpath->query("//author[#id = '{$_GET['author']}']")->length;
$mjEdit = $mjxpath->query("//editor[#id = '{$_GET['author']}']")->length;
$mjResult = ($mjAuth + $mjEdit);
echo $mjResult;
}

Laravel list() with each() function error with deprecated function

I get a little confuse here on how to alternatively replace the each() function since it was deprecated and I'm aware of that and fixed some of the while( list() = each() ) error case in my project. However, what other option should I use for this case:
foreach($new_id as $new_ids) {
list($key,$valueAddress) = each($address);
list($key,$valueCity) = each($city);
list($key,$valueState) = each($state);
if(isset($_POST['publicOnly'])) {
list($key,$valuePublicOnly) = each($publicOnly);
} else {
$valuePublicOnly = 0;
}
$propertyAddress = PropertyAddressManagement::find($new_ids);
$propertyAddress->address = $valueAddress;
$propertyAddress->city = $valueCity;
$propertyAddress->state = $valueState;
$propertyAddress->publicOnly = $valuePublicOnly;
$propertyAddress->save();
}
You're not using the keys so just get the current value and then move to the next one:
foreach($new_id as $new_ids) {
$propertyAddress = PropertyAddressManagement::find($new_ids);
$propertyAddress->address = current($address);
$propertyAddress->city = current($city);
$propertyAddress->state = current($state);
$propertyAddress->publicOnly = isset($_POST['publicOnly']) ? current($publicOnly) : 0;
$propertyAddress->save();
next($address); next($city); next($state); next($publicOnly);
}
However, if the keys are the same in all of the array then I think really this should work:
foreach($new_id as $key => $new_ids) {
$propertyAddress = PropertyAddressManagement::find($new_ids);
$propertyAddress->address = $address[$key];
$propertyAddress->city = $city[$key];
$propertyAddress->state = $state[$key];
$propertyAddress->publicOnly = isset($_POST['publicOnly']) ? $publicOnly[$key] : 0;
$propertyAddress->save();
}

Accessing variable yet to be created

I'm having some trouble here V_shop_menu $order_uuid is not populating. Now I'm guessing this is because its yet to be created this is done further below. The problem I have is there are 2 statements here doing inserts to tables but they both rely on each other.
I have a bit of chicken and egg situation as I need $shop_menu_uuid from the top area to complete the bottom insert. I was led to believe that as they are in the same public function it would just work but this is not the case.
What do I need to do to make this happen?
Thanks!
public function add_shopmenu(){
$postData = $this->input->post();
$condition['conditions'][] = "site_name ='".$this->sessionInfo['site']."'";
$site = $this->frontguide_Model->selectSingleRow("t_place",$condition);
$site_uuid = $site['site_uuid'];
unset($condition);
$condition['conditions'][] = "site_uuid ='".$site['site_uuid']."'";
$condition['conditions'][] = "shop_menu_name ='".$postData['shop_menu_name']."'";
$shopmenu_name = $this->frontguide_Model->selectData("v_shop_menus",$condition);
unset($condition);
$condition['conditions'][] = "site_uuid ='".$site['site_uuid']."'";
$shopmenus = $this->frontguide_Model->selectData("v_shop_menus",$condition);
$shop_menu_enabled = (isset($postData['shop_menu_enabled']))?$postData['shop_menu_enabled']:"false";
$shop_menu_uuid = $this->frontguide_functions->uuid();
$v_shop_menu= array(
"shop_menu_uuid" =>$shop_menu_uuid,
"site_uuid" =>$site_uuid,
"order_uuid" =>$order_uuid,
"shop_menu_extension" =>$shop_menu_extension,
"shop_menu_name" =>$postData['shop_menu_name'],
"shop_menu_greet_long" =>$postData['shop_menu_greet_long'],
"shop_menu_greet_short" =>$postData['shop_menu_greet_short'],
"shop_menu_timeout" =>$postData['shop_menu_timeout'],
"shop_menu_enabled" => $shop_menu_enabled,
"shop_menu_cid_prefix"=>$postData['shop_menu_cid_prefix']
);
log_message('debug',print_r($v_shop_menu,TRUE));
$vgu_response = $this->frontguide_Model->insert("v_shop_menus",$v_shop_menu);
$shop_menu_option_digits = $postData['shop_menu_option_digits'];
$shop_menu_option_order = $postData['shop_menu_option_order'];
$shop_menu_option_description = $postData['shop_menu_option_description'];
$shop_menu_option_param = $postData['shop_menu_option_param'];
for($i=0;$i<count($shop_menu_option_digits);$i++){
$option = array();
$option['shop_menu_option_digits'] = $shop_menu_option_digits[$i];
$option['shop_menu_option_order'] = $shop_menu_option_order[$i];
$option['shop_menu_option_description'] = $shop_menu_option_description[$i];
$option['shop_menu_option_param'] = $shop_menu_option_param[$i];
$shop_menu_option_uuid= $this->frontguide_functions->uuid();
$option['shop_menu_option_uuid'] = $shop_menu_option_uuid;
$option['shop_menu_uuid'] = $shop_menu_uuid;
$option['site_uuid'] = $site_uuid;
$vgu_response = $this->frontguide_Model->insert("v_shop_menu_options",$option);
}
$order_uuid = $this->frontguide_functions->uuid();
$order_data = array(
"site_uuid"=>$site_uuid,
"order_uuid"=>$order_uuid,
“offer_uuid" => "a6788e9b-67bc-bd1b-df59-ggg5d51289ab",
"order_context"=>$site['site_name'],
"order_name" =>$postData['shop_menu_name'],
"order_number" =>$shop_menu_extension,
"order_continue" =>'true',
"order_order" =>'333',
"order_enabled" =>"true",
);
$v_orders = $this->frontguide_Model->insert("v_orders",$order_data);
Now I'm guessing this is because its yet to be created this is done
further below.
Yes you are right.
It is quite simple.
Insert v_shop_menus data without $order_uuid .
after inserting in v_orders, get the $order_uuid and update the v_shop_menus using $shop_menu_uuid.

Return various amounts of values in symfony

I have little problem, because I have no idea how to do one thing. I want to return on page sometimes 3 values, sometimes 5, sometimes n and I have no idea how to do it. Here is my code (controller):
$result = count($countries);
$tablica = array();
for ($i = 0; $i < $result; $i++)
{
$tekst2 = "SELECT nazwa FROM product WHERE id = '$countries[$i]'";
$id_zap2 = mysql_query($tekst2);
$tablica[$i]['nazwa'] = mysql_fetch_array($id_zap2);
$tekst2 = "SELECT jednostka FROM product WHERE id = '$countries[$i]'";
$id_zap2 = mysql_query($tekst2);
$tablica[$i]['jednostka'] = mysql_fetch_array($id_zap2);
}
I want to return all these $tablica[x]['jednostka'] and $tablica[x]['nazwa']. But I have no idea how I can return it if I use this:
return $this->render('MainBundle:Default:addtolist.html.twig', array(
//What to do here?
));
Anybody have idea how I can solve this problem?
I wanted to return something like:
"testn0" => $tablica[0]['nazwa'],
"testj0" => $tablica[0]['jednostka'],
"testn1" => $tablica[1]['nazwa'],
"testj1" => $tablica[1]['jednostka'],
...
"testnn" => $tablica[n]['nazwa'],
"testjn" => $tablica[n]['jednostka'],
Just return this :
return $this->render('MainBundle:Default:addtolist.html.twig', array('tablica' => $tablica));
Then you can parse it in Twig to do whatever you want to.

If the operation is performed if the value in the list I'm looking for

I'm the data with the following code.
$parametre = mysql_query("select * from faturaparametre where musteri='$musteri' and
urungrubu='$urungrubu' and tasimasekli='$tasimasekli' and donem<= '$tarih' and donem2>= '$tarih' and teslimnoktasi='$teslimnoktasi1' and $agirlik BETWEEN min and max");
while($parametresonuc = mysql_fetch_array($parametre)) {
$fatparametreid = $parametresonuc[id];
$ynadresno = $parametresonuc[yuklemenokta];
Skip this procedure if you do not have the following variables: the next one in the list if there is no break in the last one in the search process, how can I do this?
$adresil1 = mysql_query("select * from adresler where id='$yuklemenokta'");
$adressonuc1 = mysql_fetch_array($adresil1);
$yuklemeadresno = $adressonuc1[adresno];
$yuklemeil = $adressonuc1[noktail];
$yuklemeilce = $adressonuc1[noktailce];
$yuklemeilb = "il".$yuklemeil;
This code does not run more than one priority finding. and do not find exactly the same thing
if(eregi($ynadresno, "$yuklemeadresno")) {
$ftid = $fatparametreid;
}elseif(eregi($ynadresno, "$yuklemeilce")) {
$ftid = $fatparametreid;
}elseif(eregi($ynadresno, "$yuklemeilb")) {
$ftid = $fatparametreid;
}else {
}
The array keys should be quoted,
$yuklemeadresno = $adressonuc1['adresno'];
$yuklemeil = $adressonuc1['noktail'];
$yuklemeilce = $adressonuc1['noktailce'];
$yuklemeilb = "il".$yuklemeil;

Categories