Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Populating A Select Box From A Database


I have a subscription database that allows you to edit a subscribers data. For example, you enter a search term like "Bob" and it returns a list of everyone named Bob. You click the one you want and it goes to a subscriber detail page, where all of his data is populated to a form. You can directly edit this form and click save to overwrite it.

The only issue is the select boxes (drop downs) - say I have four options in the drop down box, red, blue, green and black. On my details page for bob I end up with five, I have those four PLUS whatever was saved for his color, so it shows up twice. If Bob is green, my select box looks like:

Green
Red
Blue
Green
Black

How can I make it so that Green only shows up once?




View Complete Forum Thread with Replies

Related Forum Messages:
Populating A Select Box
What I want to do for members of my website is to allow them to click a button that will add their name to a list that populates a select box.  I can do this on my own, but I was curious if I have to use a database in order for this to be possible. 

View Replies !
Populating Select Boxes
I'm creating a data entry system using php/mysql that includes the standard add/update/delete forms in PHP with a MySQL backend.

On the update pages I'm trying to fill the select boxes (that come from other tables) with the values in those other tables, yet defaulting the selection in each of those select boxes to the value currently stored in the main table which is being updated.

For example, the main table is called 'dates' and a related table is called 'department'. So one of the select boxes should have all the various departments listed in the select box but the currently selected value should be whatever is in the department field in the 'dates' table for the record the user is trying to update. Code:

View Replies !
Reading Directories, Populating Select Box
Can anybody tell me how to read through a directory, get the file names and populate a select box(pulldown menu) with these names? I know how to loop through a directory using something like this:

while ($files = readdir($handle)) {

$ext=substr($file,-4);

if ($files != "." && $files != ".." && $ext == ".php") {

do some wild and crazy stuff here;

}

}

It's the populating the select box (pulldown menu) while doing this that I need the help on.

View Replies !
Populating SELECT Multiple Form Field And Inserting Into Db
I have an update form where I'm trying to populate a SELECT multiple field with a list of 48 categories, from tbl work_cat. And show, as SELECTED, the one or many choices that the user had previously selected from the 48 categories which are stored in tbl cat_relations as $relation_cat.

Then allow the user to update their selections and update the database. But I can't get my form to work. First problem, I can't get the SELECT field on the form to show the categories, and then I don't know where to go from there. Below are my form page and my processing page. Code:

View Replies !
Drop Down Menu Select And Populating Data Fields
I have a PHP/MySQL Content Management System set up for the job I work at. It's basically a shift program that lets users pick up shifts, post shifts, etc.

The data fields are tied to the shift ID which is selected from a dynamically populated drop down box. However, I cannot get the data fields to be updated when I select a new value and I cannot get the form to accept the new selected Shift ID. I have tried using JavaScript but cannot quite get it to work. Code:

View Replies !
Populating A Dropdown From A Database
I have put together a script that populates a dropdown menu from a database. My database contains a table called casinocredit, and it contains records that have been enterend over 2 different months (may and june). There is a field in the database that contains the date in this format: 2006-05-12 00:00:00

So The drop down is currently showing a month for each of those records. I was hoping that it would only display one. (the plan is when a user selects a month (say May) and hits submit, then I would display all of Mays records on a different page) See the image i have attached for a view of what is happening. Code:

View Replies !
Populating A Form Wth Database Info
I've coded a piece of code which populates a form with data read from the database:

$connection=mysql_connec ("localhost", "f2821842", "f2821842");
$result=mysql_select_db("QUERIES");
$query=mysql_query("Select * from Emp_Details where emp_num = '$employnum'");
while($row=mysql_fetch_array($query))
{$empname=$row['emp_name'];}

<form name="webregform" action="webadmin2.php" method="post">
<input name="requiredname" type="text" size="30" value="<?php echo "$empname"; ?>">
</form>

When I echo the $requiredname, I get spaces and no data, and I know that $empname is not a space-it does read a value in a database. 1. How can I get $requiredname to print a value?

View Replies !
Populating A Drop Box With Results From Database
I have a MySQL database with a table (category) with two fields, catId (int) and category (char(50)). What I want to do is to get all category names in this database and place all of them into a dropdown box on a web page so that the user can choose from the list of available categories.

View Replies !
Populating Checkboxes From A MySQL Database
what im doing is populating a php variable, and trying to use the result to add either checked or nothing to the value of the checkbox. Any ideas? Code:

View Replies !
Populating Drop Down Boxes From Database
I have two drop down boxes, the first one i am able to fill from my database using the following code. Code:

View Replies !
Populating Form From Database, Then Passing Results To Next Page
I have a multiple select input in a form that's being populated by a row
from my database as such:
<input type="checkbox" name="subm[]" value="$row[ID]">

That part is working fine as I can check the displayed page using View
Source and see that the value is the correct row number from the
database. It is then being submitted on a form by $_POST method to
another page where I want to evaluate the checkboxes and display the
contents of the entire row that corresponds to each value="$row[ID]"
that have been checked. But I can't seem to get it to work. I'm having a
problem passing the selected value. Can someone point me in the right
direction?

$query = ("SELECT * FROM `table`");
$result = mysql_query($query);

print "<p>Data for Selections:";
print "<table border=2><tr><th>You chose:";

foreach ($_POST['subm'] as $value) {
print "<tr><td>";
print "$row[ID];
";
print mysql_field_name($result, 1) . ": " . $row[name]."<br>";
print mysql_field_name($result, 2) . ": " . $row[address]."<br>";
print mysql_field_name($result, 3) . ": " . $row[city]."<br>";
print "</td></tr>";
print "</table>
";
}

if (!isset($_POST['subm'])){
print "<p>No matching entry ";
}

mysql_close();

View Replies !
SELECT Error: No Database Selectedin Query: SELECT * FROM Schedule
I got the above error message after reading FAQ #10 which applied to my first error. The thing is, I thought I had selected a database. This script is copied from a tutorial, and I'm just too new at this to spot my error. PHP Code:

View Replies !
Populating A Second "select" Field
is there a way to populate a second select field in a form based on input for a first select without reloading and using only php? Code:

View Replies !
Best Way To SELECT From Database
Regarding maintainability / good practice issues vs speed I have a question regarding what is the best way to SELECT some data from a database.

I have the item_id of an item bought. I want to get a customer's billing information based on the item he bought. Should I do this with two queries or one using joins? Code:

View Replies !
Select From Database
I am having a bit of trouble here trying to go to a name in a Mysql database and retrieve its id, what i am actually trying to do is: convert a url with for example dir/index.php?action=showcat&idcat=4 to dir/tablename/ instead of dir/4/ (4 being a table id) so what i need is to change the name in the url back to the id, i have tried the following without luck.

if ($catid){
$db=mysql_connect("localhost","user","password");
mysql_select_db("database",$db);
$query="SELECT 'id' FROM dir_categories WHERE name= '.$catid.' ";
$result=mysql_query($query);
$record=mysql_fetch_assoc($result);
$idcat=$record["id"];
}

View Replies !
Database Value Select In Combo Box!
This function is intended to display the current database field value as selected.. along with other values as general options.

I can't figure out how to get it work. Help is appreciated!!

function retrieve_category()
{
$cat = mysql_query("SELECT category_id FROM category");
while ($current_row = mysql_fetch_row($cat))
{
$row = $current_row[0];
if ($row == $id)
{
printf("<option selected>%s</option>
",$current_row[0]);
}
else
{
printf("<option>%s</option>
",$current_row[0]);
}
}
}

View Replies !
Select One Record From A Database
I am trying to select one record from a database. This databse has like 10 tables. I do not know which table this record is in. What php and mysql syntax would I use to accomplish this?

View Replies !
Randomly Select From Database?
this might seem like a stupid question, i should be able to do this. but on the front page of my site i want a thing to show a few users. but i dont want it to show the same people over and over. i want it to select different people each time. any ideas?

View Replies !
Select New Data From Database
how to select a new data from database.

View Replies !
Select Image From Database
A dbase is created, an image is in it a list exists based on title but I cannot get an image to display what is wrong with this code:

if ((!isset($_GET['id']) || trim($_GET['id']) == ' '))
{
die('missing record ID!');
}
$connection = @mysql_connect("localhost" , "root")
or die ('Unable to connect!');
@mysql_select_db($db) or die ('Unable to select');
$id = $_GET['id'];
$query = "SELECT imagedata FROM pixs4
WHERE id = '$id'";
$result = @mysql_query($query)
or die ("ERROR: $query. " . mysql_error());
$row = mysql_fetch_object($result);
if ($row)
.............

View Replies !
Select Last Record In The Database
I need to select the last record in a table. What is the query?

table = xyz

The data from this one row needs to be echoed on the page. Rather than have to write out every field, I'd rather have it just take each field's data and echo it on successive rows. How do I make it automatically do this?

Ex:

Fieldname1: Fielddata1
Fieldname2: Fielddata2

and so on.

View Replies !
Select List From A Database
I'm trying to dynamically generate a html select list from a MS Access database using the code below:

<?php
$conn=odbc_connect('customer','','')or die('Could Not Connect to ODBC
Database!');

$queryexe="SELECT * FROM types";

$rs=odbc_exec($conn , $queryexe)or die("Query failed: $sql<br />Error:
".mysql_error()."<br />");

echo "<SELECT name="typeId">";
while(odbc_fetch_row($rs))
{
echo "<option>".odbc_result($rs,"typeId")."</option>";
}
echo "</SELECT>";
?>

View Replies !
Database Select Problem
I'am getting this error on one of my pages "Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in".

<?php require_once('../Connections/conn.php'); ?><?php
mysql_select_db($database_web78-salon, $web78-salon);
$query_rsTimes = "SELECT DISTINCT availDate FROM savailability ORDER BY availDate ASC";
$rsTimes = mysql_query($query_rsTimes, $web78-salon) or die(mysql_error());
$row_rsTimes = mysql_fetch_assoc($rsTimes);
$totalRows_rsTimes = mysql_num_rows($rsTimes);
?>

View Replies !
Select Database Error
i cant seem to find the error in this code:

$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die("connection failed");
$db_select = mysql_select_db($databasename, $db) or die("no selection");

i have checked the variables above. if there was no such database, would it return an error such as "no database in MySQL"?

View Replies !
Selective Echoing And Database Select
I have written a search engine for business listings for the company I work for. Each listing is in a database, and that works fine. The problem though is two-fold.

The first part of the problem is that not all listings utilise every column of the database, and this leaves gaps when echoing the results. This is not what i had in mind, Any ideas/help would be appreciated.

The second part of the problem is related to the first in that there is a link for any listing that has a website, but not every listing has a website, so every listing having a "Visit our Site" link is impractical and shoddy. Also, i'm not sure how to echo the url from the database effectively in the first place.

View Replies !
Editing Mysql Database Row With Select Box
I have a small site, this small site has a few categories, now I can add items through my online admin area fine and delete them fine, but when it comes to editting them I am having some trouble, everything is working fine except the category column, because it is a drop down box I do not know how to have the category selected during the creation progress selected all the other info is loaded.

View Replies !
Randomly Select 5 Different Values From A Database
i want to randomly select 5 different values from a database, from one table, and then just assign those values to some php variable.

View Replies !
Multiple Select From Database Where Clause
I have a website with a database full of category names...I want to be able to chose lets say 5 of these categories and use a select from database clause where I could simply enter the category names I want to use but am not sure how I would go about doing it.

I can get the list to display just the Aprilia category using the code below:

$data1->q("SELECT * FROM categories WHERE cat_name = 'Aprilia' ORDER BY cat_name asc");

However...how could I get my site to display Aprilia, Ducati, Honda, Suzuki, Yamaha?

View Replies !
Using PHP And MYSQL To Select From Database Using Images
I'm trying to update a main page with a list of details matching a selection from a display of images that are displayed in a small window that have been selected from an image group using a select box in the main window, however I don't know how to do this and the main page is not receiving anything when clicking on an image so it's refreshing with empty data. 

I've seen many many pages giving examples of how to do this with select boxes or how to do this if only one entry uses an image shown in the small window, but the image display window is displaying many different small images not a select box and the database itself has multiple entries that use the same image.  Can anyone help?  I have a few instant chat programs if someone wishes to discuss this with me in real-time to see what it is I'm trying to achieve.

View Replies !
Tick Box, Select And Update Database.
I am trying to change the value in table with a tick box. If the tick box is selected it changes the value in the field to 'y' and if it is not selected it changes the field to 'n'.

First of all I need to bring back the current state of the field and then I need to be able to update it from 'y' to 'n' as many times as I want. Code:

View Replies !
Select Entries From A Database Where The First 3 Characters
I want to select entries from a database where the first 3 characters of one of the fields (title) are equal to 'BMX'. Is there a way of doing something similar to this as a query?: PHP Code:

substr($row['title'],0,3);

View Replies !
Select Latest Date From Database
I have a database with a table of events. Each event has a date

fieldname = events_date
fieldtype = date
format = 0000-00-00

What is the MySQL query to select only the one record with the latest date?

View Replies !
Running My Select Query Database
i have a html form called connect.html where i enter my username and password. I then click the submit button and if i am successful it will go to my handler1.php file

which will displays User [w1009048] successfully connected table is a page to my table.php pagef. When they click on the word table(link to table.php) i am running a select statment against my database: Code:

View Replies !
Select Two Items From Same Row In Database Table
Is there a quicker way of doing this (in php5)? It correctly picks $description_1 and $description_2, but uses two queries. I think I should be able to use one query only - but haven't figured how. Code:

View Replies !
Population Select Menu Using Php And Database Values
I have no idea how to go about this. so i would apreciate some help i want to populate the values in a html select menu from database values in one table

so i want all the values from 1 particular field in the database to be displayed in the select menu as separate options.

View Replies !
Displaying A List Of Categories From A Database In A Select Box
Could someone please tell me why this outputs nothing

<select name=categories>
<?
$cat_array = get_categories();
foreach($cat_array as $this_cat)
{
echo "<option value="";
echo $this_cat["category_id"];
echo """;
echo ">";
echo $this_cat["category_name"];
echo "
";
}
?>
</select>

==========================================================

function get_categories()
{
//get the list of categories from the database

$conn = mysql_pconnect("localhost", "user", "pwd");
$query = "select * from categories";
$result = mysql_query($query);
if(!$result)
return false;

$num_cats = mysql_num_rows($result);
if($num_cats == 0)
return false;

$result = db_result_to_array($result);
return $result;
}

//A function that returns a query to the database as an array
function db_result_to_array($result)
{
$res_array = array();
for($count=0; $row=@mysql_fetch_array($result); $count++)
$res_array[$count] = $row;

return $res_array;
}

View Replies !
Connecting Two Database Populated Select Menus
I am able to grab the data from the database to populate the menus individually using.
PHP Code:

View Replies !
Select Specific Phrase From MYSQL Database
I am working on a World of Warcraft guild's website and I am trying to create a page where players can select different kinds of gear, i.e. the gear with the most Stamina.

All the player's items are stored in the database and every item have a field in the Items-table containing the item's tooltip. This could look something like:

Boots of the Nexus Warden
Soulbound
Feet Cloth
97 Armor
+27 Stamina
+17 Intellect
Durability 35 / 35
Equip: Improves spell hit rating by 18.
Equip: Increases damage and healing done by magical spells and effects by up to 21.

I then want to select the item with i.e. the most Stamina for all the different slots; Head, Chest, Legs etc.

If I write this:
$query = mysql_query("SELECT substring(item_tooltip, LOCATE('Stamina', item_tooltip)) AS maxor FROM roster_items WHERE member_id = &#3962;'") or die(mysql_error());

It returns the following:
Stamina +17 Intellect Durability 35 / 35 Equip: Improves spell hit rating by 18. Equip: Increases damage and healing done by magical spells and effects by up to 21.

But I want for it to show the leading characters also (in this case "+27 " before "Stamina") and then not show anything else after the phrase "Stamina". So it shows "+27 Stamina" and nothing else for the above mentioned item. How do I accomplish this?

And then, secondly how do I then get it to show only the item with the most Stamina after it selected the above?

Hope this makes any sense.

I've tried to search these forums and found something a little along the lines of my problem but haven't been able to adjust them to my needs and I therefore need your help which will be greatly appreciated.

View Replies !
Reusing An Object For Common Select To Database
I've noticed that after I finished this app, I had repeated a similar task over and over and would like to modularize it. The repeated task was connecting to the database, executing a select, putting all the results of the columns into different variables of an object. PHP Code:

View Replies !
Simple Filter Of Database With $_GET And Select SQL
I need help with my logic statement with a simple search engine on a MySQL table.
I have three form text input fields named f_name, l_name and dept. I am using the GET method to gather data the user enters in each input field.

So far I have been able to build a check to see that the submit has been clicked but I am having trouble with assembling the SQL statement because I need for the search engine to be able to filter the results based on the information provided in 1-3 of the fields.

I could use if statements with some and clauses but that would mean that I would have to account for each combination. Something like

If(($_GET[‘f_name’] != “”) || ($_GET[‘l_name’] !=) || ($_GET[‘dept] !=)){

$sql = "SELECT * FROM facform WHERE f_name LIKE '$_GET[f_name]',
l_name LIKE '$_GET[‘l_name]', dept LIKE '$_GET[dept]' ”;}

The problem with this is that I would have to get every combination and it’s not very scalable. How can I create this SQL statement dynamically? Code:

View Replies !
Drop Down Menu That Will Select Which Database Is Needed
i want a drop down menu that will select which database is needed for that page..

see i have a site im making for a clan that plays like 10 different games and i wanna have 1 index but the dropdown menu will be at the beginning and when a player goes to the site they can choose which game they play so they can check the news and stuff.. the drop down menu should choose which database is needed? can this be done or will i have to make 10 different index.php pages?

View Replies !
PHP Script SELECT FROM Mysql Database WHERE Date
I am trying to develope my personal site to select from my mysql
database and organize data on the page so that it will display all the
submissions for that day, then break and display the next day, then
break and display the third day, etc.. Code:

View Replies !
Select All The Data From One Field In Various Database Tables.
I want to select all the data from one field in various database tables. Each field in each table has the same name. At the moment the query displays nothing? PHP Code:

$query = "SELECT m.name, r.name, s.name, sp.name ".
                  "FROM mergers as m, rights as r, spin_offs as s, splits as sp";

View Replies !
Retrieving Data From A Database Into A <select> Field
I'm writing a handfull of forms to enter data into a MySQL database, and then retrieve the data for editing. The form works fine when retrieving data into text boxes with

<input type=text value="<? echo $varname?>">
and with checkboxes by using
<input type="checkbox" <? if (isset($varname)) {echo "checked";}?>

My problem is that I can't use the above techniques to retrieve data from <select> lists. When I bring the edit form up, it returns the list's default value, and the default value is saved on the database unless the user changes the <select> field everytime the form is open.

I guess my question is simpler than I make it sound: how do I update a <select> field to display the value stored in the database?

View Replies !
Using Database Data For SELECT OPTION Statement
I want to use a <SELECT> / <OPTION> setup, and pull the data from a mysql database. I have done that, and don't necessarily have a problem with that. My problem is the database will have duplicate information in it, how do I only select one of each unique value? Code:

View Replies !
Select Form Options - Write To Database?
I have a form with a select list of skills that I want to write to a database and everything else except my select form works. Code:

View Replies !
Resource ID #5 - Select Data From MySQL Database Using PHP
I'm trying to select data from mySQL database using PHP and I encountered one problem. When I printed out the result after selecting data, it printed out "Resource ID #5" instead of the actual data. How can I fix this problem. Code:

View Replies !
Error In Generating Table From Database Select Statment
I am trying to dynamically create a table with the results from a select statement. Below is the code that is not working. Any help would be oh so greatly appreciated. This is for a final at school which is due in an hour. This is the only thing I can't seem to make work. Code:

View Replies !
How Do I Select Rows Created Yesterday From My MYSQL Database?
How do I select rows created yesterday from my MYSQL database?

I have worked out the code for today:

"DATE_SUB(CONCAT(CURDATE(), '00:00:00'), INTERVAL 0 DAY) <=postDateCreated"

View Replies !
Select Records By The Year From A Mktime() Stamp In The Database
I'm trying to select records by the year from a mktime() stamp in the database. I thought I could do it this way: PHP Code:

$new_date = "2006";
   $query = "select date, DATE_FORMAT(date,'%Y') AS year from articles where year = $new_date";

But I'm doing something wrong and haven't been able to figure out what it is. 2 hours of reading documentation and I'm missing something.

View Replies !
Select Specific Snippet Of Text, Replace With A Database Result
I'm having some problems trying to do something; I just can't think of a way to do it. Basically, I want to search for a specific snippet of text in a body of text, then replace it with the requested database result with some thrown in HTML.

Users will be able to type the following (or something along these lines, depending on what works best): [image=12345]Insert caption here[/image]

Then I need it to search for the requested image in the appropriate table and return the image's url (for an example, let's say the table is called "images", and the columns required are "imageid" and "imageurl". Code:

View Replies !
Populating A Combo Box
Using php how can i give a combobox a default value when the page is loaded?

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved