Jump to content

Retrive The Values From Array


yangkai9999
 Share

Recommended Posts

Hello,I can use the following code to get values into array info. I need to present those values at a html form and to make change later. I don't know how to retrive the values from the array into post variables. Can I get example form you?Thank you,code://get the value from table p2 for a specific p_id;$query = mysql_query("SELECT * FROM mytest.p2 WHERE p_id=$chk;");// puts the P2 data into the $info array $info = mysql_fetch_array( $query ); // Print out the contents of the entry Print "<b>P_ID:</b> ".$info['P_ID'] . " <br>"; Print "<b>v1:</b> ".$info['v1'] . " <br>"; Print "<b>V2:</b> ".$info['V2'] . " <br>";

Link to comment
Share on other sites

I don't know how to retrive the values from the array into post variables.Do you really mean $_POST variables? I don't think you do. Maybe you chose the wrong word.Is mytest.p2 really the name of your table? If so, ok. (I've never had a table name with a dot in it, so it looks weird to me.)If p_id is the name of a field, then $info['P_ID'] won't work. You'll need $info['p_id']Query string values need to be in quotation marks. If $chk is a string, then you'll need them. If it is a number type, then you won't (that is, don't write '$chk' as I have it below). Query strings should not end with a semicolon the way they do when you use SQL directly. Try this:mysql_query("SELECT * FROM mytest.p2 WHERE p_id='$chk'");Some implementations require tick marks around the field name. This might work if the above does not:mysql_query("SELECT * FROM mytest.p2 WHERE `p_id`='$chk'");I am concerned that the next two statements use different cases for the field names. It's fine if the field names really are in different cases, but I don't imagine a designer doing that intentionally:Print "<b>v1:</b> ".$info['v1'] . " <br>"; Print "<b>V2:</b> ".$info['V2'] . " <br>";

Edited by Deirdre's Dad
Link to comment
Share on other sites

echo "<table border=\"1\" align=\"center\">";echo "<tr><th>Quantity</th>";echo "<th>Price</th></tr>";while ( $counter <= 100 ) {	echo "<tr><td>";	echo $counter;	echo "</td><td>";	echo $brush_price * $counter;	echo "</td></tr>";	$counter = $counter + 10;}echo "</table>";

that should give you an idea about how to do it.

Link to comment
Share on other sites

Whoa. Are we working on the same project, Jim? I've been confused all week . . .
The code I posted is working. I just want to know how to retrive the values in the array (values of P_ID, V1 and V2) and show them at a html form and let user to modify them.Or, may be I should go to another way to do that?Thank you,
Link to comment
Share on other sites

If your query is working, then this part of the code should do what you expect:// Print out the contents of the entry Print "<b>P_ID:</b> ".$info['P_ID'] . " <br>"; Print "<b>v1:</b> ".$info['v1'] . " <br>"; Print "<b>V2:</b> ".$info['V2'] . " <br>";What's happening instead?

Link to comment
Share on other sites

OH! You want them in a form.echo "<input type='text' name = 'P_ID' value='{$info['P_ID']}'><br>"; echo "<input type='text' name = 'v1' value='{$info['v1']}'><br>"; echo "<input type='text' name = 'V2' value='{$info['V2']}'><br>"; Can you do the rest of the form yourself?

Edited by Deirdre's Dad
Link to comment
Share on other sites

one more question.I would like to use the code to get a value for radio group. It seems having prob. How to change it?thanks,code:How many?     <input type="radio" <?php if ($info['V4'] == "1") {echo "enabled";} ?> value="1" name="v4">   1  <input type="radio" <?php if ($info['V4'] == "2") {echo "enabled";} ?> value="2" name="v4">   2  <input type="radio" <?php if ($info['V4'] == "3") {echo "enabled";} ?> value="3" name="v4">   3 </p>

Link to comment
Share on other sites

1. There is no enabled property. Enabled is the default. There is a disabled property you could assign the others.2. You can't just put the word "disabled" in the middle of your tag. Something like this will be needed:echo "disabled='disabled'";

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...