Styling Dynamically created selection drop box using HTML and CSS. How? - php

This code is in php file. How I will style tag with "Select Size" and customize the drop down section. Below is one div which i want to style but ht class is created dynamically. And here div drop box are created dynamically and the data entered is also been done dynamically. HELP
$i = 0;
$attribArr = array();
$sizeArr = array();
$colorArr = array();
$colorStr = "color";
$sizeStr = "size";
$phpArray = array(
0 => 001 - 1234567,
1 => 1234567,
2 => 12345678,
3 => 12345678,
4 => 12345678
);
foreach ($order['cart_items'] as $item) {
$i++;
$cssNo = $i % 5;
if ($cssNo == 0) {
$cssNo = 5;
}
$giftcss = "gift-info gift" . $cssNo;
// Get products description
$presult = array();
$productId = $item['product_id'];
$reslt = getProductOptions($productId);
$values = $reslt['values'];
info('option type=' . $reslt['type'] . ' Name=' . $reslt['name']);
$sizeOptionValues = '<option>';
$colorOptionValues = '<option>';
if ($reslt['name'] == 'Size') {
foreach ($values as $value) {
info('vl=' . $value['options_value_name']);
$sizeOptionValues.= str_replace(' ', '', $value['options_value_name']) . '</option><option>';
}
}
if ($reslt['name'] == 'Color') {
foreach ($values as $value) {
info('vl=' . $value['options_value_name']);
$colorOptionValues.= $value['options_value_name'] . '</option><option>';
}
}
$pquery = "SELECT products_description, pr.products_image, products_name FROM "
. TABLE_PRODUCTS_DESCRIPTION . " AS pd JOIN " . TABLE_PRODUCTS . " as pr ON pr.products_id = pd.products_id WHERE pd.products_id=" . $productId;
$presult = $db->Execute($pquery);
$product_name = $presult->fields['products_name'];
$product_image = $presult->fields['products_image'];
$product_desc = $presult->fields['products_description'];
$prodImgs = explode(".", $product_image);
$prodImg0 = $prodImgs[0];
$prodImgExt = $prodImgs[1];
$prod_img_name = $prodImg0 . 'v.' . $prodImgExt;
info("getOrder", "Product Name=" . $product_name . " prod image=" . $prod_img_name);
$prod_desc_url = EL_PROD_DESC_PATH . $productId;
$prodAttrQry = "SELECT * FROM " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " WHERE products_prid = " . $productId . " AND orders_id = " . $orderId;
$attrReslt = $db->Execute($prodAttrQry);
$color = false;
$colorValue = '';
$size = false;
$sizeValue = '';
$personalised = false;
$attr = false;
$personalisedMsg = '';
if ($attrReslt->RecordCount() > 0) {
$attr = true;
$attrArr = array();
while (!$attrReslt->EOF) {
$optName = $attrReslt->fields['products_options'];
$optValue = $attrReslt->fields['products_options_values'];
if ($optName == 'Size') {
$size = true;
$sizeValue = $optValue;
} else if ($optName == 'Color') {
$color = true;
$colorValue = $optValue;
} else if ($optName == '') {
$personalised = true;
$rslt = explode(".", $optValue);
if ((isset($rslt[1]) && $rslt[1] == 'jpg') || (isset($rslt[1]) && $rslt[1] == 'png')) {
$personalisedMsg = "<b>Uploaded Image</b> " . "<br><img style = 'width:200px; height:200px;'src = '$optValue'/>";
} else {
$personalisedMsg = '<b>Personal Message</b><br>' . $optValue;
}
}
$sizeArr[$i] = $sizeValue;
$colorArr[$i] = $colorValue;
$attribArr['personalise_val' . $i] = $personalisedMsg;
$attrReslt->MoveNext();
}
}
$colorVisibility = 'none';
$sizeVisibility = 'none';
$personalisedVisib = 'none';
$headlineVisib = 'none';
if ($color) {
$colorVisibility = 'inline';
$headlineVisib = 'inline';
}
if ($size) {
$sizeVisibility = 'inline';
$headlineVisib = 'inline';
}
if ($personalised) {
$personalisedVisib = 'inline';
}
$secondScreen .= <<
<div class="{$giftcss}">
<input type="hidden" name= "product_id{$i}" value="{$productId}"/>
<div class="gift-img"><img src="http://{$domainName}/gifts/images/{$prod_img_name}" height="250"></div>
<div class="divider"></div><div class="gift-desc"><h3>{$product_name}</h3><span>{$product_desc}</span></div>
<div style="width:100%;"><h3 style="display:{$headlineVisib}">Customize your gift</h3><br>
<p style="display:{$sizeVisibility};">Select Size<select id = "prod_size{$i}" name="prod_size{$i}" >{$sizeOptionValues}</select></p>
<p style="display:{$colorVisibility};">Select Color<select id = "prod_color{$i}" name="prod_color{$i}" >{$colorOptionValues}</select></p>
<p style="display:{$personalisedVisib};">{$personalisedMsg}</p></div>
MARKUP;
$secondScreen .= <<<MARKUP

Im not entirely sure what you mean? But if it's what I think you mean. To print out your php values into the class='' attribute you would:
<div class="<?php echo $giftcss; ?>">
<input type="hidden" name= "product_id<?php echo $i; ?>" value="{$productId}"/>
<div class="gift-img">
<img src="http://<?php echo $domainName; ?>/gifts/images/<?php echo $prod_img_name; ?>" height="250"></div>
Simply <?php echo $variable; ?> into each html attribute.

Related

PHP session variables not persisting on new page after form submission

I have a quiz site which randomly shuffles and puts together multiple choice questions. The correct answers (as well as some other data) are stored in session variables, and the students' answers are sent via POST. On the page that the quiz form submission links to, the correct answers in SESSION are compared to the POST data, and the results of the quiz are displayed. The site used to work just fine, so I have no idea what happened to make it suddenly stop working.
I have checked to see that the session_id is the same on both pages and it is. I have made sure that start_session() is placed appropriately above all the HTML (and have even confirmed it by calling var_dump($_SESSION) on the first and second page, user login variables are displayed, but nothing else).
Here is the code from "startquiz.php" which assembles the quiz form. The session variables in question are just after the end of the "DISPLAY A QUESTION LOOP"
<?php
require_once('appvars.php');
require_once('startsession.php');
require_once('generalauthorize.php');
$page_title = '10 Question Quiz';
require_once('header.php');
require_once('navbar.php');
require_once('connectvars.php');
//=================MySQL HANDLING====================
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$quizcount = count($_GET);
$content_array = [];
foreach($_GET as $quiz_content){
$quiz_content = $quiz_content . ' = 1';
array_push($content_array, $quiz_content);
}
$where_clause = implode(' OR ', $content_array);
$query = 'SELECT * FROM questionbank WHERE ' . $where_clause;
$data = mysqli_query($dbc, $query);
$questions_found = mysqli_num_rows($data);
mysqli_close($dbc);
//==================MySQL HANDLING=======================
if ($questions_found > 9) {
//==========MAKE A LIST OF POSSIBLE QUESTIONS==================
$possible_questions_array = [];
while ($row = mysqli_fetch_array($data)) {
array_push($possible_questions_array, $row);
}
//==========MAKE A LIST OF POSSIBLE QUESTIONS=================
// ============DECIDE WHICH 10 QUESTIONS TO USE=================
$quiz_array = [];
for($i = 0; $i < 10; $i++) {
$question_bank_count = count($possible_questions_array);
$random_question_number = rand(0, ($question_bank_count - 1));
array_push($quiz_array, $possible_questions_array[$random_question_number]);
array_splice($possible_questions_array, $random_question_number, 1);
}
// ============DECIDE WHICH 10 QUESTIONS TO USE=================
//============CREATE QUESTION META DATA ARRAY=================
$quiz_metadata_array = [];
for ($i = 0; $i < count($quiz_array); $i++) {
$question_holder = $quiz_array[$i];
$metadata_only = array_splice($question_holder, 12);
array_push($quiz_metadata_array, $metadata_only);
}
//============CREATE QUESTION META DATA ARRAY=================
echo '<div class="quiz-container">';
echo '<h2 class="mainpagetitles">Good Luck!</h2>';
echo '<br />';
echo '<form role="form" method="post" action="processquiz.php">';
//==============CREATE ARRAYS TO HOLD QUIZ DATA==========
$correct_answers = [];
$question_prompts = [];
//==============CREATE ARRAYS TO HOLD QUIZ DATA==========
//===============DISPLAY A QUESTION LOOP==================
for($i = 0; $i < (count($quiz_array)); $i++){
array_push($question_prompts, $quiz_array[$i]['question']);
//==================ISOLATE THE ANSWERS===============
$answers_array = [];
array_push($correct_answers, $quiz_array[$i]['answer']);
array_push($answers_array, $quiz_array[$i]['answer']);
array_push($answers_array, $quiz_array[$i]['distractor1']);
array_push($answers_array, $quiz_array[$i]['distractor2']);
array_push($answers_array, $quiz_array[$i]['distractor3']);
//==================ISOLATE THE ANSWERS===============
//=================SCRAMBLE THE ANSWERS==============
$scrambled_array = [];
$answer_count = count($answers_array);
for ($j = 0; $j < $answer_count; $j++) {
$random_answer_number = rand(0, (count($answers_array) - 1));
array_push($scrambled_array, $answers_array[$random_answer_number]);
array_splice($answers_array, $random_answer_number, 1);
}
//=================SCRAMBLE THE ANSWERS==============
//====================CREATE THE HTML=================
echo '<h3>Question ' . ($i + 1) . '.</h3>';
echo '<div class="question-container">';
echo '<p class="question">' . $quiz_array[$i]['question'] . '</p>';
//==============LOOP THROUGH THE SCRAMBLED ANSWERS===========
for($k = 0; $k < (count($scrambled_array)); $k++) {
echo '<label for="' . $i . $k . '" class="answer_choice">' . (chr((65 + $k))) . ': </label>';
echo '<input value="' . $scrambled_array[$k] . '" id="' . $i . $k . '" class="answer_choice" type="radio" name="' . $i . '" required><p class="answer_choice"> ' . $scrambled_array[$k] . '</p><br />';
}
//==============LOOP THROUGH THE SCRAMBLED ANSWERS===========
echo '</div>';
echo '<hr>';
//====================CREATE THE HTML=================
}
//===============DISPLAY A QUESTION LOOP==================
echo '<div class="center">';
$_SESSION['correct_answers'] = $correct_answers;
$_SESSION['question_prompts'] = $question_prompts;
$_SESSION['current_quiz'] = $_GET;
$_SESSION['current_quiz_meta'] = $quiz_metadata_array;
echo session_id();
echo '<button type="submit" class="centered-button">Finished!</button>';
echo '</div>';
echo '</form>';
echo '</div>';
} else {
echo '<div class="quiz-container">';
echo '<h2 class="center">Oh no!</h2>';
echo '<h4 class="center">It looks like there aren\'t enough questions in the database to take a quiz for this category yet!</h4>';
echo '<h4 class="center">Talk to your English teachers about adding some more.</h4>';
echo '<h4 class="center">Sorry about that!</h4><br />';
echo '<a class="main_menu_button" href="quizselect.php"> Okay </a>';
echo '</div>';
}
require_once('bootstrapfooter.php');
?>
And here is the code for the quiz processing page. When I insert a var_dump($_SESSION) on this page I get the login variables that are in session, but nothing else.
<?php
require_once('appvars.php');
require_once('startsession.php');
require_once('generalauthorize.php');
$page_title = 'Quiz Results';
require_once('header.php');
require_once('navbar.php');
require_once('connectvars.php');
//=====HAND OFF CURRENT QUIZ KEYWORDS TO LOCAL VARIABLE AND RESET GLOBAL====
$current_quiz = [];
foreach ($_SESSION['current_quiz'] as $key => $value) {
array_push($current_quiz, $value);
}
$_SESSION['current_quiz'] = "";
//=====HAND OFF CURRENT QUIZ KEYWORDS TO LOCAL VARIABLE AND RESET GLOBAL====
//=======UPDATE THE NUMBER OF THIS QUIZ TYPE TAKEN FOR THE USER ===========
$increment_these_quizzes = [];
for ($i = 0; $i < count($current_quiz); $i++) {
if ($current_quiz[$i] == "english_1_1" || $current_quiz[$i] == "english_1_2") {
if (!in_array('english_1_quiz_taken = english_1_quiz_taken + 1', $increment_these_quizzes)) {
$array_insert = 'english_1_quiz_taken = english_1_quiz_taken + 1';
array_push($increment_these_quizzes, $array_insert);
}
} elseif ($current_quiz[$i] == "english_2ot_1" || $current_quiz[$i] == "english_2ot_2") {
if (!in_array('english_2ot_quiz_taken = english_2ot_quiz_taken + 1', $increment_these_quizzes)) {
$array_insert = 'english_2ot_quiz_taken = english_2ot_quiz_taken + 1';
array_push($increment_these_quizzes, $array_insert);
}
} elseif ($current_quiz[$i] == "english_2pt_1" || $current_quiz[$i] == "english_2pt_2") {
if (!in_array('english_2pt_quiz_taken = english_2pt_quiz_taken + 1', $increment_these_quizzes)) {
$array_insert = 'english_2pt_quiz_taken = english_2pt_quiz_taken + 1';
array_push($increment_these_quizzes, $array_insert);
}
} elseif ($current_quiz[$i] == "english_2sw_1" || $current_quiz[$i] == "english_2sw_2") {
if (!in_array('english_2sw_quiz_taken = english_2sw_quiz_taken + 1', $increment_these_quizzes)) {
$array_insert = 'english_2sw_quiz_taken = english_2sw_quiz_taken + 1';
array_push($increment_these_quizzes, $array_insert);
}
} else {
$array_insert = $current_quiz[$i] . '_quiz_taken = ' . $current_quiz[$i] . '_quiz_taken + 1';
array_push($increment_these_quizzes, $array_insert);
}
}
$increment_this = implode(', ', $increment_these_quizzes);
$increase_quiz_count_query = "UPDATE memberinfo SET $increment_this WHERE user_id = $_SESSION[user_id]";
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
mysqli_query($dbc, $increase_quiz_count_query);
mysqli_close($dbc);
//=======UPDATE THE NUMBER OF THIS QUIZ TYPE TAKEN FOR THE USER ===========
//================GET QUESTION COUNT & SCORE QUIZ===========
$score = 0;
$question_count = count($_SESSION['correct_answers']);
for($i = 0; $i < $question_count; $i++) {
$switch = 0;
$keywords = [];
//==============CORRECT ANSWER HANDLING=====================
if ($_POST[$i] == $_SESSION['correct_answers'][$i]) {
$generic_array = [];
$correct_array = [];
$score++;
foreach ($_SESSION['current_quiz_meta'][$i] as $key => $value) {
if ($switch == 1) {
if ($value == 1) {
if ($key == "english_1_1" || $key == "english_1_2") {
if (!in_array('english_1_correct = english_1_correct + 1', $correct_array)) {
$key = 'english_1_correct = english_1_correct + 1';
array_push($correct_array, $key);
}
if (!in_array('english_1_answers = english_1_answers + 1', $generic_array)) {
$gkey = 'english_1_answers = english_1_answers + 1';
array_push($generic_array, $gkey);
}
} elseif ($key == "english_2ot_1" || $key == "english_2ot_2") {
if (!in_array('english_2ot_correct = english_2ot_correct + 1', $correct_array)) {
$key = 'english_2ot_correct = english_2ot_correct + 1';
array_push($correct_array, $key);
}
if (!in_array('english_2ot_answers = english_2ot_answers + 1', $generic_array)) {
$gkey = 'english_2ot_answers = english_2ot_answers + 1';
array_push($generic_array, $gkey);
}
} elseif ($key == "english_2pt_1" || $key == "english_2pt_2") {
if (!in_array('english_2pt_correct = english_2pt_correct + 1', $correct_array)) {
$key = 'english_2pt_correct = english_2pt_correct + 1';
array_push($correct_array, $key);
}
if (!in_array('english_2pt_answers = english_2pt_answers + 1', $generic_array)) {
$gkey = 'english_2pt_answers = english_2pt_answers + 1';
array_push($generic_array, $gkey);
}
} elseif ($key == "english_2sw_1" || $key == "english_2sw_2") {
if (!in_array('english_2sw_correct = english_2sw_correct + 1', $correct_array)) {
$key = 'english_2sw_correct = english_2sw_correct + 1';
array_push($correct_array, $key);
}
if (!in_array('english_2sw_answers = english_2sw_answers + 1', $generic_array)) {
$gkey = 'english_2sw_answers = english_2sw_answers + 1';
array_push($generic_array, $gkey);
}
} else {
$keyword_generic = $key . '_answers = ' . $key . '_answers + 1';
$keyword_correct = $key . '_correct = ' . $key . '_correct + 1';
array_push($generic_array, $keyword_generic);
array_push($correct_array, $keyword_correct);
}
}
$switch = 0;
} else {
$switch = 1;
}
}
$set_what_generic = implode(', ', $generic_array);
$set_what = implode(', ', $correct_array);
$update_query = "UPDATE memberinfo SET $set_what WHERE user_id = $_SESSION[user_id]";
$update_generic_query = "UPDATE memberinfo SET $set_what_generic WHERE user_id = $_SESSION[user_id]";
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
mysqli_query($dbc, $update_query);
mysqli_query($dbc, $update_generic_query);
mysqli_close($dbc);
//==============CORRECT ANSWER HANDLING=====================
//==============WRONG ANSWER HANDLING=====================
} else {
$generic_array = [];
foreach ($_SESSION['current_quiz_meta'][$i] as $key => $value) {
if ($switch == 1) {
if ($value == 1) {
if ($key == "english_1_1" || $key == "english_1_2") {
if (!in_array('english_1_answers = english_1_answers + 1', $generic_array)) {
$gkey = 'english_1_answers = english_1_answers + 1';
array_push($generic_array, $gkey);
}
} elseif ($key == "english_2ot_1" || $key == "english_2ot_2") {
if (!in_array('english_2ot_answers = english_2ot_answers + 1', $generic_array)) {
$gkey = 'english_2ot_answers = english_2ot_answers + 1';
array_push($generic_array, $gkey);
}
} elseif ($key == "english_2pt_1" || $key == "english_2pt_2") {
if (!in_array('english_2pt_answers = english_2pt_answers + 1', $generic_array)) {
$gkey = 'english_2pt_answers = english_2pt_answers + 1';
array_push($generic_array, $gkey);
}
} elseif ($key == "english_2sw_1" || $key == "english_2sw_2") {
if (!in_array('english_2sw_answers = english_2sw_answers + 1', $generic_array)) {
$gkey = 'english_2sw_answers = english_2sw_answers + 1';
array_push($generic_array, $gkey);
}
} else {
$keyword_generic = $key . '_answers = ' . $key . '_answers + 1';
array_push($generic_array, $keyword_generic);
}
}
$switch = 0;
} else {
$switch = 1;
}
}
$set_what_generic = implode(', ', $generic_array);
$update_generic_query = "UPDATE memberinfo SET $set_what_generic WHERE user_id = $_SESSION[user_id]";
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
mysqli_query($dbc, $update_generic_query);
mysqli_close($dbc);
}
//===============WRONG ANSWER HANDLING=====================
}
//================GET QUESTION COUNT & SCORE QUIZ===========
//============ADJUST OVERALL TOTALS AND SUCCESS RATES===================
$update_score_query = "UPDATE memberinfo SET score = total_answers * overall_success_rate WHERE user_id = $_SESSION[user_id]";
$increase_totals_query = "UPDATE memberinfo SET total_quizzes_taken = total_quizzes_taken + 1, total_answers = total_answers + $question_count, total_correct = total_correct + $score WHERE user_id = $_SESSION[user_id]";
$adjust_success_query = "UPDATE memberinfo SET overall_success_rate = (total_correct / total_answers) * 100, phys_con_success = (phys_con_correct / phys_con_answers) * 100, abbr_success = (abbr_correct / abbr_answers) * 100, anatomy_success = (anatomy_correct / anatomy_answers) * 100, society_success = (society_correct / society_answers) * 100, career_success = (career_correct / career_answers) * 100, ment_heal_success = (ment_heal_correct / ment_heal_answers) * 100, tools_success = (tools_correct / tools_answers) * 100, other_success = (other_correct / other_answers) * 100, english_1_success = (english_1_correct / english_1_answers) * 100, english_2ot_success = (english_2ot_correct / english_2ot_answers) * 100, english_2pt_success = (english_2pt_correct / english_2pt_answers) * 100, english_2sw_success = (english_2sw_correct / english_2sw_answers) * 100 WHERE user_id = $_SESSION[user_id]";
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
mysqli_query($dbc, $increase_totals_query);
mysqli_query($dbc, $adjust_success_query);
mysqli_query($dbc, $update_score_query);
//===============UPDATE THE RANKING CHARTS====================
//==========FIRS FLUSH ALL RANKINGS TO 0===================
$flush_rankings = "UPDATE memberinfo SET rank = 0";
mysqli_query($dbc, $flush_rankings);
//==========FIRS FLUSH ALL RANKINGS TO 0===================
//==========NEXT GET ELIGIBLE MEMBERS====================
$get_eligible_scores = "SELECT user_id FROM memberinfo WHERE total_quizzes_taken > 0 AND overall_success_rate >= 40 ORDER BY score DESC, overall_success_rate DESC, total_correct DESC";
$eligible_data = mysqli_query($dbc, $get_eligible_scores);
//==========NEXT GET ELIGIBLE MEMBERS====================
//==========LOOP THROUGH AND UPDATE THE DATABASE=================
$rank_number = 1;
while ($member_data = mysqli_fetch_array($eligible_data)) {
$rank_update_query = "UPDATE memberinfo SET rank = $rank_number WHERE user_id = $member_data[user_id]";
mysqli_query($dbc, $rank_update_query);
$rank_number++;
}
//==========LOOP THROUGH AND UPDATE THE DATABASE=================
//===============UPDATE THE RANKING CHARTS====================
mysqli_close($dbc);
//============ADJUST OVERALL TOTALS AND SUCCESS RATES===================
//=================DISPLAY SCORE & APPROPRIATE MESSAGE=========
echo '<div class="quiz_results">';
echo '<div class="container">';
if ($score == 10) {
echo '<h2 class="center">Perfect Score!!!</h2>';
} else if ($score > 7 && $score < 10) {
echo '<h2 class="center">Well Done!</h2>';
} else if ($score > 5 && $score < 8) {
echo '<h2 class="center">Good!</h2>';
} else if ($score > 3 && $score < 6) {
echo '<h2 class="center">Try a little harder!</h2>';
} else if ($score > 1 && $score < 4) {
echo '<h2 class="center">Oooh. Not good.</h2>';
} else if ($score <= 1) {
echo '<h2 class="center">Seriously? That bad?</h2>';
} else {
echo '<h2 class="center">How\'d you even get this score??</h2>';
}
echo '<h1 class="center">You scored ' . $score . '/' . $question_count . '</h1>';
//=================DISPLAY SCORE & APPROPRIATE MESSAGE=========
//================COMPARE AND DISPLAY ANSWERS=================
?>
<div id="quiz_table_headings" class="row">
<h2 class="col-xs-6">Correct Answer</h2>
<h2 class="col-xs-6">Your Answer</h2>
</div>
<?php
for ($i = 0; $i < $question_count; $i++) {
echo '<div id="quiz_table_question" class="row">';
echo '<p id="quiz_table_question_inner" class="col-xs-12">Question ' . ($i + 1) . ': ' . $_SESSION['question_prompts'][$i] . '</p>';
echo '</div>';
echo '<div id="quiz_table_data" class="row">';
echo '<p id="quiz_table_answer" class="col-xs-6">' . $_SESSION['correct_answers'][$i] . '</p>';
if ($_POST[$i] == $_SESSION['correct_answers'][$i]) {
echo '<p id="quiz_table_correct" class="col-xs-6">' . $_POST[$i] . '</p>';
} else {
echo '<p id="quiz_table_wrong" class="col-xs-6">' . $_POST[$i] . '</p>';
}
echo '</div>';
echo '<hr>';
}
echo '</div>';
//================COMPARE AND DISPLAY ANSWERS=================
//===========CREATE END OF QUIZ LINKS=====================
$replay_url = 'startquiz.php?';
$args_array = [];
for ($i = 0; $i < count($current_quiz); $i++) {
$arg = 'quiz' . $i . '=' . $current_quiz[$i];
array_push($args_array, $arg);
}
$link_args = "";
$link_args = implode('&', $args_array);
$replay_url .= $link_args;
//=============DISPLAY THE BUTTONS=====================
echo '<div class="container">';
echo '<div id="quiz_finish_buttons_row" class="row">';
echo '<div id="quiz_finish_buttons_col" class="col-xs-6">';
echo '<a class="centered-button" href="' . $replay_url . '">Take This Quiz Again</a>';
echo '</div>';
echo '<div id="quiz_finish_buttons_col" class="col-xs-6">';
echo '<a class="centered-button" href="quizselect.php">Back to Quiz Select</a><br />';
echo '</div>';
echo '</div></div>';
echo '</div>';
//=============DISPLAY THE BUTTONS=====================
//===========CREATE END OF QUIZ LINKS=====================
require_once('bootstrapfooter.php');
?>
I apologize for posting the entire code for each page, but I'm not a professional programmer and I'm not sure what is relevant and what isn't.
The problem has been resolved. It turns out the issue was with the php.ini file on the hosting site. They recently made some changes that I was unaware of and the temporary storage location for session files/variables became undefined. Once I edited that information in the .ini file, everything worked just fine.

Save file on specific directory inside server instead of downloading the file

I'm trying to change this below script that will works and save same file but inside server internal location instead of like it is doing now save file and then upload to my destination.
<?php
session_start();
include("includes/config.inc2.php");
#ini_set('display_errors','Off');
$quantity_store_query = ''; $quantity_store_query1 = '';
if(isset($_REQUEST['store_id']) && $_REQUEST['store_id'] != '')
{
$get_t = mysql_fetch_array(mysql_query("select quantity_store_id from tbl_website where `store_id` = '".$_REQUEST['store_id']."'"));
$quantity_store_query = " pq.quantity_store_id = '".$get_t['quantity_store_id']."' and ";
$quantity_store_query1 = " quantity_store_id = '".$get_t['quantity_store_id']."' and ";
$get_cur = mysql_fetch_array(mysql_query("SELECT currencies_id FROM currencies WHERE code = (SELECT currency FROM tbl_store WHERE store_id = {$_REQUEST['store_id']})"));
$currency = $get_cur['currencies_id'];
}
if(isset($_REQUEST['lowstock']) && $_REQUEST['lowstock'] != '')
{
define("MINI_ITMS_STOCK",5);
$data='';
$csv_output="";
$refundquery = mysql_query("select p.product_name,p.product_code,p.product_desc,p.weight,p.was_price,p.quantity,p.id,p.created_dt from product as p,product_quantity as pq where ".$quantity_store_query." p.id = pq.product_id and pq.`quantity` <= '".MINI_ITMS_STOCK."' group by pq.product_id order by p.created_dt") or die(mysql_error());
if(mysql_num_rows($refundquery) > 0)
{
$row1 = array("Item Name", "Item Code", "Description", "Weight", "Colour", "Size", "Wholesale Price", "Image1", "Image2", "Image3", "Image4", "Image5", "Quantity");
foreach ($row1 as $value1 )
{
$data .= $value1."\t";
}
$data .= "\n";
for($p=0;$p<mysql_num_rows($refundquery);$p++)
{
$orderinfo = mysql_fetch_array($refundquery);
$prod_id = $orderinfo['id'];
$product_name = stripslashes($orderinfo['product_name']);
$product_code = stripslashes($orderinfo['product_code']);
$product_desc = strip_tags(stripslashes($orderinfo['product_desc']));
$weight = stripslashes($orderinfo['weight']);
$was_price = get_table_data("product_price","price","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . " AND currencies_id = $currency");
$colour_name = 'N/A';
$size_name = 'N/A';
$quantity = $info['quantity'];
$barcode = $info['barcode'];
$psql = mysql_query("SELECT * FROM `product_quantity` where ".$quantity_store_query1." product_id = '$prod_id' and `quantity` <= '".MINI_ITMS_STOCK."' LIMIT 12") or die(mysql_error());
if(mysql_num_rows($psql) > 0)
{
for($k=0;$k<mysql_num_rows($psql);$k++)
{
$kinfo = mysql_fetch_array($psql);
$colour_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['color_id']);
$size_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['size_id']);
$images = get_image_data($prod_id,$kinfo['color_id']);
$quantity = $kinfo['quantity'];
$barcode = $kinfo['barcode'];
if($quantity <= MINI_ITMS_STOCK)
{
$export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}
$csv_output .= "\n";
}
}
}
else
{
$p_sql = mysql_query("SELECT * FROM `product` where id = $prod_id and quantity <= ".MINI_ITMS_STOCK." and is_color = 0 and is_size = 0");
if(mysql_num_rows($p_sql) > 0)
{
$kinfo = mysql_fetch_array($p_sql);
$images = get_image_data($prod_id,0);
$export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}$csv_output .= "\n";
}
}
}
$data = str_replace("\r","",$data);
$to_date = date("d-m-y-h-i-s");
$excel_name = "Low_stock_".$to_date;
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"".$excel_name.".xls\"");
header("Pragma: no-cache");
header("Expires: 0");
print $data.$csv_output;
exit;
}
}
if(isset($_REQUEST['outofstock']) && $_REQUEST['outofstock'] != '')
{
define("MINI_ITMS_STOCK",0);
$data='';
$csv_output="";
$refundquery = mysql_query("select p.product_name,p.product_code,p.product_desc,p.weight,p.was_price,p.quantity,p.id,p.created_dt from product as p,product_quantity as pq where ".$quantity_store_query." p.id = pq.product_id and pq.`quantity` <= '".MINI_ITMS_STOCK."' group by pq.product_id order by p.created_dt") or die(mysql_error());
if(mysql_num_rows($refundquery) > 0)
{
$row1 = array("Item Name", "Item Code", "Barcode", "Description", "Weight", "Colour", "Size", "Wholesale Price", "Image1", "Image2", "Image3", "Image4", "Image5", "Quantity");
foreach ($row1 as $value1 )
{
$data .= $value1."\t";
}
$data .= "\n";
for($p=0;$p<mysql_num_rows($refundquery);$p++)
{
$orderinfo = mysql_fetch_array($refundquery);
$prod_id = $orderinfo['id'];
$product_name = stripslashes($orderinfo['product_name']);
$product_code = stripslashes($orderinfo['product_code']);
$product_desc = strip_tags(stripslashes($orderinfo['product_desc']));
$weight = stripslashes($orderinfo['weight']);
$was_price = get_table_data("product_price","price","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . " AND currencies_id = $currency");
$colour_name = 'N/A';
$size_name = 'N/A';
$quantity = $info['quantity'];
$barcode = $info['barcode'];
$psql = mysql_query("SELECT * FROM `product_quantity` where ".$quantity_store_query1." product_id = '$prod_id' and `quantity` <= '".MINI_ITMS_STOCK."'") or die(mysql_error());
if(mysql_num_rows($psql) > 0)
{
for($k=0;$k<mysql_num_rows($psql);$k++)
{
$kinfo = mysql_fetch_array($psql);
$colour_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['color_id']);
$size_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['size_id']);
$images = get_image_data($prod_id,$kinfo['color_id']);
$quantity = $kinfo['quantity'];
$barcode = $kinfo['barcode'];
if($quantity <= MINI_ITMS_STOCK)
{
$export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}
$csv_output .= "\n";
}
}
}
else
{
$p_sql = mysql_query("SELECT * FROM `product` where id = $prod_id and quantity <= ".MINI_ITMS_STOCK." and is_color = 0 and is_size = 0");
if(mysql_num_rows($p_sql) > 0)
{
$kinfo = mysql_fetch_array($p_sql);
$images = get_image_data($prod_id,0);
$export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}$csv_output .= "\n";
}
}
}
$data = str_replace("\r","",$data);
$to_date = date("d-m-y-h-i-s");
$excel_name = "Out_Of_stock_".$to_date;
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"".$excel_name.".xls\"");
header("Pragma: no-cache");
header("Expires: 0");
print $data.$csv_output;
exit;
}
}
if(isset($_REQUEST['stock']) && $_REQUEST['stock'] != '')
{
define("MINI_ITMS_STOCK",'-1');
$data='';
$csv_output="";
$refundquery = mysql_query("select p.main_category_name,p.sub_category_name,p.item_collection,p.product_name,p.product_code,p.product_desc,p.weight,p.was_price,p.quantity,p.id,p.created_dt from product as p,product_quantity as pq where ".$quantity_store_query." p.id = pq.product_id and pq.`quantity` >= '".MINI_ITMS_STOCK."' group by pq.product_id order by p.created_dt") or die(mysql_error());
if(mysql_num_rows($refundquery) > 0)
{
$row1 = array("Main Category","Sub Category","Item Collection","Item Name", "Item Code", "Stock Code", "Barcode", "Description", "Weight", "Colour", "Size", "Wholesale Price", "RRP", "Image1", "Image2", "Image3", "Image4", "Image5", "Quantity", "Quantity Code");
foreach ($row1 as $value1 )
{
$data .= $value1."\t";
}
$data .= "\n";
for($p=0;$p<mysql_num_rows($refundquery);$p++)
{
$orderinfo = mysql_fetch_array($refundquery);
$prod_id = $orderinfo['id'];
$product_name = stripslashes($orderinfo['product_name']);
$product_code = stripslashes($orderinfo['product_code']);
$product_desc = strip_tags(stripslashes($orderinfo['product_desc']));
$item_collection = stripslashes($orderinfo['item_collection']);
$main_category_name = stripslashes($orderinfo['main_category_name']);
$sub_category_name = stripslashes($orderinfo['sub_category_name']);
$weight = stripslashes($orderinfo['weight']);
$was_price = get_table_data("product_price","price","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . " AND currencies_id = $currency");
$was_active = get_table_data("product_website","active","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . "");
$colour_name = 'N/A';
$size_name = 'N/A';
$quantity = $info['quantity'];
$barcode = $info['barcode'];
$psql = mysql_query("SELECT * FROM `product_quantity` where ".$quantity_store_query1." product_id = '$prod_id' and `quantity` >= '".MINI_ITMS_STOCK."'") or die(mysql_error());
$psql2 = mysql_query("SELECT * FROM `product_category` where product_id = $prod_id");
if(mysql_num_rows($psql) > 0)
if($was_active == 1)
{
for($k=0;$k<mysql_num_rows($psql);$k++)
{
$kinfo = mysql_fetch_array($psql);
$kinfo2 = mysql_fetch_array($psql2);
$category_name = get_table_data("category","cat_name","cat_id=".$kinfo2['category_id']);
$colour_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['color_id']);
$size_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['size_id']);
$images = get_image_data($prod_id,$kinfo['color_id']);
$quantity = $kinfo['quantity'];
$barcode = $kinfo['barcode'];
$RRP = ceil($was_price * 2.5);
?>
<?php
if ($quantity > 5) {
$quantity_code = 2;
} elseif ($quantity < 5) {
$quantity_code = 1;
} elseif ($quantity = 0){
$quantity_code = 0;
?>
<?php
$export=array($main_category_name,$sub_category_name,$item_collection,$product_name,$product_code,$product_code.$colour_name.$size_name,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$RRP,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity,$quantity_code);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}
$csv_output .= "\n";
}
}
}
else
{
$p_sql = mysql_query("SELECT * FROM `product` where id = $prod_id and quantity >= ".MINI_ITMS_STOCK." and is_color = 0 and is_size = 0");
if(mysql_num_rows($p_sql) > 0)
if($was_active == 1)
{
$kinfo = mysql_fetch_array($p_sql);
$images = get_image_data($prod_id,0);
$export=array($main_category_name,$sub_category_name,$item_collection,$category_name,$product_name,$product_code,$product_code.$colour_name.$size_name,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$RRP,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity,$quantity_code);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}$csv_output .= "\n";
}
}
}
$data = str_replace("\r","",$data);
$to_date = date("d-m-y-h-i-s");
$excel_name = "BANNED_STOCK_UPDATE";
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"".$excel_name.".xls\"");
header("Pragma: no-cache");
header("Expires: 0");
print $data.$csv_output;
exit;
}
}
?>

Order Custom Taxonomy by Slug in Wordpress Plugin

CONTEXT
We have created a custom taxonomy that is to be displayed as a search filter parameter in third party plugin (in the form of a checkbox). However, we want the list of taxonomies to be displayed ordered by slug.
This is the function that generates the checkbox and outputs the taxonomy - the part that we customized starts at " //create the attributes" .
public function checkbox($args)
{
//init defaults & vars
$input_args = $this->prepare_input_args($args, "checkbox");
$input_name = $input_args['attributes']['name'];
unset($input_args['attributes']['name']);
//filter the input arguments before the html is generated - allowing almost all options to be modified
if(has_filter('sf_input_object_pre')) {
$input_args = apply_filters('sf_input_object_pre', $input_args, $this->sfid);
}
//prepare html
$attibutes_html = $this->convert_attributes_to_html($input_args['attributes']);
$open_child_count = 0;
ob_start();
?>
<ul<?php echo $attibutes_html; ?>>
<?php
$last_option_depth = 0;
$option_count = count($input_args['options']);
$current_depth = 0;
$is_li_open = array();
//echo "<ul>";
for($i=0; $i<$option_count; $i++)
{
$option = &$input_args['options'][$i];
if(!isset($option->attributes))
{
$option->attributes = array(
'class' => '',
'id' => ''
);
}
//check a default has been set and set it
$option->attributes['type'] = "checkbox";
$option->attributes['value'] = $option->value;
$option->attributes['name'] = $input_name;
$option->attributes['html'] = '';
$container_attributes = array();
if($this->is_option_selected($option, $input_args['defaults']))
{
$option->attributes['checked'] = 'checked';
$option->attributes['class'] = trim($option->attributes['class']).' sf-option-active';
}
else
{
if(isset($option->attributes['checked']))
{
unset($option->attributes['checked']);
}
}
//now we want to put the class attribute on the LI, and remove from input
$option_class = $option->attributes['class'];
$option->attributes['class'] = $input_args['input_class'];
$input_id = $this->generate_input_id($input_name."_".$option->value);
$option->attributes['id'] = $input_id;
$container_attibutes_html = "";
if(isset($option->count))
{
$container_attributes['data-sf-count'] = $option->count;
$container_attibutes_html = $this->convert_attributes_to_html($container_attributes);
}
//create the attributes
$input_attibutes_html = $this->convert_attributes_to_html($option->attributes);
$option_label = $option->label;
$option_html = $option->attributes['value'];
if($input_name == "_sft_module_authors[]"){
$tax_name = "module_authors";
} else if ($input_name == "_sft_module_mindset[]") {
$tax_name = "module_mindset";
} else if ($input_name == "_sft_module_language[]") {
$tax_name = "module_language";
} else if ($input_name == "_sft_management_levels[]") {
$tax_name = "management_levels";
} else{
$tax_name = "wpdmcategory";
}
// Get the ID of a given category
$my_term = get_term_by('slug',$option->value,$tax_name);
$category_id = $my_term->term_id;
$category_desc = $my_term->description;
$category_name = $my_term->name;
$meta_image = get_wp_term_image($category_id);
// Get the URL of this category
$category_link = get_category_link( $category_id );
if ($input_name == "_sft_module_authors[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="eModal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>';
echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-8'>" . $category_desc . "</div>" . "<div class='col-md-4'>" . "<div class='img-wrap'><img src='".$meta_image."'></div></div>" . "[/modal]");
} else if ($input_name == "_sft_module_mindset[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="eModal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>';
echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-12'>" . $category_desc . "</div>" . "[/modal]");
} else if ($input_name == "_sft_module_language[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name;
} else if ($input_name == "_sft_management_level[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name;
} else {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="eModal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>';
echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-12'>" . $category_desc . "</div>" . "[/modal]");
}
if(isset($option->depth))
{//then we do depth calculations
$current_depth = $option->depth;
$close_li = true;
$open_child_list = false;
$close_ul = false;
$next_depth = -1;
if(isset($input_args['options'][$i+1]))
{
$next_option = $input_args['options'][$i+1];
$next_depth = $next_option->depth;
}
if($next_depth!=-1)
{
if($next_depth!=$current_depth)
{//there is a change in depth
if($next_depth>$current_depth)
{//then we need to open a child list
//and, not close the current li
$open_child_list = true;
$close_li = false;
}
else
{
$close_ul = true;
}
}
}
if($open_child_list)
{
$open_child_count++;
echo '<ul class="children">';
}
if($close_li)
{
echo "</li>";
}
if($close_ul)
{
$diff = $current_depth - $next_depth;
$open_child_count = $open_child_count - $diff;
$str_repeat = str_repeat("</ul></li>", $diff);
echo $str_repeat;
}
}
}
$str_repeat = str_repeat("</ul></li>", (int)$open_child_count);
echo $str_repeat;
?>
</ul>
<?php
$output = ob_get_clean();
return $output;
}

How to add more elements to specific key in array?

I am trying to convert xml node into array, i have 3 separated nodes inside parent match node, so i need to convert all them into array.
When i try this code
foreach($lineup->away->player as $player){
$awaysquad .= $player->attributes()->name . '; ';
$matcharr['name'] = (string)$player->attributes()->name;
$matcharr['number'] = (int)$player->attributes()->number;
$matcharr['playerid'] = (int)$player->attributes()->id;
$yellowcount = count(explode(" ",$player->attributes()->booking));
if(substr_count($player->attributes()->booking,"YC") == 1){
$matcharr['yellow'] = (int)$player->attributes()->id;
}
elseif((substr_count($player->attributes()->booking,"RC")==1)
or ($yellowcount == 3)){
$matcharr['red'] = (int)$player->attributes()->id;
}
}
and call this matcharr by:
print_r($matcharr);
There is just last element for each index/array, i want to get all players from lineup tag.
So print_r prints this:
Array ( [goal] => 2456166 [name] => Luís Leal [number] => 9 [playerid]
=> 2474225 [yellow] => 2486288 [subin] => 2353344 [subout] => 0 [minute] => NA )
for each match tag, but i need to get 22 players for each match.
Here is more detailed code:
foreach($week->match as $match){
$matcharr = array();
//var_dump($match);
$fixid = 0;
if($match->attributes()->id == 0 || $match->attributes()->id == ''){
if($match->attributes()->alternate_id == 0 || $match->attributes()->id == ''){
$fixid = $match->attributes()->alternate_id_2;
}
else{
$fixid = $match->attributes()->alternate_id;
}
}
else{
$fixid = $match->attributes()->id;
}
$dbdate = date('Y-m-d',strtotime($match->attributes()->date));
$dbtime = date('H:i:s', strtotime($match->attributes()->time));
//if($dbdate == date('Y-m-d')){
echo $dbdate . ' ' . date("Y-m-d");
$datetime = date('Y-m-d H:i:s',strtotime($dbdate . $dbtime));
$fcountry = $this->filterCountries($results->attributes()->country);
$stadium = $match->attributes()->venue;
$city = $match->attributes()->venue_city;
//echo $fcountry;
//$home = $match->home->attributes()->name;
//$away = $match->away->attributes()->name;
$home = '';
$away = '';
$homeid = 0;
$awayid = 0;
$hgoals = 0;
$agoals = 0;
if($match->home){
$home = $this->getMap($fcountry,$match->home->attributes()->name);
$away = $this->getMap($fcountry,$match->away->attributes()->name);
$homeid = $this->filterTeams($fcountry,$match->home->attributes()->id);
$awayid = $this->filterTeams($fcountry,$match->away->attributes()->id);
$hgoals = $match->home->attributes()->score;
$agoals = $match->away->attributes()->score;
}
$eventname = $home . ' - ' . $away;
$halftimehomegoals = 0;
$halftimeawaygoals = 0;
if($match->halftime->attributes()->score != NULL){
$halftime = explode("-",$match->halftime->attributes()->score);
$halftimehomegoals = (int)$halftime[0];
if(array_key_exists(1,$halftime)){
$halftimeawaygoals = (int)$halftime[1];
}
}
$homescore = '';
$awayscore = '';
if($match->goals->goal != NULL){
foreach($match->goals->goal as $goal){
if($goal->attributes()->team == 'home'){
$homescore .= $goal->attributes()->minute.': '.
$goal->attributes()->player.'; ';
$matcharr['goal'] = (int)$goal->attributes()->playerid;
}
elseif($goal->attributes()->team == 'away'){
$awayscore .= $goal->attributes()->player.'; ';
$matcharr['goal'] = (int)$goal->attributes()->playerid;
}
}
}
$homesquad = '';
$awaysquad = '';
if($match->lineups != NULL){
foreach($match->lineups as $lineup){
if($lineup->home->player != NULL){
foreach($lineup->home->player as $player){
$homesquad .= $player->attributes()->name . '; ';
$matcharr['name'] = (string)$player->attributes()->name;
$matcharr['number'] = (int)$player->attributes()->number;
$matcharr['playerid'] = (int)$player->attributes()->id;
$yellowcount = count(explode(" ",$player->attributes()->booking));
if(substr_count($player->attributes()->booking,"YC") == 1){
$matcharr['yellow'] = (int)$player->attributes()->id;
}
elseif((substr_count($player->attributes()->booking,"RC")==1)
or ($yellowcount == 3)){
$matcharr['red'] = (int)$player->attributes()->id;
}
}
}
if($lineup->away->player != NULL){
foreach($lineup->away->player as $player){
$awaysquad .= $player->attributes()->name . '; ';
$matcharr['name'] = (string)$player->attributes()->name;
$matcharr['number'] = (int)$player->attributes()->number;
$matcharr['playerid'] = (int)$player->attributes()->id;
$yellowcount = count(explode(" ",$player->attributes()->booking));
if(substr_count($player->attributes()->booking,"YC") == 1){
$matcharr['yellow'] = (int)$player->attributes()->id;
}
elseif((substr_count($player->attributes()->booking,"RC")==1)
or ($yellowcount == 3)){
$matcharr['red'] = (int)$player->attributes()->id;
}
}
}
}
}
$homesub = '';
$awaysub = '';
if($match->substitutions != NULL){
foreach($match->substitutions as $subs){
if($subs->home->substitution != NULL){
foreach($subs->home->substitution as $sub){
$homesub .= $sub->attributes()->minute."' in: ".
$sub->attributes()->player_in_name . '; ' . ' out: ' .
$sub->attributes()->player_out_name . '; ';
$matcharr['subin'] = (int)$sub->attributes()->player_in_id;
$matcharr['subout'] = (int)$sub->attributes()->player_out_id;
$matcharr['minute'] = (string)$sub->attributes()->minute;
}
}
if($subs->away->substitution != NULL){
foreach($subs->away->substitution as $sub){
$awaysub .= $sub->attributes()->minute."' in: ".
$sub->attributes()->player_in_name . '; ' .
$sub->attributes()->player_out_name . '; ';
$matcharr['subin'] = (int)$sub->attributes()->player_in_id;
$matcharr['subout'] = (int)$sub->attributes()->player_out_id;
$matcharr['minute'] = (string)$sub->attributes()->minute;
}
}
}
}
echo $leaguename . ' ' . $leagueid . ' ' . $fixid . ' ' . $eventname.'<br>';
print_r($matcharr);
Add some counter variable before storing it in array like below
$element_count = 0;//Counter variable
foreach ($lineup->away->player as $player) {
$awaysquad .= $player->attributes()->name . '; ';
$matcharr[$element_count]['name'] = (string)$player->attributes()->name;
$matcharr[$element_count]['number'] = (int)$player->attributes()->number;
$matcharr[$element_count]['playerid'] = (int)$player->attributes()->id;
$yellowcount = count(explode(" ", $player->attributes()->booking));
if (substr_count($player->attributes()->booking, "YC") == 1) {
$matcharr[$element_count]['yellow'] = (int)$player->attributes()->id;
}
elseif ((substr_count($player->attributes()->booking, "RC") == 1) or ($yellowcount == 3)) {
$matcharr[$element_count]['red'] = (int)$player->attributes()->id;
}
$element_count++;
}

How To Change Numbers Based On Results

I have a follow up question on something I got help with here the other day (No Table Three Column Category Layout).
The script is as follows:
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);
$parent_node = mysql_fetch_assoc($res);
$id = (isset($parent_node['cat_id'])) ? $parent_node['cat_id'] : $id;
$catalist = '';
if ($parent_node['left_id'] != 1)
{
$children = $catscontrol->get_children_list($parent_node['left_id'], $parent_node['right_id']);
$childarray = array($id);
foreach ($children as $k => $v)
{
$childarray[] = $v['cat_id'];
}
$catalist = '(';
$catalist .= implode(',', $childarray);
$catalist .= ')';
$all_items = false;
}
$NOW = time();
/*
specified category number
look into table - and if we don't have such category - redirect to full list
*/
$query = "SELECT * FROM " . $DBPrefix . "categories WHERE cat_id = " . $id;
$result = mysql_query($query);
$system->check_mysql($result, $query, __LINE__, __FILE__);
$category = mysql_fetch_assoc($result);
if (mysql_num_rows($result) == 0)
{
// redirect to global categories list
header ('location: browse.php?id=0');
exit;
}
else
{
// Retrieve the translated category name
$par_id = $category['parent_id'];
$TPL_categories_string = '';
$crumbs = $catscontrol->get_bread_crumbs($category['left_id'], $category['right_id']);
for ($i = 0; $i < count($crumbs); $i++)
{
if ($crumbs[$i]['cat_id'] > 0)
{
if ($i > 0)
{
$TPL_categories_string .= ' > ';
}
$TPL_categories_string .= '' . $category_names[$crumbs[$i]['cat_id']] . '';
}
}
// get list of subcategories of this category
$subcat_count = 0;
$query = "SELECT * FROM " . $DBPrefix . "categories WHERE parent_id = " . $id . " ORDER BY cat_name";
$result = mysql_query($query);
$system->check_mysql($result, $query, __LINE__, __FILE__);
$need_to_continue = 1;
$cycle = 1;
$column = 1;
$TPL_main_value = '';
while ($row = mysql_fetch_array($result))
{
++$subcat_count;
if ($cycle == 1)
{
$TPL_main_value .= '<div class="col'.$column.'"><ul>' . "\n";
}
$sub_counter = $row['sub_counter'];
$cat_counter = $row['counter'];
if ($sub_counter != 0)
{
$count_string = ' (' . $sub_counter . ')';
}
else
{
if ($cat_counter != 0)
{
$count_string = ' (' . $cat_counter . ')';
}
else
{
$count_string = '';
}
}
if ($row['cat_colour'] != '')
{
$BG = 'bgcolor=' . $row['cat_colour'];
}
else
{
$BG = '';
}
// Retrieve the translated category name
$row['cat_name'] = $category_names[$row['cat_id']];
$catimage = (!empty($row['cat_image'])) ? '<img src="' . $row['cat_image'] . '" border=0>' : '';
$TPL_main_value .= "\t" . '<li>' . $catimage . '' . $row['cat_name'] . $count_string . '</li>' . "\n";
++$cycle;
if ($cycle == 7) // <---- here
{
$cycle = 1;
$TPL_main_value .= '</ul></div>' . "\n";
++$column;
}
}
if ($cycle >= 2 && $cycle <= 6) // <---- here minus 1
{
while ($cycle < 7) // <---- and here
{
$TPL_main_value .= ' <p> </p>' . "\n";
++$cycle;
}
$TPL_main_value .= '</ul></div>'.$number.'
' . "\n";
}
I was needing to divide the resulting links into three columns to fit my html layout.
We accomplished this by changing the numbers in the code marked with "// <---- here".
Because the amount of links returned could be different each time, I am trying to figure out how to change those numbers on the fly. I tried using
$number_a = mysql_num_rows($result);
$number_b = $number_a / 3;
$number_b = ceil($number_b);
$number_c = $number_b - 1;
and then replacing the numbers with $number_b or $number_c but that doesn't work. Any ideas?
As mentioned before, you can use the mod (%) function to do that.
Basically what it does is to get the remainder after division. So, if you say 11 % 3, you will get 2 since that is the remainder after division. You can then make use of this to check when a number is divisible by 3 (the remainder will be zero), and insert an end </div> in your code.
Here is a simplified example on how to use it to insert a newline after every 3 columns:
$cycle = 1;
$arr = range (1, 20);
$len = sizeof ($arr);
for ( ; $cycle <= $len; $cycle++)
{
echo "{$arr[$cycle - 1]} ";
if ($cycle % 3 == 0)
{
echo "\n";
}
}
echo "\n\n";

Categories