Jump to content

Search the Community

Showing results for tags 'select'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 13 results

  1. Im having trouble on my php script. it is working on my computer but when I put it in x10hosting it fails and gives an error 500. I tried tracing the problem and I found out that it happens if I call get_result. Here is the part code: $username = strtolower(filter_input(INPUT_POST, 'username')); $password = filter_input(INPUT_POST, "password"); $remember = filter_input(INPUT_POST, "remember"); $result = array(); include 'Connection.php'; $query = "SELECT Number, Username, Password, Alias, Level FROM user WHERE Username = ?;"; $stmt = $conn->prepare($query); if(!$stmt->prepare($query)) { die( "Failed to prepare statement."); } $stmt->bind_param("s", $username); $stmt->execute(); echo $stmt->error; //error hapens here $selectResult = $stmt->get_result();
  2. I'm looking to replace a select dropdown with images. My current code for the drop down is <div class="app_services_dropdown_select"> <select name="app_select_services" class="app_select_services"> <option value="1" selected="selected">Class IV MOT (Up to 3,000KG)</option> <option value="2">Class VII MOT (3,000KG - 3,500KG)</option></select> <input type="button" class="app_services_button" value="Show available times"> </div> Which is generated by this code: $s .= '<div class="app_services">'; $s .= '<div class="app_services_dropdown">'; $s .= '<div class="app_services_dropdown_title">'; $s .= $select; $s .= '</div>'; $s .= '<div class="app_services_dropdown_select">'; $s .= '<select name="app_select_services" class="app_select_services">'; if ( $services ) { foreach ( $services as $service ) { $service_description = ''; // Check if this is the first service, so it would be displayed by default if ( $service->ID == $appointments->service ) { $d = ''; $sel = ' selected="selected"'; } else { $d = ' style="display:none"'; $sel = ''; } // Add options $s .= '<option value="'.$service->ID.'"'.$sel.'>'. stripslashes( $service->name ) . '</option>'; } } $s .= '</select>'; $s .= '<input type="button" class="app_services_button" value="'.$show.'">'; $s .= '</div>'; $s .= '</div>'; And I really want an image of a car as value 1 and a van as value 2, plus I really want it to submit on click rather than having the button. Is it possible to replace the dropdown with images instead or would I need to use a radio button, then style it using an image? You can see my current dropdown in use here
  3. I have a php program that calls a function in my class to populate a select tag for display in the page. For some reason I cannot seem to discover, it retrieves the information, it correctly creates the option tags, but then when it displays the dropdown dialog box, the very top entry is missing. I sure could use another set of eyes on this to tell me what I'm missing as I know it has to be something simple. Here is the php page code that calls the function: if ($redisp==1) { $table_ex_entries .= "<table><tr>"; for ($x=0; $x<10; $x++) { //get the categories list with the selected one highlighted in the list $selected = $page->getGroupsForEntriesForm3($_SESSION['UID'],$entry_cat[$x]); //get the value for the off hours radio button if (isset($entry_offhrs[$x]) && $entry_offhrs[$x]=='y') { $set_checked_y = "checked='checked'"; $set_checked_n = ""; } else { if (isset($entry_offhrs[$x]) && $entry_offhrs[$x]=='n') { $set_checked_n = "checked='checked'"; $set_checked_y = ""; } else { $set_checked_n = "checked='checked'"; $set_checked_y = ""; } } $table_ex_entries .= "<tr>"; $table_ex_entries .= "<td><input size='12' name='date" . $x . "' type='text' value='" . $entry_date[$x] . "' id='datetimepicker" . $x . "'></td>"; $table_ex_entries .= "<td><input size='12' name='id" . $x . "' type='text' value='" . $entry_id[$x] . "'></td>"; $table_ex_entries .= "<td><input size='18' name='name" . $x . "' type='text' value='" . $entry_name[$x] . "'></td>"; $table_ex_entries .= "<td><select width='250' name='cat" . $x . "' value='" . $selected . "</select></td>"; $table_ex_entries .= "<td><input size='43' name='desc" . $x . "' type='text' value='" . $entry_desc[$x] . "'></td>"; $table_ex_entries .= "<td><input size='6' name='hrs" . $x . "' type='text' value='" . $entry_hrs[$x] . "'></td>"; $table_ex_entries .= "<td>Yes<input name='offhrs" . $x . "' type='radio' value='y' " . $set_checked_y . "> No <input name='offhrs" . $x . "' type='radio' value='n' " . $set_checked_n . "></td>"; $table_ex_entries .= "</tr>"; } $table_ex_entries .= "</table>"; } Here is the div in the html body (it displays fine as I have some javascript that determines which div to display based on the $redisp==1 show in the above code snippet) <div id="re_entry" style="display:none"> <p align="center"> *<b>Date/Category/Description/Hours are REQUIRED fields</b> <br>Please correct your entries and click Add Entries again to proceed. <br> </p> <?php echo $table_header; ?> <?php echo $table_ex_entries; ?> </div> And here is the function that it calls to create the option tags for the select tag in the first set of code building the html table. Oh and I do have categories preferences so it is retrieving just my list not the whole list in this function. public function getGroupsForEntriesForm3($uid,$category) { $out = ''; $cats = array(); $cat_id = array(); $catname = array(); $dbh = $this->rdb; //check to see if the user has set preferences for their list of categories $dbh->query("SELECT Categories FROM Users WHERE ID = :id"); $dbh->bind(':id', $uid); $row = $dbh->single(); $user_cats = (isset($row['Categories']) ? $row['Categories'] : ''); if ($user_cats == '') { //no special preference for categories so go get them all after getting the user's group ID $dbh->query("SELECT GID FROM Users WHERE ID = :id"); $dbh->bind(':id', $uid); $row = $dbh->single(); $gid = $row['GID']; $cats = $this->getCategories($gid); } else { //user has preference for categories so only go get the ones they have in their preference list to create the select options $dbh->query("SELECT ID, Name FROM Categories WHERE ID IN ($user_cats) ORDER BY Name"); $rows = $dbh->resultset(); $xx=0; foreach ($rows as $row) { $catname[$xx] = $row['Name']; $cat_id[$xx] = $row['ID']; $xx++; } } $dbh = NULL; $select_opt = ""; for ($xx=0; $xx<count($rows); $xx++) { //echo "category ID inside the function is set to " . $category . "<br>"; //echo "catname while while creating the select options set to " . $catname[$xx] . "<br>"; if ($category == $cat_id[$xx]) { //echo "match category is " . $category . " and cat_id[xx] is " . $cat_id[$xx] . " and catname[xx] is set to " . $catname[$xx] . " and xx is set to " . $xx . "<br>"; $select_opt .= "<option selected value='" . $cat_id[$xx] . "'>" . $catname[$xx] . "</option>"; } else { //echo "category is " . $category . " and cat_id[xx] is " . $cat_id[$xx] . " and catname[xx] is set to " . $catname[$xx] . " and xx is set to " . $xx . "<br>"; $select_opt .= "<option value='" . $cat_id[$xx] . "'>" . $catname[$xx] . "</option>"; } } return $select_opt; } Thanks in advance! Ches
  4. Hello. I'm a newbie so sorry if this isn't the best forum to post my problem. I am using a MySQL and PHP to create a web app. I have authentication, and I can register users. I also have a form that users provide information and it is successfully inserting data into a table in my database. I will use fictional fields for my database table called meal_info: username dateStartedDiet numberMealsPerDay costPerMeal Problem: Select user-specific data from the MySQL database, using Session username to select only the current user's data, then display it and do some calculations. Here is thecode at the top, and I am fairly sure it's working: session_start(); //execute commone code require("common.php"); //includes code to connect to database, etc. if(empty($_SESSION['user'])) { // If they are not, we redirect them to the login page. header("Location: login.php"); // Remember that this die statement is absolutely critical. Without it, // people can view your members-only content without logging in. die("Redirecting to login.php"); } Here is the part of the code that has to do with displaying user data: $userID = $_SESSION['user']['username']; //create a variable that is the session username which is identical to the field in our MySQL table $query = "SELECT * FROM meal_info WHERE username = $userID"; //our SELECT statement $result = db->query($query); //execute the query $row_count = $result->num_rows;//count the rows in the table and place in variable to use in incremental loop code for ($i = 0; $i < $row_count; $i++) : $row = $result->fetch_assoc(); //for each row in the table, fetch and create and array $dateStart = $row['dateStartedDiet']; $numberMeals = $row['numberMealsPerDay']; $costMeal = $row['costPerMeal']; echo $dateStart; echo $numberMeals; echo $costMeal;
  5. SELECT user_id FROM users WHERE active = :active ORDER BY RAND() LIMIT 1 The above query works. But what if the users table is filled with thousands of users? Will this query break or be very slow? If so, what's the alternative solution to this?
  6. I have a timeclock application where you can add entries into a table. One of the columns is a <select> dropdown tag. If you do not enter one of the required fields, I redisplay the values entered so the user can correct the entries and resubmit to save them. Everything saves (posts) except the <select> dropdown value. The dropdown does show properly, even with the properly selected value. But if you change the value, it doesn't update. It retains the original value. Here is the function from STOP_Timeclock.php class that does the form: public function add_entries_page($msg) { $redisp = $_SESSION['redisp']; $out = ''; $offhrs = "N"; $dbh = new Database; //display the last entry the user saved to the database $dbh->query("SELECT * FROM Entries WHERE UID = :uid and GID = :gid order by Date DESC Limit 1"); $dbh->bind(':uid', $_SESSION['UID']); $dbh->bind(':gid', $_SESSION['GID']); $rows = $dbh->resultset(); foreach ($rows as $value) { $msg .= "Your last entry was: " . date('m-d-Y',strtotime($value['Date'])) . " for: " . $value['Description'] . " - " . number_format($value['Hours'],2,'.','') . " hour(s) were recorded. <br>"; } $select = $this->getGroupsForEntriesForm($_SESSION['UID']); //$select2 = $this->getGroupsForEntriesForm3($_SESSION['UID'],$_SESSION['array_category']); $caption = 'If you leave the Date Box empty, it defaults to today. *<b>Date/Category/Description/Hours are REQUIRED fields</b> <br><br>'; $head = array(array('name' => 'head', '1' => 'Date *', '2' => 'Ticket ID', '3' => 'Ticket Name', '4' => 'Category *', '5' => 'Description of Work Done *', '6' => 'Hours *', '7' => 'Off Hours(Y/N)' )); if($redisp == 0) { $body = array(); unset($_SESSION['array_id']); unset($_SESSION['array_name']); unset($_SESSION['array_category']); unset($_SESSION['array_desc']); unset($_SESSION['array_hours']); unset($_SESSION['array_offhrs']); for ($i = 1; $i < 11; $i++) { $row = array($this->xhtml->input(array('type' => 'text', 'id' => "datepicker$i", 'class' => 'entries_field_1', 'name' => 'DATE[]' )), $this->xhtml->input(array('type' => 'text', 'name' => 'ID[]', 'class' => 'entries_field_2' )), $this->xhtml->input(array('type' => 'text', 'name' => 'NAME[]', 'class' => 'entries_field_3' )), $select, $this->xhtml->input(array('type' => 'text', 'name' => 'DESC[]', 'class' => 'entries_field_5' )), $this->xhtml->input(array('type' => 'text', 'name' => 'HOURS[]', 'class' => 'entries_field_6' )), $this->xhtml->input(array('type' => 'text', 'name' => 'OFFHOURS[]', 'value' => $offhrs, 'class' => 'entries_field_7' )) ); $body[$i] = $row; } } if($redisp == 1) { $body = array(); $name = $_SESSION['array_name']; $id = $_SESSION['array_id']; $category = $_SESSION['array_category']; $desc = $_SESSION['array_desc']; $hours = $_SESSION['array_hours']; $offhrs = $_SESSION['array_offhrs']; $dates = $_SESSION['array_dates']; $max_count = $_SESSION['max_count']; for ($i = 0; $i < $max_count; $i++) { $selected = $this->getCatName($_SESSION['UID'], $category[$i]); $row = array($this->xhtml->input(array('type' => 'text', 'id' => "datepicker$i", 'class' => 'entries_field_1', 'value' => $dates[$i], 'name' => 'DATE[]' )), $this->xhtml->input(array('type' => 'text', 'name' => 'ID[]', 'value' => "$id[$i]", 'class' => 'entries_field_2' )), $this->xhtml->input(array('type' => 'text', 'name' => 'NAME[]', 'value' => "$name[$i]", 'class' => 'entries_field_3' )), "$selected", $this->xhtml->input(array('type' => 'text', 'name' => 'DESC[]', 'value' => "$desc[$i]", 'class' => 'entries_field_5' )), $this->xhtml->input(array('type' => 'text', 'name' => 'HOURS[]', 'value' => "$hours[$i]", 'class' => 'entries_field_6' )), $this->xhtml->input(array('type' => 'text', 'name' => 'OFFHOURS[]', 'value' => "$offhrs[$i]", 'class' => 'entries_field_7' )), ); $body[$i] = $row; if(isset($_POST['CAT'])) { $_SESSION['cats'][$i] = $_POST['CAT']; } else { $_SESSION['cats'][$i] = $category[$i]; } } } $data = array_replace($head, $body); $table = $this->xhtml->table2($data, $caption, array('class' => 'add_time')); $table .= $this->xhtml->input(array('type' => 'submit', 'value' => 'Add Entries' )); $form = $this->xhtml->form(array(array($table), ), array('action' => BASE . '/addEntries.php', 'class' => 'add_time', 'onsubmit' => 'return valid_Add(this)', 'method' => 'post' ) ); $out = $form; $menu = $this->getMenu(); $msg = $this->xhtml->div("$msg", array('id' => 'error')); $out = $this->xhtml->div("$out", array('id' => 'add_entries_form')); $out = $this->xhtml->div("$msg$out", array('id' => 'main')); $out = $this->xhtml->div("$menu$out", array('id' => 'container')); $out = $this->xhtml->body("$out", array('onload' => 'startUp();')); return $out; } And here is the addEntries page that evaluates for all fields and then saves to the database if correct. <?php session_start(); include('includes/config.php'); $msg =''; $x=0; $ok_to_post = 0; $page = new STOP_Timeclock; $xhtml = new XHTML; $dbh = new Database; if (isset($_POST['NAME'])) { $name = array_filter($_POST['NAME']); $_SESSION['array_name'] = $name; } if (isset($_POST['ID'])) { $id = array_filter($_POST['ID']); $_SESSION['array_id'] = $id; } if($_SESSION['redisp'] == 0) { if (isset($_POST['CAT'])) { $category = array_filter($_POST['CAT']); $_SESSION['array_category'] = $category; } } else { $category = $_SESSION['cats']; } if (isset($_POST['DESC'])) { $desc = array_filter($_POST['DESC']); $_SESSION['array_desc'] = $desc; } if (isset($_POST['HOURS'])) { $hours = array_filter($_POST['HOURS']); $_SESSION['array_hours'] = $hours; } if (isset($_POST['OFFHOURS'])) { $offhrs = array_filter($_POST['OFFHOURS']); $_SESSION['array_offhrs'] = $offhrs; } if (isset($_POST['DATE'])) { $dates = array_filter($_POST['DATE']); $_SESSION['array_dates'] = $dates; } $count_category = count($category); //$msg .= "count of category field is " . $count_category . "<br>"; $count_desc = count($desc); //$msg .= "count of desc field is " . $count_desc . "<br>"; $count_hours = count($hours); //$msg .= "count of hours field is " . $count_hours . "<br>"; $count_dates = count($dates); //$msg .= "count of date field is " . $count_dates . "<br>"; if ($count_desc == $count_hours) { if ($count_hours == $count_dates) { $ok_to_post = 1; $max_count = $count_desc; } else { if ($count_hours > $count_dates) { $max_count = $count_desc; } else { $max_count = $count_hours; } $ok_to_post = 0; $msg .= 'You did not enter one of the required fields - Date/Category/Description/Hours are REQUIRED. <br />'; } } else { if ($count_desc > $count_hours) { $max_count = $count_desc; } else { $max_count = $count_hours; } $ok_to_post = 0; $msg .= 'You did not enter one of the required fields - Date/Category/Description/Hours are REQUIRED. <br />'; } //$msg .= "max count is set to " . $max_count . "<br>"; $_SESSION['max_count'] = $max_count; //everything is entered correctly - now process and insert into the database $rowCount = 0; $today = date("Y-m-d"); $count = 0; if ($ok_to_post == 1) { $redisp = 0; $_SESSION['redisp'] = $redisp; $dbh->beginTransaction(); $myquery = "INSERT INTO Entries (`UID`, `GID`, `Date`, `CID`, `TicketNumber`, `TicketName`, `Description`, `Hours`, `OffHours`,`Created_Date`) VALUES (:uid, :gid, :date, :cid, :num, :name, :desc, :hrs, :offhrs, now())"; $dbh->query($myquery); for ($x = 0; $x < $max_count; $x++) { $dbh->bind(':uid', $_SESSION['UID']); $dbh->bind(':gid', $_SESSION['GID']); $dbh->bind(':date', $dates[$x]); $msg .= "category[x] is set to " . $category[$x] . "<br>"; $dbh->bind(':cid', $category[$x]); if (count($id)==0) { $dbh->bind(':num', NULL); } else { $dbh->bind(':num', $id[$x]); } if (count($name)==0) { $dbh->bind(':name', NULL); } else { $dbh->bind(':name', $name[$x]); } $dbh->bind(':desc', $desc[$x]); $msg .= "desc[x] is set to " . $desc[$x] . "<br>"; $dbh->bind(':hrs', $hours[$x]); $msg .= "hour[x] is set to " . $hours[$x] . "<br>"; $dbh->bind(':offhrs', $offhrs[$x]); $result = $dbh->execute(); if (!$result) { $msg .= "Saving entry to the database failed. Please see system administrator. <br />"; continue; } $count += $dbh->rowCount(); } if ($count != $max_count) { $dbh->cancelTransaction(); $msg .= 'An error occurred and all entries could not be added. <br /> For safety, this was rolled back and no entries were added. <br /> Please see system administrator. <br />'; } else { $dbh->endTransaction(); $dbh->query("SELECT * FROM Entries WHERE UID = :uid and GID = :gid and Created_Date >= :date2"); $dbh->bind(':uid', $_SESSION['UID']); $dbh->bind(':gid', $_SESSION['GID']); $dbh->bind(':date2', $today); $rows = $dbh->resultset(); $msg .= "Returned " . count($rows) . " entries successfully written to and retrieved from the database for you today. <br>"; $tothrs = 0; foreach ($rows as $value) { $msg .= "On " . date('m-d-Y',strtotime($value['Date'])) . " for " . $value['Description'] . " - " . number_format($value['Hours'],2,'.','') . " hour(s) were recorded. <br>"; $tothrs = $tothrs + $value['Hours']; } $msg .= "Total hours entered today = " . $tothrs . "<br>"; $msg .= "<br><br>"; } $dbh = NULL; $_SESSION['MSG'] = $msg; header('Location: ' . BASE); } else { $redisp = 1; $_SESSION['redisp'] = $redisp; $_SESSION['MSG'] = $msg; header('Location: ' . BASE); } ?> I am hoping that you all might be able to assist. Thanks in advance.
  7. I have a table called "playlists", and a table called "musics". In the musics table, there is a column playlist_id which references the playlist that each music is contained. I'm using api calls to display information on the site with JavaScript, so I need to return a JSON. I need the json with the following structure: [ Playlists: [ { Name: "etc", musics: [ { name: "teste.mp3" }, { name: "test2.mp3" } ] }, ... ] ] And this is my code: $query = $con->prepare("SELECT * FROM playlists WHERE user_id = :id"); $query->execute(array("id" => $userID)); $playlists = $query->fetchAll(PDO::FETCH_ASSOC); foreach ($playlists as &$key) { $query = $con->prepare("SELECT * FROM musics WHERE playlist_id = :id"); $query->execute(array("id" => $key['ID'])); $songs = $query->fetchAll(PDO::FETCH_ASSOC); $key['musics'] = $songs; } There's a way to avoid this loop?
  8. Hello, I don't know if this is possible. I want to make a switch between pages, lets say i have more than 100 pages and each page have a unique name.php. So what i want to do is when page equal to random-page.php SELECT * FROM `jobs` WHERE title LIKE '%news%' And for example how it should be, but i don't know what is exactly wrong here and how to fix it. $sql_q; $path=$_SERVER['PHP_SELF']; $page=basename($path); switch("$page") { case 'index.php': $sql_q = 'SELECT * FROM `jobs` WHERE `title` LIKE '%news%' LIMIT $p_num, $per_page'; break; case 'jobs.php': $sql_q = 'SELECT * FROM `jobs` WHERE `title` LIKE '%jobs%' LIMIT $p_num, $per_page'; break; case 'region.php': $sql_q = 'SELECT * FROM `jobs` WHERE `title` LIKE '%region%' LIMIT $p_num, $per_page'; break; } And here: $getquery = mysql_query("$sql_q"); Is that possible somehow ? Thanks.
  9. Hi, Thanks for taking the time. I'm trying PDO for the first time and I'm trying to make a CRUD codebase. I can insert but I have trouble with the select statement and iterate through the data, Apache gives me this error: Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in index.php:38 This is line 38: $getName = $result; while( $row = $getName->fetch_assoc() ){ echo $row['name']; } This is my code: $pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $pdo->prepare("SELECT name FROM users"); $stmt->execute(); // set the resulting array to associative $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); $getName = $result; //Iterate through the data // line 38: while( $row = $getName->fetch_assoc() ){ echo $row['name']; }
  10. Hi All, The Problem: I'm trying to learn how to take records from the NAME row of one table (i.e. Tom, Jim, Chris, Mike) and put them into a SELECT (drop down menu) box, then select a name and save it to a DIFFERENT table where the row is also called NAME, and THEN have that selection I just saved show in the SELECT box as SELECTED when the page refreshes. I have found a hundred websites showing how to bind a SELECT box to a table and put them into a SELECT box via $key => $val and even how to save it to ANOTHER textbox on the page, which is a lot easier, but never a step further as described in the first paragraph above. Seems unbelievable to me since it's so common. Maybe I'm just not using the proper search terms/keywords. Here's an example: Let's say you wanted to notify 3 people of your birthday. So, on the notification page, you would enter three names of people you would want notified all in separate input textboxes with [keys]. So, you enter John, Chris, and Tom into three text boxes and save the page. Done. Now, on another page, I have -- say .... five select boxes. For arguments sake, let's just say I click on all of them one at a time. In each of them, I would only see three names (John, Chris, and Tom). Now, in the first SELECT box I click on John. In the second select box I click on Chris, and on the third I click on Tom. Then save the form. I would like to see John, Chris, and Tom in the first three boxes after refreshing and I would like to see SELECT A NAME on the last two Select boxes that we never did anything with. Remember, there are NO default names in the first table with row called NAMES. They are populated by the user and saved to the row. I'm attaching an image of what the page looks like that I want to see the names and be able to select them. Does anyone have a link to a site that shows how to do this... or maybe have something very basic that would show me the process? Or, if not too difficult, maybe you could show me? Thanks in advance for any help!
  11. Hello there friends I have an select box and I would like to define the alue of the selects with array. Like this: var price_list= new Array(); price_list["-"]=0; price_list["bronze"]=5; price_list["silver"]=10; price_list["gold"]=15; The I have a Selectbox where <form action="" id="metal" onsubmit="return false;" <select id="a" name="metals" class="form-select"> <option value="-">-</option> <option value="bronze">bronze</option> <option value="silver">silver</option> <option value="gold">gold</option> </select> And performig calculations with following script (that works fine if the value is directly in select). And obviously there is another select (#b) but that is just numbers so I didn show it here. $(document).ready(function() { function compute() { var a = $('#metals').val(); var b = $('#b').val(); var total = a * b * 1.22; $('#result').text(total); } $('#metals, #b').change(compute); }); I just get returned NaN If you have an answer then please hit
  12. Hi. I have 2 problems which I'm hopeing someone can help me with. 1. For the following script to change the pages language, I would like it so that whichever option selected is set on the page (i.e. if you select Euskal, the select box stays set as Euskal, and not Espanyol as it does at the moment) <form name="Language" action="" method="post" id="Language"> <div class="btn-group"> <?php $uri = strtok($_SERVER["REQUEST_URI"],'?');; $url="http://".$_SERVER['HTTP_HOST'].$uri; ?> <span class="btn btn-primary"> <select name="lang" onchange="javascript:change_langs(this.form)"> <option value="Esp">Espanyol</option> <option value="Eng">English</option> <option value="Cat">Catalan</option> <option value="Bas">Euskal</option> <option value="Gal">Galego</option> </select> </span> </div></form> 2. I have 2 dropdown lists in the following format: <select class="form-control" name='category'> <option <?php print ((isset($_GET["category"]) && ($_GET["category"]=="A"))?"selected='A'":""); ?> value='A'><?=getlg($lang,"A")?></option> <option <?php print ((isset($_GET["category"]) && ($_GET["category"]=="b"))?"selected='b'":""); ?> value='b'><?=getlg($lang,"b")?></option> <option <?php print ((isset($_GET["category"]) && ($_GET["category"]=="c"))?"selected='c'":""); ?> value='c'><?=getlg($lang,"c")?></option> </select> <select class="form-control" name='category'> <option <?php print ((isset($_GET["category"]) && ($_GET["category"]=="D"))?"selected='D'":""); ?> value='D'><?=getlg($lang,"D")?></option> <option <?php print ((isset($_GET["category"]) && ($_GET["category"]=="e"))?"selected='e'":""); ?> value='e'><?=getlg($lang,"e")?></option> <option <?php print ((isset($_GET["category"]) && ($_GET["category"]=="f"))?"selected='f'":""); ?> value='f'><?=getlg($lang,"f")?></option> </select> However, I require just one dropdown list with catagories A and D as the main item. Catagories b & c should be a sub category of A, and e & f should be a sub category of D Any help would be appreciated. Thanks
  13. I am trying to create a simple forum in a MVC architecture. This is my database setup (the relevant part): Table: forum_categories `forum_categories` ( `cat_id` INT( NOT NULL AUTO_INCREMENT, `cat_title` VARCHAR(255) NOT NULL, `cat_desc` TEXT NOT NULL, PRIMARY KEY (`cat_id`), UNIQUE KEY (`cat_title`) Table: forum_topics `forum_topics` ( `topic_id` INT( NOT NULL AUTO_INCREMENT, `cat_id` INT( NOT NULL COMMENT 'foreign key with forum_categories table', `user_id` INT(11) NOT NULL COMMENT 'foreign key with users table', `topic_title` VARCHAR(255) NOT NULL, `topic_desc` TEXT NOT NULL, `topic_date` DATETIME DEFAULT NULL, PRIMARY KEY (`topic_id`), FOREIGN KEY (`cat_id`) REFERENCES forum_categories (`cat_id`) ON DELETE CASCADE ON UPDATE CASCADE Example of the functionality, I would like to achieve: Category 1 has cat_id = 1 Category 2 has cat_id = 2 Topic 1 has cat_id = 1 Topic 2 has cat_id = 2 Now when category 1 is selected I just want topic 1 to show. If category2 is selected I just want topic 2 to show. This prepared SQL statement achieves that: PREPARE stmnt FROM 'SELECT * FROM forum_categories fc JOIN forum_topics ft ON fc.cat_id = ft.cat_id WHERE fc.cat_id = ? ORDER BY ft.topic_date DESC'; SET @a = 1; EXECUTE stmnt USING @a; My Problem: I would like to move this functionality into my PHP MVC structure. Here is my attempt, which does not work (it shows all topics in all categories). Controller /** * Show all the topics in the chosen category */ public function showForumTopics() { $topic_model = $this->loadModel('Forum'); $this->view->forum_topics = $topic_model->getForumTopics(); $this->view->render('forum/viewTopics'); } Model /** * Gets an array that contains all the forum topics in the database. * Each array element is an object, containing a specific topic's data. * @return array All the forum topics */ public function getForumTopics($cat_id) { $sql = 'SELECT * FROM forum_categories fc JOIN forum_topics ft ON fc.cat_id = ft.cat_id WHERE fc.cat_id = :cat_id ORDER BY ft.topic_date DESC'; $query = $this->db->prepare($sql); $query->execute(array(':cat_id' => $cat_id)); return $query->fetchAll(); } View if ($this->forum_topics) { foreach($this->forum_topics as $key => $value) { echo '<p><strong>Title:</strong>' . $value->topic_title . '</p>'; echo '<p><strong>Description:</strong> ' . $value->topic_desc . '</p>'; echo '<p><strong>Author:</strong> ' . $value->topic_author . '</p>'; echo '<p><strong>Date:</strong> ' . $value->topic_date . '</p>'; } } else { echo 'No forum topics.'; } Help would be highly appreciated! Thank you!!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.