General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 14th, 2004, 10:35 AM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
Select box dilemma

I am hoping that someone out there can help me with a problem I am having with select boxes in PHP. I am using PHP 4.3.4 with Apache and MySQL. My problem is I have a set of select boxes which enable the user to select a value and store it in my database. I want the value the user selected to be pulled from the database and displayed the next time the user visits the page. The problem is that my select boxes always revert back to displaying the original list when the user visits the page and not the selected item which was stored in my MySQL database by the user. I have searched endlesslessy and found very little information on doing this in this forum as well as the Internet. I have been looking for over a month so thought it was time to ask for some help.

Thanking you in Advance for any guidance.

Reply With Quote
  #2  
Old April 15th, 2004, 02:52 PM
devqual devqual is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Porto, Portugal
Posts: 33 devqual User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 19 m 41 sec
Reputation Power: 15
I'm not sure what you are asking but...

A piece of your code would help...

When you have a select box and you define options that you want to be checked you should use:

<option value="--anything--" Selected>Option1</option>

try to get out the value from your table and use something like this:

<?
If ($user_variable=="--your_option_value--") {
$select="selected";
} else {
$select="";
}
?>
<option value="--your_option_value--"<?=$select?>> OptionX </option>

I hope this help's

I'm not an expert, there's maybe a more obvious and correct solution but I'm using this and it work's well...

Reply With Quote
  #3  
Old April 16th, 2004, 01:26 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
Here is my select box code.
<select size="1" type="option" name="CCOUNTY">
<option value="1">Belknap</option>
<option value="2">Carroll</option>
<option value="3">Cheshire</option>
<option value="4">Coos</option>
<option value="5">Grafton</option>
<option value="6">Hillsborough</option>
<option value="7">Merrimack</option>
<option value="8">Rockingham</option>
<option value="9">Strafford</option>
<option value="10">Sullivan</option>
<option value="11">OOS</option>
</select>
My select lists consists of a list of counties as you can see above. When a user selects a county and saves the form the data is written to a field in the database called CCOUNTY as a value which was associated with their selection. Currently when the user goes back to the page the value in the select box reverts to the value in the top of the list namely Belknap. What I would like is to have the value displayed to be the value which the user chose when submitting the form. If user selects Rockingham when they completed the form and saved it, the value 8 was stored in the database. When the user returns to the page for the second time the select box displays Rockingham. I hope this helps to show what I am trying to accomplish. I appreciate your response.
Scot

Reply With Quote
  #4  
Old April 16th, 2004, 03:12 PM
devqual devqual is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Porto, Portugal
Posts: 33 devqual User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 19 m 41 sec
Reputation Power: 15
Ok,

if you want than When the user returns to the page for the second time the select box displays Rockingham
you must have the following html code:

<option value="8" selected>Rockingham</option>

so you must have a query that returns the user value in a new var ($user_val for instance) and perform something like that for each option.

<?
If ($user_val==1){
$select="selected";
} else {
$select="";
}
?>
<option value="1" <?=$select?>>Belknap</option>
...
<?
If ($user_val==8){
$select="selected";
} else {
$select="";
}
?>
<option value="8" <?=$select?>>Rockingham</option>
...

I hope that help's...

Reply With Quote
  #5  
Old April 16th, 2004, 04:34 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
Thanks I will try this approach. I hate to be a pest but I am new to PHP. I know how to write a query to the MySQL database, but how do I get that value to be represented by my new variable, $user_val ? Thanks for your help so far. I really appreciate it!

Reply With Quote
  #6  
Old April 17th, 2004, 05:41 AM
devqual devqual is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Porto, Portugal
Posts: 33 devqual User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 19 m 41 sec
Reputation Power: 15
Try something like this...

$hDB = mysql_connect('your_sql_server', 'your_user', 'your_pass')*;
mysql_select_db('your_database', $hDB);
$Query="your query";
$Result=mysql_query($Query, $hDB);
$Arr=mysql_fetch_row($Result);
$user_val=$Arr['field_name_in_the_table'];



*-If you are running Apache in your PC it probably turns in
$hDB = mysql_connect('localhost', '', '')

Reply With Quote
  #7  
Old April 19th, 2004, 01:40 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
I am excited now!

It almost works! Closer than the six weeks I have been trying answers and snippets of code from everywhere!! I want to tell you that I really appreciate the help!!!!!! I am probably not doing the best at explaining what I need. So I will try again. If your nice enough to help me I will try to explain exactly what I am looking for....

The select box works but it still doesn't pull the value from my database called "nhla_cases", table"_clientsw" or field "CCOUNTY" Each record in the table has a unique identifier "CLIENTNUM". When a user selects a county from the select box that value is written to the field "CCOUNTY" in the form of a number i.e. 1 through 11 corresponding to the county they selected. Now when the user returns to the same record for a second time I would like the value i.e. county name displayed in the select box which corresponds with the number in the database they selected when they initially entered the record. So if I open a record where the CLIENTNUM = 3 the select box will return the value from the field CCOUNTY which corresponds with the county in which the person lives. The following code is what I have thus far. If your willing to give me just another little nudge in the right direction I think I will have it! Thanks so much for your help and your patience. I am still an idiot at most of this stuff.
Code:
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title>Title here!</title>
</head>
<body>
<?php
$hostname='localhost';
$username='root';
$password='';
$database='nhla_cases';

mysql_connect("localhost","root","");
mysql_select_db('nhla_cases');
$Query="SELECT CLIENTNUM,CLNAME,CFNAME,PCODE,CADDRESS,
CCITY,CSTATE,CZIP,CACODE,CPHONE,CASETYPE,DOPEN,
CCOUNTY,SEX,AGE,RACE,CHILDREN,ADULTS,KNOW,OFFICENU  M,
FUNDSNUM,SNUM,PHELPED,CITIZEN,CMI,SSN,BDATE,LANGUA  GE,
MARITALS,SLNAME,SFNAME,CSTATUS,EXT,LIVEAR,SERVICE,  IRCLOSED,UW FROM _clientsw WHERE CLIENTNUM='{$_REQUEST['CLIENTNUM']}'";
$Result=mysql_query($Query);
$Arr=mysql_fetch_row($Result);
$user_val=$Arr['CCOUNTY'];
?>
//output to html
<form>
Enter CLIENTNUM TO FIND THE COUNTY WHERE CLIENT LIVES:<input type="text" name="CLIENTNUM" size="4"><BR>
<select name="CCOUNTY">
<?
If ($user_val==1){
$select="selected";
} else {
$select="";
}
?>
<option value="1" <?=$select?>>Belknap</option>
<?
If ($user_val==2){
$select="selected";
} else {
$select="";
}
?>
<option value="2" <?=$select?>>Carrol</option>
<?
If ($user_val==3){
$select="selected";
} else {
$select="";
}
?>
<option value="3" <?=$select?>>Cheshire</option>
<?
If ($user_val==4){
$select="selected";
} else {
$select="";
}
?>
<option value="4" <?=$select?>>Coos</option>
<?
If ($user_val==5){
$select="selected";
} else {
$select="";
}
?>
<option value="5" <?=$select?>>Grafton</option>
<?
If ($user_val==6){
$select="selected";
} else {
$select="";
}
?>
<option value="6" <?=$select?>>Hillsborough</option>
<?
If ($user_val==7){
$select="selected";
} else {
$select="";
}
?>
<option value="7" <?=$select?>>Merrimack</option>
<?
If ($user_val==8){
$select="selected";
} else {
$select="";
}
?>
<option value="8" <?=$select?>>Rockingham</option>
<?
If ($user_val==9){
$select="selected";
} else {
$select="";
}
?>
<option value="9" <?=$select?>>Strafford</option>
<?
If ($user_val==10){
$select="selected";
} else {
$select="";
}
?>
<option value="10" <?=$select?>>Sullivan</option>
<?
If ($user_val==11){
$select="selected";
} else {
$select="";
}
?>
<option value="11" <?=$select?>>OOS</option>
</select>
<input type="submit" value="">
</form>
</body>
</html>

Last edited by stumpy : April 20th, 2004 at 06:25 PM. Reason: Placed code in [CODE] tags

Reply With Quote
  #8  
Old April 20th, 2004, 02:14 PM
devqual devqual is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Porto, Portugal
Posts: 33 devqual User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 19 m 41 sec
Reputation Power: 15
I not sure what's the problem but try this...(for the experts is not the correct way but it might work)

$Query="SELECT
CCOUNTY FROM _clientsw WHERE CLIENTNUM='{$_REQUEST['CLIENTNUM']}'"; (you only need one field it's not necessary to resquest all)
$Result=mysql_query($Query);
while ($Arr=mysql_fetch_array($Result){
$user_val=$Arr['CCOUNTY'];
} // it shouldn't be necessary to have a while cicle because you have only one result but it will work any way...

Please let me know the result..


Reply With Quote
  #9  
Old April 22nd, 2004, 11:38 AM
fizker fizker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: denmark
Posts: 42 fizker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 18 sec
Reputation Power: 15
Send a message via MSN to fizker
I have made something like this a couple of times. But usually i get the content of the <select> from the database as well, because it means that adding additional entries in the future is easier and because i can more easily convert the id-number to the name of the object.

in this case, i would create a table for the counties, perhaps called counties, with two columns: id and name. Fx, for Belknap, the id would be '1' and the name 'Belknap'.

for filling the select i would use a simple while-loop to add all the options and at the same time check if the current option should be selected:
PHP Code:
<select name=''>
<?
$query mysql_query("SELECT * FROM counties");
while(
$array mysql_fetch_array($query)) {
   if(
$array['id'] == $user_val) {
      print 
"<option selected value=$array[id]>$array[name]</option>";
   } else {
      print 
"<option value=$array[id]>$array[name]</option>";
   }
}
?>
</select> 


this is much prettier code than what you used, and if you ever need to type in a new county, just enter it into the database and it will appear on the list.

as for your own query, i would recommend typing it like this:

PHP Code:
 $Query="SELECT * FROM _clientsw WHERE CLIENTNUM='".$_REQUEST['CLIENTNUM']."'"


It is decidedly easier to look at, and it just takes everything from the table instead of just the fields you requested.

Reply With Quote
  #10  
Old April 27th, 2004, 12:17 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0

Reply With Quote
  #11  
Old April 27th, 2004, 12:28 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
Thanks fizker!!!

I will give your idea a try about creating the table counties,it sounds like a good one. I am still in a fog as to how I get the right selection returned from the field CCOUNTY in the _clientsw table. I.E. to display in the form the selection that was initially recorded when the record was added to the table

Reply With Quote
  #12  
Old April 27th, 2004, 02:59 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
Not Quite There Yet!

I really appreciate everyone's help!!!! The idea of putting the select values into the table works GREAT! Certainly much more practical than hardcoding in html! Also a very helpful suggestion on abbreviating the query. But I still cannot get the select box to retrieve the correct value from the database field "CCOUNTY" in the table "_clientsw". I am beginning to feel really dumb. Everyone has had such good suggestions but it still don't work! I don't know if its something I am overlooking or I just haven't explained it correctly.

Reply With Quote
  #13  
Old April 29th, 2004, 04:20 AM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 15
Send a message via MSN to Pheifel
for all means, always putting the data into a db, this makes it easy'r to get multiple both languages and sellect options

Reply With Quote
  #14  
Old May 2nd, 2004, 02:46 PM
Morrowind Morrowind is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Finland
Posts: 7 Morrowind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to Morrowind
Option list shows the selected item correctly

Hi Scot! This code creates option select list and populates it dynamically and it shows the selected item which was stored in the database by the user. I hope that this code will help you.


PHP Code:
<?php 
$sql_cat 
'SELECT cat_id, cat_name FROM category'
$result1 mysql_query($sql_cat); 
 echo 
"\n<select size=\"1\" class=\"tfield\" name=\"cat_id\">";
while (
$fetch_category mysql_fetch_row($result1) )
{

echo 
"\n<option value=\"$fetch_category[0]\" "; if ($row['cat_id'] == $fetch_category[0]){echo "selected";} echo ">$fetch_category[1]</option>";
}
echo
"\n</select>"

$cat_id $fetch_category[0];
echo 
$fetch_category[0]; 

?>

Reply With Quote
  #15  
Old May 3rd, 2004, 11:11 AM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
Looks promising But can I ask a few questions

Morrowind
You will have to excuse me. I am so new to this stuff I am wet behind the ears. The code creates the dynamic select box great! But how do I plug in the variables for the table where the user input is stored named "_clientsw". The value is stored in the field 'CCOUNTY' I am not really sure where to include these in the code. Thanks Again! I really appreciate the assist. Have a Great Day!

Reply With Quote
  #16  
Old May 3rd, 2004, 01:26 PM
fizker fizker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: denmark
Posts: 42 fizker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 18 sec
Reputation Power: 15
Send a message via MSN to fizker
what exactly are you trying to do? just retrieving the value in the field called 'CCOUNTY'?
because that could hardly be more simple. to refer to the example i gave, i get the value from field 'id' with the words $array['id'] and the value from the name with $array['name'].

to retrieve the value from 'CCOUNTY', just type $array['CCOUNTY']. the >'< is not always necessary, but sometimes it is, and the code is more pretty to look at if you use some simple conventions such at that
__________________
Benjamin Horsleben
horsleben.com/benjamin
Don't blame malice for what stupidity can explain

Reply With Quote
  #17  
Old May 3rd, 2004, 03:55 PM
Morrowind Morrowind is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Finland
Posts: 7 Morrowind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to Morrowind
One problem unsolved for me, too

Quote:
Originally Posted by Scot
Morrowind
You will have to excuse me. I am so new to this stuff I am wet behind the ears. The code creates the dynamic select box great! But how do I plug in the variables for the table where the user input is stored named "_clientsw". The value is stored in the field 'CCOUNTY' I am not really sure where to include these in the code. Thanks Again! I really appreciate the assist. Have a Great Day!
I'd really want to give answer to your question, but I have the one problem yet and I could not solve it so far. So, I cannot store the new selected value from option select list by the user to the database. I do not know how the selected value (cat_id) could be passed from the form to the table (cat_id field). My INSERT query works perfectly, but UPDATE does not work with dynamically populated option select list.

My current code for UPDATE form is here:
PHP Code:
//Begin of the form
echo "\n<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=\"management.php?id={ $_GET['id']}\">";
//ENCTYPE because I update the image,too
<br>
<
br>
<!-- 
Form user interface (option select and input and textarea are here and then the submit buttons-->
<
input type="hidden" name="id" value=<?php echo "{ $_ GET['id']}" ?>>
<input type="hidden" name="cat_id" value=<?php echo "{ $_POST['cat_id']}" ?>>
 
<input type="submit" name="deletebutton" class="button" value="Delete item">&nbsp;<input type="submit" name="save" class="button" value="Update">
</FORM> 


And UPDATE query

PHP Code:
if (isset( $POST['save'])) 

//Trying to pass the selected value from option select to the database, but not working... 
echo "\n<input type=hidden name=id value={ $_GET['id']}>";
echo 
"\n<form><input type=hidden name=cat_id value={$row['cat_id']}></form>";
 
$result2 mysql_query 
("UPDATE products SET product='$product',cat_id='$cat_id',description='$  description', image='$image' WHERE id = '"$_GET['id']."'"); 


If someone can see, what is still wrong with the codes, me too would be very thankful. I have tried to solve this problem many days.

Reply With Quote
  #18  
Old May 3rd, 2004, 06:10 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 15
Send a message via MSN to Pheifel
hmmm.... not to be a bitch. But seriously. Morrowind. Why is it, that you keep trying to make new ways of confusing people. ???... and why is it that you so badly want to hardcode unnessesary information ad ugly coding into the site ?... why not just do it like fizker suggested ? thats much easier.

Reply With Quote
  #19  
Old May 4th, 2004, 12:41 AM
Morrowind Morrowind is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Finland
Posts: 7 Morrowind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to Morrowind
Because I suspect, that fizker's way is not enough for my situation at least. I think, I need not value but id-number to store the database in update query. And because I believe that I am quite near to solve the problem in this way, but some confusing things are still.
If fizker's way is enough for my situation, I am more than happy to get out of this problem.

Reply With Quote
  #20  
Old May 4th, 2004, 04:34 AM
fizker fizker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: denmark
Posts: 42 fizker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 18 sec
Reputation Power: 15
Send a message via MSN to fizker
i don't know what you are trying to do:
is the select-object populated correctly? and does it post to the page that handles the update/insert? if so, why use the hidden inputs? that makes no sense.

what you need as the value in the <option> is a unique value from the database. the id-column for example. or anything else that is unique for the row in question. my example uses the id, because that is usually a thing that is certain to be unique...

and as for your update-query, the only thing that catches my eye is a few whitespaces here
Code:
...description='$  description'...

Reply With Quote
  #21  
Old May 4th, 2004, 10:19 AM
Morrowind Morrowind is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Finland
Posts: 7 Morrowind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to Morrowind
Quote:
Originally Posted by fizker
i don't know what you are trying to do:
is the select-object populated correctly? and does it post to the page that handles the update/insert? if so, why use the hidden inputs? that makes no sense.

what you need as the value in the <option> is a unique value from the database. the id-column for example. or anything else that is unique for the row in question. my example uses the id, because that is usually a thing that is certain to be unique...

and as for your update-query, the only thing that catches my eye is a few whitespaces here
Code:
...description='$ description'...
I try to explain...my admin system is this kind:
1) browse producs.php page: select all items in products-table and create dynamic links based on product's id-number.
2) When click that link, the id of the selected product will be passed to the management page to update or delete the item
3) management.php page has form and the id of the selected product is passed to the form in this way (METHOD=\"POST\" ACTION=\"management.php?id={ $_GET['id']}\">"
So my form action is dynamic, too.
4) The form contains some INPUT type fields and text area and that option select list. The option select list works fine, it is populated dynamically and the value, that some user has selected (by using INSERT quey) to be pulled from categories table and displayed in the list. So far everything is just fine and all text fields and text area can be updated without errors.
5) But the problem occurs in this way: if the user want to update the category of the product, the new value from the option select list cannot be saved to the products table by UPDATE query. The new value cannot be passed from the form to the database, the result is always zero.

My form cannot send the id number via URL, that must be a problem with option select list.
The cat_id field in the products table is tinyint(4) and cat_id in the categories table is tinyint(4), too.
I tried to change cat_id field type to VARCHAR, but it was useless.

The selected value of option select list lost and cannot ever "find" to the database. This is the reason why I tried to use HIDDEN fields to pass the id and cat_id's value to the UPDATE query. But is was not successfull, and now I do not know what I should do.
I have add_product page dynamically populated option select list and the INSERT query works great here.


PS. The whitespaces in the UPDATE query was some error or typo in this text editor. My query has not whitespaces really.

Reply With Quote
  #22  
Old May 4th, 2004, 11:39 AM
fizker fizker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: denmark
Posts: 42 fizker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 18 sec
Reputation Power: 15
Send a message via MSN to fizker
you are propably quite right that it won't work with varchar, because of autoincrement and the way it works. and there is no use trying to force your tinyint to be 4 characters long, as it is only 1byte big, which gives it a span from -128 to 127 (taken from the mysql manual: http://dev.mysql.com/doc/mysql/en/Numeric_types.html ). I would recommend mediumint or int instead.

are you sure that the post-form on management.php is working correctly? because i don't believe you can use '{' or '}' the way you try to. a good thing is always echoing the posted values to the screen just to make sure it actually posts them correctly .

the same for your hidden fields. as far as i know, using '{' or '}' that way is just not possible.

but otherwise, give me a copy of your file and it will be easier to see what you mean. if i can get it working, you can have it back and you can compare what i did with what you did yourself.

Reply With Quote
  #23  
Old May 4th, 2004, 03:16 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
My problems

Fizker
Thanks for your continued patience. I am using the code you gave me to dynamically create the select box like so...

<select name=''>
<?
$query = mysql_query("SELECT * FROM counties");
while($array = mysql_fetch_array($query)) {
if($array['id'] == $user_val) {
print "<option selected value=$array[id]>$array[name]</option>";
} else {
print "<option value=$array[id]>$array[name]</option>";
}
}
?>
</select>
Obviously this pulls my list of counties from a table called counties with two fields, id and name. From this select box the user chooses the county from the list and that value associated with the county is saved in the table clientsw to the field CCOUNTY. It records the county that the person lives in. For example User selects county Belknap with an id of 2 from the above select list. That value 2 is stored in the clientsw table in the field CCOUNTY.

The next time the user visits the page and pulls up this record identified by the id I call CLIENTNUM I would like the select box to display the name of the county which is stored in the field CCOUNTY. This means if the record in clientsw table has a CLIENTNUM of 13 the select query retrieves the record for CLIENTNUM 13 where 2 is the variable saved in CCOUNTY field. My problem is pulling this value 2 from CCOUNTY and displaying it to the user as the name associated with it Belknap. Right now my select boxes always revert back to display the first item in the table counties, and not the value stored in the clientsw table in the field CCOUNTY. I hope this helps you understand my dilemma. You have given me some excellent help so far!!
Thanks
Scot

Reply With Quote
  #24  
Old May 5th, 2004, 03:04 AM
fizker fizker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: denmark
Posts: 42 fizker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 18 sec
Reputation Power: 15
Send a message via MSN to fizker
heh. no problem. i would hate having a problem and noone to help me . so basically, im just doing to you what i hope others will for me

to do what you want, i would recommend that when the user logs in and opens the page, the $user_val is set to the value from CCOUNTY. this would use the existing code to display the chosen value.

the code would be something like this:
PHP Code:
 $clientnum 13//or whatever the user is :)
$client mysql_fetch_array(mysql_query("SELECT * FROM clientsw WHERE CLIENTNUM = '$clientnum'"));
$user_val $client['CCOUNTY']; 

That should do it

Reply With Quote
  #25  
Old May 5th, 2004, 06:09 AM
Morrowind Morrowind is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Finland
Posts: 7 Morrowind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to Morrowind
Quote:
Originally Posted by fizker
heh. no problem. i would hate having a problem and noone to help me . so basically, im just doing to you what i hope others will for me

You have the same way to think than I do I think PHP is community, where programmers can share ideas and help each others if they have problems.

I sent my php files to you via private message and gave a link to copy the files you asked. I compressed the files with Winzip and added more comments in English to the codes.

Reply With Quote
  #26  
Old May 5th, 2004, 03:42 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
Muchas Gracias fizker! Happy Cinco De Mayo! That last snippet of code fixed all my problems with a little tweaking! Thanks Thanks and Thanks Again!!!
Scot

Reply With Quote
  #27  
Old May 6th, 2004, 04:07 AM
fizker fizker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: denmark
Posts: 42 fizker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 18 sec
Reputation Power: 15
Send a message via MSN to fizker
scot: good. i'm happy to have been of assistance
morrowind: i have looked through your code and have sent it back with some changes

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Select box dilemma


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap