Forum Moderators: coopster

Message Too Old, No Replies

combo box from mysql

         

JuicyScript

10:22 am on Oct 29, 2009 (gmt 0)

10+ Year Member



I've been trying to find a way to disable an item on my combo box when that item is submit into the database...But dont knw where to begin.Can someone give me and idea.

mvaz

1:46 pm on Oct 29, 2009 (gmt 0)

10+ Year Member



Where is the data to your combo box coming from? If it is hardcoded, then you cannot change this.

JuicyScript

4:15 pm on Oct 29, 2009 (gmt 0)

10+ Year Member



it's coming from the database...is it possible

mvaz

4:19 pm on Oct 29, 2009 (gmt 0)

10+ Year Member



You should be able to echo it only if it does not exist in the table.

I am a bit confused though, for are you trying to update an entirely different table?

Your coding, if was provided, would have helped in this case.

JuicyScript

4:49 pm on Oct 29, 2009 (gmt 0)

10+ Year Member



<?php
require_once('config.php');
// Connect to the database
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
$query = "SELECT Items FROM members ";
//print_r($query);
// exit();
$sql = mysql_query($query);
$result=mysql_fetch_array($sql);
echo print_r($result);
//exit();

if(@mysql_num_rows($result)) {
while($row = mysql_fetch_row($result))
{

@print("<option value=\"$row[0]\">$row[0]</option>");
}
}
elseif($result('bag')>=4)
disable bag
else {
print("<option value=\"\">No courses created yet</option>");
}

?>

What i want to achieve here is that after a users select an item for the dropdown box and submit for 4 times that particular item with b disabled to all other users

mvaz

5:02 pm on Oct 29, 2009 (gmt 0)

10+ Year Member



You could put in an extra column for counts, and increment it by 1 everytime it is selected and when reached 4, prevent it from displaying by modifying your query.

I am afraid, I am not all that great in explaining in words, but the concept is here, in my mind.

JuicyScript

5:17 pm on Oct 29, 2009 (gmt 0)

10+ Year Member



$sql2="UPDATE members SET bag=bag+1 WHERE 'login='";
Ok i've got the concept but can u check the script i posted earlier cos
print("<option value=\"$row[0]\">$row[0]</option>");
does not get executed

rocknbil

5:24 pm on Oct 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, if you are doing this from PHP, you shouldn't be outputting a select list at all.

A bit of a rush today and don't have time to add precise code, but I would output something based on a "check" of the database data. You could do a count(*) or something like

select count(*) from table (or whatever . . .check it first)

if ($count >= 4) { echo "Not available"; }
else {
// your code to output the select
}

JuicyScript

10:19 pm on Oct 29, 2009 (gmt 0)

10+ Year Member



ok i have the script below which fetch data from mysql...how will i resubmit it to another table since it does not have a combo box name
<?php
while ($row = mysql_fetch_array($query)) {
echo '<select name="items">';
while ($row = mysql_fetch_array($query)) {
echo '<option value="',$row['options'],'">',$row['options'],'</option>';
//echo '<option value="',$row['username'],'">',$row['username'],'</option>';
}
echo '</select>';
}

?>