3

I'm trying to get a value that is associated (through mysql data-base row) to a unique Id through an option form:

<form>
<td>
<select name='rolo'>
   <option value='$id'>$item</option>
</td>
<td>
   $value
</td>
</select>
</form>

So, when I choose an option, I get the correspondent $value associated with it in the next .

What I have tried so far:

$query = "SELECT * FROM rolostock WHERE id='$id' ";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo $row['value'];
}

I am not a php expertise, and I thought this would do it? Thanks in advance!

EDIT:

What i'm trying is to (html form) SELECT > OPTION $id > (php) get $value of $id in the next (html) TD . :\

5
  • Some of your html is alil strange, what exactly is the error that you are getting? Commented Nov 21, 2012 at 3:50
  • 1
    sorry if not being very explicit :\ the error im getting is Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in Commented Nov 21, 2012 at 3:55
  • try to see what error is.echo mysql_error(); put after your query Commented Nov 21, 2012 at 3:59
  • Its not geting the value of id thats why query is not executed Commented Nov 21, 2012 at 4:01
  • That you all, ye the id was the problem! Beh so close and so far :\ Commented Nov 21, 2012 at 4:05

1 Answer 1

6

Try with this:

$query = "SELECT * FROM `rolostock` WHERE id = '$id';";
$result = mysql_query($query);
if (!$result) exit("The query did not succeded");
else {
    while ($row = mysql_fetch_array($result)) {
        echo $row['value'];
    }
}

If running this prints The query did not succeded then you have an error in your query. Try running it via PhpMyAdmin.

Also use:

<option value='<?php echo $id;?>'><?=php echo $item;?></option>

instead of:

<option value='$id'>$item</option>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.