PHP - How To Display Data According To Dynamic List Box
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.
Similar TutorialsHi, 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! im making a game and i need to show a users money but i dont know how help? I am brand new to PHP but, after using W3 Schools, can retrieve a record from a MySQL database using php & SQLi.
I have a page with a list of between 20 and 30 items down one side and a panel on the other. When a user clicks a list item I want to display the details of the clicked item in the panel. The details a Program (text), Convenor (text), Dates (text), Times (Text), Location (text), Notes (Text large).
The details are stored in a MySQL Database 'Documents', in a table 'Programs' and I would like to put the details into text boxes in the panel.
Could you point me to some info on doing this please?
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 I'm pulling data from an xml file and I'm getting a lot of duplicates. How can I remove the duplicates from the query? Code: [Select] foreach($xml->category->subcategory as $category){ echo $category[id]; }//end foreach 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 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; } ?> 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, 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; } ?> Hi... have looked far and wide without success. Can someone point me in the right direction to learn how to dynamically display a price as the client adds/subtracts items from a shopping cart without refreshing the page ? Thanks Hello, I had page that display results dynamically from the database, I need to export that html table to pdf. Any help? Thanks Hello. If someone can help me, i'll be grateful So i have a foreach and an $output .= function that fills some infos in a table. Inside it i have a div for each line that when hovering your mouse should get some data .. Here i have a big problem, because for each line it should get some data and i don't know how to do it ... i'll post here some of my code for better understanding. Quote //some java here <?php require "class.php"; $server_list = query_group(); $misc = server_misc($server); foreach ($server_list as $server) { $misc = server_misc($server); $server = server_html($server); $idi = "{$server['o']['id']}"; $harta = "<a onmouseover=\"ShowContent('harta'); return true;\" onmouseout=\"HideContent('harta'); return true;\" href='".link($server['o']['id'])."' target=\"_self\">{$server['s']['map']}</a> <div style=\"position:absolute;\" id=\"harta\" class=\"FAQ\">file_get_contents('http://mysite/player.php?d={$idi}')</div> "; $output .= " <table> ........... some code..... <td> {$harta} </td> ....... so basicly when i hover my mouse over each row it should get data from the file for that id... The problem is that only one page can be loaded with file_get_contents. I read over the internet that some ajax functions can do it but i really don't know how. Please help me, i've been looking for 3 days already without any luck Hey guys, I got another one that i could use some help on. I have a input form that utilizes a javascript that adds additional rows to my table. here is a look at what i got. Code: [Select] <script type="text/javascript"> function insertRow() { var x = document.getElementById('results_table').insertRow(-1); var a = x.insertCell(0); var b = x.insertCell(1); var c = x.insertCell(2); var d = x.insertCell(3); var e = x.insertCell(4); a.innerHTML="<input type=\"text\" name=\"id\">"; b.innerHTML="<input type=\"text\" name=\"place\">"; c.innerHTML="<input type=\"text\" name=\"username\">"; d.innerHTML="<input type=\"text\" name=\"earnings\">"; e.innerHTML="<input type=\"button\" value=\"delete\" onClick=\"deleteRow(this)\">"; } function deleteRow(r) { var i=r.parentNode.parentNode.rowIndex; document.getElementById('results_table').deleteRow(i); } </script> this is my code stored in the header of my page. basically just a button to add a new row and a button in each row to delete rows if needed. here is a look at my html table, pretty basic... Code: [Select] <table id="results_table"> <th>Event ID</th><th>Place</th><th>Username</th><th>Earnings</th> <tr> <td><input type="text" name="id"></td><td><input type="text" name="place"></td><td><input type="text" name="username"></td><td><input type="text" name="earnings"></td><td><input type="button" value="delete" onClick="deleteRow(this)"</td> </tr> </table> Now what I am hoping to acheive is once i submit all of these rows to the database i will insert each of these rows into their own row in the database. is this doable? the structure of my database is: ResultID (Primary Key) Place Earnings UserID (Foreign Key) EventID (Foreign Key) now i think the biggest problem i'm having with submitting data to the database is that in the original HTML form I am typing in the actual username and not the userID. so when it comes to processing I need to do a switch of these two things before I run my query. Should something like this work? Code: [Select] $username = $_POST['username']; $userID = "SELECT userID FROM users WHERE username="$username"; $query = mysql_query($userID); also i've never tried to submit multiple entries at a time. maybe i have to create an array somehow in order to capture each rows data. any thoughts? as always thanks for the help. Hi, I have a dynamic form which uses javascript to add rows on the fly. The name of the element on my test page is txtRow1, txtRow2, etc; the number is added when I add a new row. I am trying to figure out how I will extract the data once the form had been POSTED. I have tried Code: [Select] $tags = $_POST['txtRow']; foreach ($tags as $t) { echo "$t<br />"; } but that shows nothing. I would be grateful for any assistance. Thanks Hi - I'm trying to speed up part of my business. I sell photos taken on site...I dump said photos in a directory and my little app pulls all images from a given directory and displays them on a page. I can get the filename etc displayed on screen, added to the image attributes, whatever. I'd like to have a checkbox next to each image, and the user checks a few and it'll send an email to me so I can fill their order. Looks like this: http://www.limitedwave.com/reflex/ I can use a sendmail like I've tried, but it can take like 10 minutes to actually send from the server which is lame. I'd be cool with just dropping the data in my database, then retrieving selections by user's name, but I don't know how to set up a form/insert page that will insert from a somewhat random set of checkboxes. Thoughts? Thanks. i've to populate google charts with dynamic data. the data looks llike. +----+-------+---------+-------+-----------+---------+------+ | id | name | physics | maths | chemistry | biology | sst | +----+-------+---------+-------+-----------+---------+------+ | 1 | Name1 | 10 | 25 | 35 | 42 | 62 | | 2 | Name2 | 80 | 45 | 45 | 45 | 25 | | 3 | Name3 | 63 | 25 | 63 | 36 | 36 | | 4 | Name4 | 82 | 36 | 75 | 48 | 42 | | 5 | Name5 | 45 | 45 | 78 | 25 | 24 | | 6 | Name6 | 36 | 36 | 15 | 75 | 36 | | 7 | Name7 | 99 | 45 | 24 | 24 | 45 | | 8 | Name8 | 45 | 85 | 85 | 85 | 96 | +----+-------+---------+-------+-----------+---------+------+ i have to create google charts based on this such that # namewise - such that when i select a name it displays all subject marks of that particular name in a column chart #markswise - when i select a subject, it displays all the names with marks in that particular subject. conisdiering that data may be added and i've to accumulate that also, for namewise i did // chart.php <?php include("connection.php"); $query = "SELECT name FROM csv GROUP BY name DESC"; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); ?> <!DOCTYPE html> <html> <head> <title>Google charts</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> </head> <body> <br /><br /> <div class="container"> <div class="panel panel-default"> <div class="panel-heading"> <div class="row"> <div class="col-md-9"> <h3 class="panel-title">Student Wise Marks Data</h3> </div> <div class="col-md-3"> <select name="name" class="form-control" id="name"> <option value="">Select Student</option> <?php foreach($result as $row) { echo '<option value="'.$row["name"].'">'.$row["name"].'</option>'; } ?> </select> </div> </div> </div> <div class="panel-body"> <div id="chart_area" style="width: 1000px; height: 620px;"></div> </div> </div> </div> </body> </html> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {packages: ['corechart', 'bar']}); google.charts.setOnLoadCallback(); function load_student_data(name, title) { var temp_title = title + ' '+name+''; $.ajax({ url:"fetch.php", method:"POST", data:{name:name}, dataType:"JSON", success:function(data) { drawStudentwiseChart(data, temp_title); } }); } function drawStudentwiseChart(chart_data, chart_main_title) { var jsonData = chart_data; var data = new google.visualization.DataTable(); data.addColumn('number', 'Physics'); data.addColumn('number', 'Maths'); data.addColumn('number', 'Chemistry'); data.addColumn('number', 'Biology'); data.addColumn('number', 'SST'); $.each(jsonData, function(i, jsonData){ var Physics = jsonData.Physics; var Maths = jsonData.Maths; var Chemistry = jsonData.Chemistry; var Biology = jsonData.Biology; var SST = jsonData.SST; data.addRows([[Physics,Maths,Chemistry,Biology,SST]]); }); var options = { title:chart_main_title, hAxis: { title: "Subjects" }, vAxis: { title: 'Percentage' } }; var chart = new google.visualization.ColumnChart(document.getElementById('chart_area')); chart.draw(data, options); } </script> <script> $(document).ready(function(){ $('#name').change(function(){ var name = $(this).val(); if(name != '') { load_student_data(name, 'Student wise marks data'); } }); }); </script> and in order to fetch data // fetch.php <?php //fetch.php include('connection.php'); if(isset($_POST["name"])) { $query = " SELECT * FROM csv WHERE name = '".$_POST["name"]."' ORDER BY id ASC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { $output[] = array( 'Physics' => $row["Physics"], 'Maths' => $row["Maths"], 'Chemistry' => $row["Chemistry"], 'Biology' => $row["Biology"], 'SST' => $row["SST"], ); } echo json_encode($output); } ?> it diplays a blank page. however when i play with singular values i.e one subject at a time it displays fine Edited March 19, 2019 by zetastreakOk so I have a form to submits to a .php file that creates an image. This works fine, but I also want the info from the form to be sent to MySQL database. The problem is that something in a script I "required" called core.inc.php is interfering and so no image is output. Here is core.inc.php: Code: [Select] <?php ob_start(); session_start(); $current_file = $_SERVER['SCRIPT_NAME']; if(isset($_SERVER['HTTP_REFERER'])&&!empty($_SERVER['HTTP_REFERER'])) { $http_referer = $_SERVER['HTTP_REFERER']; } function loggedin() { if(isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])) { return true; } else { return false; } } function getuserfield($field) { $query="SELECT `$field` FROM `Users` WHERE `id`='".$_SESSION['user_id']."'"; if($query_run=mysql_query($query)) { if($query_result = mysql_result($query_run, 0, $field)) { return $query_result; } } } ?> Here is the code for the image creating .php file: Code: [Select] <?php require 'connect.inc.php'; require 'core.inc.php'; $title = $_REQUEST['title'] ; $user_id = getuserfield('id'); $query = "INSERT INTO `---` VALUES ('".mysql_real_escape_string($title)."','".mysql_real_escape_string($user_id)."')"; $query_run = mysql_query($query); //There is some more code in here obviously, but it's irrelevant header('Content-type: image/png'); imagepng($image_f); imagedestroy($image_f) Can anybody give me some idea of what is conflicting or what I can do to fix it? |