how to fetch a value to dropdown?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 1580 Views - Last Post: 23 August 2015 - 10:20 PM Rate Topic: -----

#1 thartrepair   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-August 15

how to fetch a value to dropdown?

Posted 22 August 2015 - 07:52 AM

how to fetch a value to dropdown,so that i can change and update the into the database.

situation;

the value am going to update is displayed on the page in the form of table, in which each row has update link.

this is my display table.

while($row = mysql_fetch_array($query)) 

{
echo "
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['patientid']."</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['trandate']."</td>
<td style='border:1px solid; color:gray' width='600px'>".$row['trandescription']."</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>".$row['tranquantity']."</td>
<td style='border:1px solid; color:gray' width='90px' align='right'>".number_format($row['tranunitprice'],2)."</td>
<td style='border:1px solid; color:gray' width='150px' align='right'>".number_format($row['tranamount'],2)."</td>
<td style='border:1px solid; color:gray'><a href='updatebillindex.php?update=$row[id]'>update</a></td>
<td style='border:1px solid; color:gray'><button class='btn btn-default btn-sm';><a href='updatebillindex.php?update=$row[0]'>edit
<span class='glyphicon glyphicon-trash'></span></a></button></td>

</tr> ";

}


this is my updatebillindex.php and dropdown list from database.

<?php
			if (isset($_GET['update'])) 
			{
			
			$id = $_GET['update'];
			
			$query = mysql_query("SELECT * FROM transaction where id = '$id'") or die ("could not search");
			$count = mysql_num_rows($query);	

			while ($rows = mysql_fetch_array($query)) {

			$id = $rows['id'];
			$tranid = $rows['tranid'];
			$trandate = $rows['trandate'];
			$patientid = $rows['patientid'];
			$transactiontype = $rows['transactiontype'];
			$trandescription = $rows['trandescription'];
			$tranquantity = $rows['tranquantity'];
			$tranunitprice = $rows['tranunitprice'];
			$tranamount =$rows['tranamount'];
			$gettrandescription = $rows['trandescription'];

			}
			
	}

			?>
			
			<form action="billindex.php" method="POST">

			<input type="text" name="id" value="<?php echo "$id"; ?>">
			<input type="text" name="tranid" value="<?php echo "$tranid"; ?>">
			<input type="text" name="patientid" value="<?php echo "$patientid"; ?>">
			<input type="text" name="trandate" value="<?php echo "$trandate"; ?>">
			<input type="text" name="transactiontype" value="<?php echo "$transactiontype"; ?>">
			<input type="text" name="trandescription" value="<?php echo "$trandescription"; ?>">
			<input type="text" name="tranquanity" value="<?php echo "$tranquantity"; ?>">
			<input type="text" name="tranunitprice" value="<?php echo "$tranunitprice"; ?>">
			<input type="text" name="tranamount" value="<?php echo "$tranamount"; ?>">
			<input type="submit" name="update" value="Update">

			</form>

			<?php
			echo "$trandescription";
			?>


div class="panel panel-info">
																					<div class="panel-heading"><h7>Medicine Type : </h7></div>
																						<div class="panel-body">
																							<select name="selectmedicine" class="form-control col-sm-4" id="medicinename">
																								<option id="0" style="width:100px"></option>
																									<?php

																										$medicine = mysql_query("SELECT * FROM medicine");
																									    while ($row = mysql_fetch_array($medicine)) {
																									        echo '<option id="' . $row['medicinename']  . '"';
																									        echo ' value="' . $row['medicineid'] . '"';
																									        if($row['medicineid'] == $row['medicinename']) {
																									           echo ' selected="selected"'; 
																									        }
																									        echo '>';
																									        echo $row['medicinename'];
																									        echo '</option>';           	
																									}
																									?>
																							</select>
																						</div>
																				</div>
																			</div>			


the update will took place in the dropdown, thats why I need to display/fetch the value am going to update in dropdown as selected.

This post has been edited by andrewsw: 22 August 2015 - 07:58 AM
Reason for edit:: Added [code][/code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: how to fetch a value to dropdown?

#2 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,532
  • Joined: 12-December 12

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 07:59 AM

How to use code tags

Attached Image
Was This Post Helpful? 1
  • +
  • -

#3 thartrepair   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-August 15

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 08:08 AM

thanks for the info and changing my post into tags

This post has been edited by andrewsw: 22 August 2015 - 08:13 AM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,532
  • Joined: 12-December 12

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 08:12 AM

The mysql extension is deprecated and should not be used for new code. See my signature below. It has been removed from the most recent version of PHP.

Nor do table elements have width and align attributes, use CSS. If you are working from a tutorial then you need to find one that is at least reasonably up-to date.

What's wrong with your code, does it work? In which case, presumably you are asking about adding something completely new to it?

This post has been edited by andrewsw: 22 August 2015 - 08:13 AM

Was This Post Helpful? 1
  • +
  • -

#5 thartrepair   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-August 15

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 08:19 AM

thanks for the reply and suggestion. i will do as advised.

the problem is i dont know how to code in displaying the value into dropdown so that i can change/update the value thru downdown.
yes, the code is working.

This post has been edited by andrewsw: 22 August 2015 - 08:21 AM
Reason for edit:: removed botched quotes

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,532
  • Joined: 12-December 12

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 08:22 AM

Note that you do not have to quote the previous post, there is a Reply button further down the page, or use the Fast Reply box.
Was This Post Helpful? 1
  • +
  • -

#7 thartrepair   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-August 15

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 08:24 AM

tnx
Was This Post Helpful? 0
  • +
  • -

#8 thartrepair   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-August 15

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 08:37 AM

btw, the variable $trandescription is the value am going to display on the dropdown.
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,532
  • Joined: 12-December 12

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 08:51 AM

What are you planning to do with the information that the mysql extension, and width and align attributes, are no longer supported?

If you want to display all the trandescriptions in a drop-down, a select element, then you first have to collect them all. You might collect them in an array before constructing the select.

If people are to select from an existing list of trandescriptions then they should be stored in a separate, linked table, and connected via an id number.

It also strikes me that you should not be storing an id, transaction details and patient id all in the same table. This is a "transaction" table so tranid should identify it, there should not be a need for another id value. (Having a tranunitprice is another indicator that your database structure is wrong. Do you have more than one table?)

This post has been edited by andrewsw: 22 August 2015 - 08:58 AM

Was This Post Helpful? 1
  • +
  • -

#10 thartrepair   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-August 15

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 09:01 AM

the mysql fetch array in the code above is the table displayed on page which has a update link. when I click the update link the rows selected is displayed on the input text i above, the $transdescription is the only value am going to update, in which this value has the same value on the dropdown. the user cannot change the value by typing but thru the value in the dropdown. the dropdown has a list of value from the database. sorry if this not well explain am not that good in english.
Was This Post Helpful? 0
  • +
  • -

#11 thartrepair   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-August 15

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 09:07 AM

the input text above is just sample display that i really selected and displayed the correct row value, it will be hidden soon as i know how to fetch the value on the dropdown. sorry for that.
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,532
  • Joined: 12-December 12

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 09:11 AM

To help you, sentences begin with a capital letter.

You haven't responded to or acknowledged my previous post so I'll leave it to someone else who might want to assist you. Good luck.
Was This Post Helpful? 1
  • +
  • -

#13 thartrepair   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-August 15

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 09:17 AM

Please Andrewsw?

Am just a new member here, am still learning the dream in code ways. sorry.
Was This Post Helpful? 0
  • +
  • -

#14 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,532
  • Joined: 12-December 12

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 09:23 AM

If you want all the trandescriptions to appear in a drop-down, a select, then, as I said, you need to collect them first. SELECT trandescription FROM transaction. Then loop through the returned values, either using each to add an option to the selection, or store all the values into an array so that you can construct the select further down in the code.
Was This Post Helpful? 0
  • +
  • -

#15 thartrepair   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-August 15

Re: how to fetch a value to dropdown?

Posted 22 August 2015 - 09:34 AM

No, the transdescription value has the same value on the dropdown [selectmedicine]. So when i click the update link on the row this trandescription value will be displayed on the dropdown as selected on the dropdown since i click the update.

dropdown values - transaction table transdescription values
- medicinenames - medicinenames
- roomnames
- laboratorynames
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3