PHP - Dynamic Checkbox List
Hello all, I found this dynamic checkbox list online. I have changed it to suit my needs, added some of my own parts but now, after getting past all the terminal errors, it now produces absolutely nothing. Can I get some help on why there is no echo occurring? Thanks!
<?php function dynamic_checkbox_table ($sql_str, $col_label, $col_name, $val_checked, $cant_cols_tbl){ $sql_str = dynamic_checkbox_table("SELECT * FROM Categories"); $col_label = "catlevel3"; $col_name = "catlevel3"; $val_checked="S"; $cant_cols_tbl=3; //connect DB and run query $db="TB"; $db_user=""; $pass=""; $host="localhost"; @mysql_connect($host,$db_user,$pass); @mysql_select_db($db) or die ("cannot connect to DB"); $q_resultado = mysql_query($sql_str); mysql_close(); if (mysql_num_rows($q_resultado)==0) exit("no rows returned"); $next_row = mysql_fetch_array($q_resultado); //fetch first row $output = "<table border=\"1\">\n"; //open table tag do { $output .= "<tr>\n"; //open row tag for ($i=1 ; $i <= $cant_cols_tbl ; $i++ ){ //loops as many times as $cant_cols_tbl $row=$next_row; $output .= "<td>"; //open TD tag $output .= (!$row) ? "" : '<input type="checkbox" name="'.$row[$col_name].'" value="'.$val_checked.'" />'.$row[$col_label]; echo (!$row) ? "" : '<input type="checkbox" name="'.$row[$col_name].'" value="'.$row[$val_checked].'" />'.$row[$col_label]; $next_row = mysql_fetch_array($q_resultado); //retrieve next row $output .= "</td>\n"; //close TD } //close for loop $output .= "</tr>\n"; //close row } while ($next_row); //close do-while (and checks if there's another row) $output .= "</table>\n"; //close table return $output; } ?> Similar TutorialsHi, I use the following code to create a select menu from an array of options stored in LISTS.php: include 'LISTS.php'; print('<select id="from" name="from">'); foreach ($langList as $lang) {printf('<option %s>%s</option>', ($from1 == $lang ? 'selected="selected"' : ''), $lang); } echo '</select>'; where LISTS.php includes the following: $langList = array(' ','English', 'French', 'German', 'Dutch', 'Spanish'); This works great, but now I want to do something similar with a checkbox list, where each checkbox has an associated 'onchange' javascript function and I'm getting pretty stuck. My checkbox list is of the following form: Code: [Select] <html> <ul style="height: 95px; overflow: auto; width: 200px; border: 1px solid #480091; list-style-type: none; margin: 0; padding: 0;"> <li id="li1b"><label for="chk1b"><input name="chk1b" id="chk1b" type="checkbox" onchange="function1('chk1b','li1b')">Option1</label></li> <li id="li2b"><label for="chk2b"><input name="chk2b" id="chk2b" type="checkbox" onchange="function1('chk2b','li2b')">Option2</label></li> //etc. </ul> </html> What I want to do is have 'Option1', 'Option2', etc. stored in an array in LISTS.php and have a PHP script that populates the checkbox list accordingly, in a similar manner to my select menu above. I can't work out how to get the ID of the next <li> and the next <input> in the list to go up by one each time, e.g. 'li1b' then 'li2b', 'li3b', etc. Could someone pls help me out? Thanks! Hi , I have one question .. Can I split showing of content of dynamic list in 2 parts , when I echo list in code .. Code: [Select] <?php // Run a select query to get my letest 8 items // Connect to the MySQL database include "../connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 8"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<table width="100%" border="2" cellspacing="2" cellpadding="2"> <tr> <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="2" /></a></td> <td width="83%" valign="top">' . $product_name . '<br /> $' . $price . '<br /> <a href="product.php?id=' . $id . '">View Product Details</a></td> </tr> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Code: [Select] <p><?php echo $dynamicList; ?><br /> </p> It works ok, and putting my files, everything works, but when I put 8 pictures with price and other details, it just show one image with details and another image below with details, and the third image below and so on .. Can I split dynamic list to show 4 images with details on the left side and 4 on the right side? Thank you in advance for help , if is possible Here is the issue: I am creating an input form which would allow someone to check multiple boxes. These checkboxes are populated from a table called reasonforcare. Here is my code: Quote <?php $rows = mysql_num_rows($reasonforcare); for ($i=0; $i < $rows; ++$i) { $row = mysql_fetch_row($reasonforcare); echo "<input name='reasonforcare' type='checkbox' value='" . $row[0] . "'/>"; echo $row[1]; } ?> I get all the checkboxes to show up, but at the end of the last database entry there is an extra checkbox! Can someone help me figure out why this is happening? I got some great help from DavidAM a few days ago that gave me a working function for updating checkboxes when unselected during an editing process later. I was looking for a way to overwrite the old array of values if ALL of the checkboxes were unchecked. The SOLUTION was done with some hard-coding of checkboxes names. I have written a function to find out which checkbox names are going to be called for this form (it can be different multi-value checkboxes loaded depending on the Category of Post the user is trying to make). Now I would like to apply whatever values that come up in a foreach loop after querying the WordPress database to the following function so that instead of hard-coding these three separate multi-value checkboxes I can generate the dynamic code that takes the place of the following: Notice that it needs to know the names of the checkboxes first so I need a looping foreach statement that will takes the results of the query before this that returns an array such as example: (cp_checkbox_help,cp_checkbox_new,cp_checkbox_old,cp_checkbox_stuff) What the query returns in names and the quantity count of these names will vary according to the category id that is passed when the user decides to post into a particular category. if($post_id) { // Make sure the checkbox arrays exist if (! isset($_POST['cp_checkbox_charley'])) $_POST['cp_checkbox_charley'] = array(); if (! isset($_POST['cp_checkbox_help'])) $_POST['cp_checkbox_help'] = array(); if (! isset($_POST['cp_checkbox_hello'])) $_POST['cp_checkbox_hello'] = array(); // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) { if (cp_str_starts_with($meta_key, 'cp_checkbox_charley')) { if (isset($_POST['cp_checkbox_charley'])) $meta_value= implode(',', $_POST['cp_checkbox_charley']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) { if (isset($_POST['cp_checkbox_help'])) $meta_value = implode(',', $_POST['cp_checkbox_help']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) if (isset($_POST['cp_checkbox_hello'])) $meta_value= implode(',', $_POST['cp_checkbox_hello']); else $meta_value = ''; } update_post_meta($post_id, $meta_key, $meta_value); } from a query (I have now built) at this point in the process the script will have returned whatever checkbox names such as cp_checkbox_hello, cp_checkbox_hello, cp_checkbox_charley are relevant to the specific form that is attached to the online Post category a user is trying to Post to. Just what checkbox names are the result of this query will vary according to the Category Id assigned to this Post form. A different category id may bring a different post form to fill out with different multi-value checkboxes names. Which is why this has to be dynamic to take 2 or 3 or 4 or whatever number of names return for checkbox names and then create the following code to handle a variable number of checkboxes that must have the name values filled in. I hope I have explained this clearly enough-- that I want to make the code example dynamic-- right now it takes care of 3 specifically named checkboxes--- I want to get rid of the hardcode and write all of that dynamically, looping through to take care of every situation and every checkbox that may show up. Thank you for taking the time to consider this thoughtfully! Hi All, I've a loop which lists a series of options as checkboxes. What I'd like to do is set 1 as a default. But I've no idea how to do it!? Here's the code: <?php $i = 0; ?> <?php if ( bp_has_groups() ) : while ( bp_groups() ) : bp_the_group(); ?> <input type="checkbox" id="field_reg_groups_<?php echo $i; ?>" name="field_reg_groups[]" value="<?php bp_group_id(); ?>" /><?php bp_group_name(); ?> <?php } ?> <?php $i++; ?> Any help is much appreciated TIA Hi, basically, here's the deal: I have a lit of checkboxes that are added by the admin (there's an unlimited amount, just depends on how many are added). Then, those are put in a form, in which the user picks whichever ones need to be chosen and those values get sent to a MySQL table. Here's the code that displays the checkboxes Code: [Select] <?php $sql="SELECT * FROM category ORDER BY categoryID ASC"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ echo "<input type='checkbox' id='". $row['categoryName'] ."' name='licensed[]' value='" . $row['categoryID'] ."' /><label for='". $row['categoryName'] ."'><br>" . $row['categoryName'] ."</label><br>"; } ?> What I'm making now, is an edit form where whichever checkboxes were checked, will show up checked in the edit form. But I'm not really sure how to go about this, since there is only one actual input tag in the code, I can't select the different ones. I also have this SQL query which selects whichever boxes were inputted into the DB Code: [Select] $sql2="SELECT * FROM category, categoryInfo WHERE category.categoryID = categoryInfo.categoryID AND categoryInfo.parentID = $parentID"; $result2=mysql_query($sql2); Where $parentID is the ID of whichever form you're editing. But yes, I'm basically not really sure how to go about this and would like some help figuring this out Thanks for your time Ok, so I've spent quite a bit of time piecing together this solution from a variety of sources. As such, I may have something in my code below that doesn't make sense or isn't neccessary. Please let me know if that is the case. I'm creating an administrative form that users will you to add/remove items from a MySQL table that lists open positions for a facility. The foreach loop generates all of the possible job specialties from a table called 'specialty_list'. This table is joined to a second table ('open_positions') that lists any positions that have been selected previously. Where I'm stuck is getting the checkbox to be checked if the facility_ID from the open_positions table matches the $id passed in the URL via ?facility_id=''. Here's where I am so far: $query = "SELECT specialty_list.specialty_displayname , specialty_shortname , open_positions.position , facility_ID FROM specialty_list LEFT OUTER JOIN open_positions ON open_positions.position = specialty_list.specialty_shortname ORDER BY specialty_list.specialty_shortname"; $results = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($results)) { $positions[$row['specialty_shortname']] = $row['specialty_displayname']; } echo "<form method='POST' action='checkbox.php'>"; foreach($positions as $specialty_shortname => $specialty_displayname) { $facility_ID = $row['facility_ID']; $checked = $facility_ID == $row['facility_ID'] ? ' checked' : ''; echo "<input type='checkbox' name='position[]' value=\"{$specialty_shortname}\"{$checked}> {$specialty_displayname}</input><br/>"; } echo "<input type='hidden' name='facility_ID' value='$id'>"; echo "<input type='submit' value='Submit Checkboxes!'>"; echo "</form>"; Any ideas how to get this working? I feel like I'm very close, but I just can't get it. I also tried starting from scratch with a WHILE statement instead of a FOREACH, but haven't tweaked it enough to prevent duplicate checkboxes. With that in mind, here it is, just in case that's a better direction: $query = "SELECT specialty_list.specialty_displayname , specialty_shortname , open_positions.position , facility_ID FROM specialty_list LEFT OUTER JOIN open_positions ON open_positions.position = specialty_list.specialty_shortname ORDER BY specialty_list.specialty_shortname"; $results = mysql_query($query) or die(mysql_error()); echo "<form method='POST' action='checkbox.php'>"; while($row=mysql_fetch_assoc($results)) { $facility_ID = $row['facility_ID']; $specialty_shortname = $row['specialty_shortname']; $specialty_displayname = $row['specialty_displayname']; if ($facililty_ID==$id) { $checked=' checked'; } echo "<input type='checkbox' name='position[]' value=\"$specialty_shortname\"$checked> $specialty_displayname</input><br/>"; } echo "<input type='hidden' name='facility_ID' value='$id'>"; echo "<input type='submit' value='Submit Checkboxes!'>"; echo "</form>"; Hello PhpFreaks... been a while since I stopped by. I need to reach out for some assistance. The task I am trying to complete seems so simple, but I can't get my brain around it and have searched through these forums and the almighty google and have not found what I need. So here is what I need some directions on. I am trying to create a multi-level un-ordered list using PHP & MySQL. It is going to be a database driven menu with an unknown number of parent items with 0 or more child items. Surely I am not the first one to need to solve this problem, but cannot find the simplest solution that gets me what I want. Ok.. so I got a table setup like this with some test data in it.... Code: [Select] CREATE TABLE IF NOT EXISTS `navigation` ( `linkId` int(11) NOT NULL AUTO_INCREMENT, `displayName` varchar(255) NOT NULL, `url` varchar(255) NOT NULL, `parentId` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`linkId`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; INSERT INTO `navigation` (`linkId`, `displayName`, `url`, `parentId`) VALUES (1, 'Home', '/', 0), (2, 'City Hall', '/city_hall/', 0), (3, 'City Council', '/city_council', 0), (4, 'Upcoming Meetings', '/city_council/upcoming_meetings.php', 3), (5, 'Past Minutes', '/city_council/past_minutes', 3), (6, 'Council Members', '/city_council/council_members.php', 3), (7, 'Forms & Downloads', '/downloads', 0), (8, 'Parks & Recreation', '/parks', 0), (9, 'Park Name', '/parks/park.php', 8), (10, 'Another Link', '/parks/link2.php', 8); I have a query and loop that grabs the entire menu, and places it in 2 arrays to separate the top-level parent items and the items that have a parent id != 0. $items = $db->getData("SELECT linkId, displayName, url, parentId FROM navigation ORDER BY parentId, linkId ASC"); while ($row = mysql_fetch_object($items['result'])) { if ($row->parentId == 0) { $parent_menu[$row->linkId]['label'] = $row->displayName; $parent_menu[$row->linkId]['link'] = $row->url; } else { $sub_menu[$row->linkId]['parent'] = $row->parentId; $sub_menu[$row->linkId]['label'] = $row->displayName; $sub_menu[$row->linkId]['link'] = $row->url; } } That gives me an array that looks like this. Code: [Select] Array( [1] => Array ( [label] => Home [link] => / ) [2] => Array ( [label] => City Hall [link] => /city_hall/ ) [3] => Array( [label] => City Council [link] => /city_council ) [7] => Array( [label] => Forms & Downloads [link] => /downloads ) [8] => Array( [label] => Parks & Recreation [link] => /parks ) ) Array ( [4] => Array( [parent] => 3 [label] => Upcoming Meetings [link] => /city_council/upcoming_meetings.php ) [5] => Array( [parent] => 3 [label] => Past Minutes [link] => /city_council/past_minutes ) [6] => Array( [parent] => 3 [label] => Council Members [link] => /city_council/council_members.php ) [9] => Array( [parent] => 8 [label] => Park Name [link] => /parks/park.php ) [10] => Array( [parent] => 8 [label] => Another Link [link] => /parks/link2.php ) ) Taking that array and doing a couple loops, gets me close (sorta.. I realize that there needs to be recursion for this to work). echo '<ul>'."\r\n"; foreach($parent_menu as $pid => $pvalue){ echo ' <li><a href="'.$pvalue['link'].'">'.$pvalue['label'].'</a>'."\r\n"; foreach($sub_menu as $sid => $svalue){ if($svalue['parent'] == $pid){ echo ' <li>'.$svalue['label'].'</li>'."\r\n"; } } echo '</li>'."\r\n"; } echo '</ul>'."\r\n"; That gets me a list that is not quite correct markup. The nested <ul> items are missing because I could not determine the best way to do this. The goal for the data presented here is to be marked up like this. Code: [Select] <ul> <li><a href="/">Home</a></li> <li><a href="/city_hall">City Hall</a></li> <li><a href="/city_council">City Council</a> <ul> <li><a href="/city_council/upcoming_meetings.php">Upcoming Meetings</a></li> <li><a href="/city_council/past_minutes">Past Minutes</a></li> <li><a href="/city_council/council_members.php">Council Members</a></li> </ul> </li> <li><a href="/downloads">Forms & Downloads</a></li> <li><a href="/parks">Parks & Recreation</a> <ul> <li><a href="/parks/park.php">Park 1</a></li> <li><a href="/parks/link2.php">Another Link</a></li> </ul> </li> </ul> Thats where I am at here. Any ideas or tips would be helpful and appreciated. So anyone solved this problem before? Sorry for the long post, but I wanted to give all information and code that I have. Thanks in advance, Nathan Hi there, I'm a movie freak and I'm planning of building a simple dynamic movie list. There are some movie lister software available on internet, but I want it lighter and customized. Here is the idea: It looks like yahoo mail inbox...I want to create this script based on php and sql. I think this is the right place where can I get some help. Thanks in advance. NaimeniM Hey guys, I can't wrap my head around how to make this work right... I have three tables: Code: [Select] CREATE TABLE `games` ( `g_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(150) DEFAULT NULL, PRIMARY KEY (`g_id`)); CREATE TABLE IF NOT EXISTS `game_player` ( `r_id` int(11) NOT NULL AUTO_INCREMENT, `p_id` int(11) DEFAULT NULL, `g_id` int(11) DEFAULT NULL, `bool` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`r_id`)); CREATE TABLE IF NOT EXISTS `players` ( `p_id` int(11) NOT NULL AUTO_INCREMENT, `playerid` varchar(150) NOT NULL, PRIMARY KEY (`p_id`), UNIQUE KEY `playerid` (`playerid`)); The players table is my list of users, and they're tied to the list of games via the game_player table. So here's my issue... I'm trying to show the full list of games, and then check mark each record where the player does play it. This is what I have so far - it shows all the games, but it's not checking the boxes. Code: [Select] $result = mysql_query("SELECT * FROM games") or die(mysql_error()); while($row = mysql_fetch_array($result)) { $newquery = "SELECT * FROM game_player, players WHERE game_player.p_id = players.p_id AND game_player.g_id = ".$row['g_id']. " AND players.playerid = {$userid}"; $query = mysql_query($newquery) or die(mysql_error()); if($query['bool'] == 1) { $set_checked = " CHECKED"; } else{ $set_checked = ""; } echo "<input type=\"checkbox\" name=\"box1\" value=\"".$query['g_id']."\"" . $set_checked . "/>".$row['name']."<br />\n"; } please help me the concept or code to retrive data from the database and display data according to the data from the dynamic list box option. Hi, I am hoping someone can help me out with a slight issue I have with php and mySQL. I have an ajax-powered form with a select (dropdown) field populated through a php function. Based on the user-selected values in this field, data is displayed on the webpage; i.e. selected value 1 returns values x and y on the page. I am now trying to call additional data (value z) from a different table in the same database, and as before, use the selected values from the dropdown to display the data. For some reason, value z is not changing according to the user-selected value. This is my code: [The function to populate the select field] Code: [Select] function kfl_get_funds_names() { $result = array(); $result['CDF'] = 'Crosby Dragon Fund'; $result['CPF'] = 'Crosby Phoenix Fund'; $result['AMZPIF'] = 'AMZ Plus Income Fund'; $result['KASBIIF'] = 'KASB Islamic Income Opportunity'; $result['KASBCPGF'] = 'KASB Capital Protected Gold Fund'; $result['KASBLF'] = 'KASB Income Opportunity Fund'; $result['KASBCF'] = 'KASB Cash Fund'; $result['KASBBF'] = 'KASB Asset Allocation Fund'; $result['KASBSMF'] = 'KASB Stock Market Fund'; return $result; } [the code calling and using the function to interact with the database] Code: [Select] $funds_to_display = kfl_get_funds_names(); $current_symbol = key( $funds_to_display ); $current_nav_rates = kfl_get_latest_rates( $current_symbol ); [the code calling additional data, value z, from the database, and using the info in the select field to filter it] Code: [Select] $cutoff = kfl_cutoff( $current_symbol ); The display of each of these items is as follows: Code: [Select] <?php echo $current_nav_rates['nav_date']; ?> <?php echo $funds_to_display[$current_symbol]; ?> <?php echo $cutoff['cutoff']; ?> I can't get the $cutoff code to display the correct values. It picks up the first symbol to display and doesn't change with user selection. The code for the selection box, by the way: Code: [Select] <select id="dailynav-funds" autocomplete="off" name="dnf"> <?php foreach ($funds_to_display as $fund_symbol => $fund_name) { echo '<option'; if( $fund_symbol == $current_symbol ) { echo ' selected="selected"'; } echo ' value="' . $fund_symbol . '">'; echo $fund_name; echo '</option>'; } ?> </select> I've tried to get data using $_GET['dnf'] into the cutoff code, but that throws up parse errors. What am I doing wrong, and how can I resolve this issue? Thanks in advance! Hi, i m new with php programming... I m working on one form in which i have created filter options for filter dynamic table content by completed, approve and rejected status.... but problem is when i m selecting any filtered option using select list data is displayed... but when i m clicking on next button in paging... dynamic table showing blank... same slect list getting blank.... anyone will help me...? code of php file Code: [Select] <?php require_once('../Connections/localhost.php'); ?> <?php if (!isset($_SESSION)) { session_start(); } $MM_authorizedUsers = "client"; $MM_donotCheckaccess = "false"; // *** Restrict Access To Page: Grant or deny access to this page function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { // For security, start by assuming the visitor is NOT authorized. $isValid = False; // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. // Therefore, we know that a user is NOT logged in if that Session variable is blank. if (!empty($UserName)) { // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. // Parse the strings into arrays. $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } // Or, you may restrict access to only certain users based on their username. if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && false) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "../index.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) $MM_referrer .= "?" . $_SERVER['QUERY_STRING']; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Recordset1 = 30; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; $myID = $_SESSION['MM_Username']; $mystatus=$_GET['status']; switch ($options) { case "All"; $All="selected"; break; case "Completed"; $Completed="selected"; break; case"Rejected"; $Rejected="selected"; break; case"Pending"; $Pending="selected"; break; } $mystatus=$_POST['status']; $maxRows_Recordset1 = 10; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; //databse queary for filters $query_Recordset1 = "SELECT username, Jobid, Market, General_10, Entry_Points, Dept_Points, General_Points, Total_Points FROM form_gf "; if($mystatus !=='All'){ $query_Recordset1 .= "WHERE status = '$mystatus'";} else { $query_Recordset1 .= "ORDER BY form_gf.Jobid";} mysql_select_db($database_localhost, $localhost); $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $localhost) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; mysql_select_db($database_localhost, $localhost); $query_status = "SELECT dropdown.options FROM dropdown WHERE dropdown.dropdownname = 'status'"; $status = mysql_query($query_status, $localhost) or die(mysql_error()); $row_status = mysql_fetch_assoc($status); $totalRows_status = mysql_num_rows($status);mysql_select_db($database_localhost, $localhost); $query_status = "SELECT options FROM dropdown WHERE dropdownname = 'status' ORDER BY options ASC"; $status = mysql_query($query_status, $localhost) or die(mysql_error()); $row_status = mysql_fetch_assoc($status); $totalRows_status = mysql_num_rows($status); $queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Brakedown Report</title> <link href="../template.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="../Menu/js/jquery.js"></script> <script type="text/javascript" src="../Menu/js/interface.js"></script> <script type="text/javascript" src="../Menu/js/fisheye_patched.js"></script> <!--[if lt IE 7]> <style type="text/css"> .dock img { behavior: url(iepngfix.htc) } </style> <![endif]--> <link href="../Menu/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .Header { font-family: "Segoe UI"; font-size: 12px; font-weight: 500; color: #CCC;} .table { font-family: "Segoe UI"; font-size: 10pt; border: 1px solid #000; } .text { font-family: "Segoe UI"; font-size: 10pt; } a { font-family: "Segoe UI"; font-size: 12px; color: #333; font-weight: bold; } a:link { text-decoration: none; } a:visited { text-decoration: none; color: #333; } a:hover { text-decoration: none; color: #36F; } a:active { text-decoration: none; color: #333; } </style> </head> <body> <!--Wrapper Start--> <div id="wrapper"> <!--Header Start--> <div id="header"> <div id="logo"><img src="../images/logo.png" alt="isnlogo" width="64" height="30" align="middle" longdesc="http://www.isngs.com" /></div> <div id="userinfo"> <table width="180" border="0" align="right" cellpadding="0" cellspacing="0"> <tr> <td width="27" height="34"><img src="../images/user.png" width="26" height="30" alt="user" /></td> <td width="77">Sagar Dhande</td> <td width="26"><img src="../images/arrow.png" width="26" height="30" alt="arrow" /></td> </tr> </table> </div> <div id="status"></div> </div> <!--Header end--> <div id="content"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr align="center"> <td width="99%"> <div id="dash3"> <div id="dash3_grid_head">Total Reccords </div> <div id="dash3_grid_cont_back"><br /> <table width="890" border="0" align="center" cellpadding="0" cellspacing="0" class="table"> <tr class="Header"><form action="" method="post"> <td height="55" colspan="3" align="center" valign="middle" id="filters">Filter By Status</td> <td align="left" valign="middle"><select name="status" id="status2" onchange="document.forms[0].submit();"> <option value="" <?php if (!(strcmp("", $mystatus))) {echo "selected=\"selected\"";} ?>></option> <?php do { ?> <option value="<?php echo $row_status['options']?>"<?php if (!(strcmp($row_status['options'], $mystatus))) {echo "selected=\"selected\"";} ?>><?php echo $row_status['options']?></option> <?php } while ($row_status = mysql_fetch_assoc($status)); $rows = mysql_num_rows($status); if($rows > 0) { mysql_data_seek($status, 0); $row_status = mysql_fetch_assoc($status); } ?> </select></td> <td align="left" valign="bottom"><a href="excel.php"></a></td> <td align="left" valign="bottom"> </td> <td align="center" valign="middle"><a href="../excelexprt.php"></a></td> <td align="center" valign="middle"> </td> <td align="center" valign="middle"> </td> <td align="right" valign="middle"><a href="excel.php"><img src="../images/Export.png" alt="Export" width="48" height="48" border="0" /></a></td> </form> </tr> <tr class="Header"> <td height="2" colspan="10" align="center" valign="bottom" id="filters3"><hr color="#333333" size="1px"/></td> </tr> <tr class="Header"> <td height="345" colspan="10" align="center" valign="bottom" id="filters"><a href="../excelexprt.php"> <iframe src="pai1.php" width="485px" height="370px" frameborder="0"></iframe> </a></td> </tr> <tr class="Header"> <td height="22" colspan="3" align="center" valign="bottom" id="filters2"> </td> <td align="left" valign="bottom"> </td> <td align="left" valign="bottom"> </td> <td align="left" valign="bottom"> </td> <td colspan="4" align="center" valign="middle"> </td> </tr> <tr class="Header"> <td style="border: 1px solid #000;" height="44" colspan="3" align="center" valign="middle" bgcolor="#666666">Options</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666" class="Header">Job ID</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Market ID</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Transaction No.</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Entry Points</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Department Points</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">General Points</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Total Points</td> </tr> <?php do { ?> <tr> <td width="31" height="28" align="center" style="border: 1px solid #000;"><a href="../pdf.php?Jobid=<?php echo $row_Recordset1['Jobid']; ?>" target="_blank"><img src="../images/pdf.png" alt="PDF Export" width="16" height="16" border="0" /></a></td> <td width="31" style="border: 1px solid #000;" align="center"><a href="../view.php?Jobid=<?php echo $row_Recordset1['Jobid']; ?>" target="_blank"><img src="../images/preview.png" alt="Preview" width="16" height="16" border="0" /></a></td> <td width="31" style="border: 1px solid #000;" align="center"><a href="../update_form.php?Jobid=<?php echo $row_Recordset1['Jobid']; ?>" target="_blank"><img src="../images/Edit.png" alt="Edit" width="16" height="16" border="0" /></a></td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Jobid']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Market']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['General_10']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Entry_Points']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Dept_Points']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['General_Points']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Total_Points']; ?> </td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> <table border="0" align="center" width="270px"> <tr> <td width="30px" valign="middle"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="../images/first.png" alt="First" width="16" height="16" alt="First Page" /> </a> <?php } // Show if not first page ?></td> <td width="30px" valign="middle"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="../images/previous.png" alt="Previous Page" width="16" height="16" alt="previous" /> </a> <?php } // Show if not first page ?></td> <td width="150px" style="font-family:'Segoe UI'; font-size:12px; color:#333; font-weight:700; line-height:40px;"> Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?></td> <td width="30px" valign="middle"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"><img src="../images/Next.png" width="16" height="16" alt="Next" /> </a> <?php } // Show if not last page ?></td> <td width="30px" valign="middle"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="../images/Last.png" alt="Last Page" width="16" height="16" alt="Last" /> </a> <?php } // Show if not last page ?></td> </tr> </table> </table> </div> <div id="dash3_grid_bot"></div> </div><br /> <br /> <br /> </td> </tr> </table> <div id="dashboard"> </div> </div> <div class="dock" id="dock2"> <div class="dock-container2"> <a class="dock-item2" href="client.php"><span>Dashboard</span><img src="../Menu/images/Dashboard-.png" alt="home" /></a> <a class="dock-item2" href="brakedown.php"><span>Brakedown Report</span><img src="../Menu/images/brakedown.png" alt="contact" /></a> <a class="dock-item2" href="Compliance.php"><span>Compliance Report</span><img src="../Menu/images/compliance.png" alt="portfolio" /></a> <a class="dock-item2" href="jobstatus.php"><span>Job Status Report</span><img src="../Menu/images/jobstatus.png" alt="music" /></a> <a class="dock-item2" href="reports.php"><span>Reports</span><img src="../Menu/images/charts.png" alt="video" /></a> <a class="dock-item2" href="#"><span>Logout</span><img src="../Menu/images/off.png" alt="history" /></a> </div> </div> <!--Menu End--> </div> <!--Wrapper End--> <!--dock menu JS options --> <script type="text/javascript"> $(document).ready( function() { $('#dock2').Fisheye( { maxWidth: 60, items: 'a', itemsText: 'span', container: '.dock-container2', itemWidth: 40, proximity: 80, alignment : 'left', valign: 'bottom', halign : 'center' } ) } ); </script> </body> </html> <?php mysql_free_result($Recordset1); mysql_free_result($status); ?> Please Help me guys Hello,, I have looked for numerous examples, and have only got part of the answer. I have successfully populated a drop down list by reading the database. It populates with a list of quest titles. Once the user selects the quest. I want a textbox to populate with the Quest Description. I found an example that uses AJAX/PHP to do this, but it doesn't access a db to read/populate. The main code is in index.html The original example you select a country, and it populates a text field with the currency code. It passes a variable called $country to another file called find_ccode.php. I changed the first case in find_ccode.php to access my database, and populate the text box with quest description. Ideally I will like to make this case dynamic based off QuestID, would populate textbox with corresponding Quest Description (QDescrip). I then tried the other way in index.php I dynamically populated the dropdown list, and gave the option values the QuestIDs to be passed to $country, but something isn't working. I have a write files command to let me know what the $country variable is passing, and it never writes. It works in index.html though. I apologize in advance for my amateurish coding. I still have a lot to learn. I have included the code below, but if you know a more elegant way of doing it. I am creating a role-playing game, as you probably have figured out by now. I hope to one day put it on the web, but right now using it as a way of learning html, and PHP. I really want to know how to catch the value of the dropdown box. I would like to know what it is before sending over. also what is this.value. I assume this is what the value of the dropdown box is when you have selected something. I have been beating my head for days trying to figure this out. Any help is very much appreciated! Index.html <html> <head> <title>Changing textbox value based on dropdown list using Ajax and PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use //fuction to return the xml http object function getXMLHTTP() { var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getCurrencyCode(strURL) { var req = getXMLHTTP(); if (req) { //function to be called when state is changed req.onreadystatechange = function() { //when state is completed i.e 4 if (req.readyState == 4) { // only if http status is "OK" if (req.status == 200) { document.getElementById('cur_code').value=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body style="font: 12px Verdana, Arial, Helvetica, sans-serif;"> <form style="text-align:center" method="post" action="" name="form1"> <p style="color:#000099 ">When you change the dropdown list, the respective currency code of the country will be displayed in the textbox which is fetched from PHP using Ajax. </p> <p>Country : <select name="country" onChange="getCurrencyCode('find_ccode.php?country='+this.value)" <?php mysql_connect('localhost', '$user', '$password'); mysql_select_db('sok'); $result = mysql_query('select QuestID,QTitle, QDescrip from QuestList'); $options=""; while ($row=mysql_fetch_array($result)) { $QuestID=$row["QuestID"]; $QTitle=$row["QTitle"]; $options.="<OPTION VALUE=\"$QuestID\">".$QTitle; } ?> <option value="">Select Country</option> <option value="1">USA</option> <option value="2">UK</option> <option value="3">Nepal</option> </select><br/><br/> Currency : <input type="text" name="cur_code" id="cur_code" ></p> </form> </body> </html> Index.php <html> <head> <title>Changing textbox value based on dropdown list using Ajax and PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use //fuction to return the xml http object function getXMLHTTP() { var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getCurrencyCode(strURL) { var req = getXMLHTTP(); if (req) { //function to be called when state is changed req.onreadystatechange = function() { //when state is completed i.e 4 if (req.readyState == 4) { // only if http status is "OK" if (req.status == 200) { document.getElementById('cur_code').value=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body style="font: 12px Verdana, Arial, Helvetica, sans-serif;"> <form style="text-align:center" method="post" action="" name="form1"> <p style="color:#000099 ">When you change the dropdown list, the respective currency code of the country will be displayed in the textbox which is fetched from PHP using Ajax. </p> <p>Quest : <select name="country" getCurrencyCode('find_ccode.php?country='+this.value)">' <?php mysql_connect('localhost', '$user', '$password'); mysql_select_db('sok'); $result = mysql_query('select QuestID,QTitle, QDescrip from QuestList'); $options=""; while ($row=mysql_fetch_array($result)) { $QuestID=$row["QuestID"]; $QTitle=$row["QTitle"]; $options.="<OPTION VALUE=\"$QuestID\">".$QTitle; } $myFile = "test_catchoption.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $options); fclose($fh); ?> Choose your Quest <?=$options?> </SELECT> <br/><br/> Quest Description : <input type="text" name="cur_code" id="cur_code" ></p> </form> </body> </html> find_ccode.php <?php // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use $country=$_REQUEST['country']; $myFile = "testFilefindcc.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $country); fclose($fh); switch($country) { case "1" : mysql_connect('localhost', '$user', '$password'); mysql_select_db('sok'); $result = mysql_query("select * from QuestList where QuestID = '1'"); $row = mysql_fetch_assoc($result); echo $row['QDescrip']; break; case "2" : echo "GBP"; break; case "3" : echo "NPR"; break; } ?> Folks, I need help (Php code ) to generate a Dynamic Text on a Base Image. What i want to do is, to make this Image as header on my Site and to make this Header Specific to a Site, i want to Add the Domain Name on the Lower Left of the Image. Got the Idea? Here is the Image link: Quote http://img27.imageshack.us/i/shoppingheader1.jpg/ PHP Variable that holds the Domain name is: $domain All i need the Dynamic PHP Codes that i can put on all my sites to generate this Text on Image (Header) Dynamically... May Anyone Help me with this Please? Cheers Natasha T. Hi all I need to combine these two scripts: Firstly, the following decides which out of the following list is selected based on its value in the mySQL table: <select name="pack_choice"> <option value="Meters / Pack"<?php echo (($result['pack_choice']=="Meters / Pack") ? ' selected="selected"':'') ?>>Meters / Pack (m2)</option> <option value="m3"<?php echo (($result['pack_choice']=="m3") ? ' selected="selected"':'') ?>>Meters / Pack (m3)</option> <option value="Quantity"<?php echo (($result['pack_choice']=="Quantity") ? ' selected="selected"':'') ?>>Quantity</option> </select> Although this works OK, I need it also to show dynamic values like this: select name="category"> <?php $listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($categoryReturned=mysql_fetch_array($listCategories)) { echo "<option value=\"".$categoryReturned['name']."\">".$categoryReturned['name']."</option>"; } ?> </select> I'm not sure if this is possible? Many thanks for your help. Pete Hi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> Is there a way to take data that is listed like a,b,c,d,e and turn that into an unordered list? Basically, I'm going to have a list of schools that will be listed with comma separators. I'll print that data out in two places, one will be printed as it's in the database. The other I would like to echo as an unordered list. |