1

So I made a query like this

    global $connection;
    $query = "SELECT * 
    FROM streams ";
    $streams_set = mysql_query($query, $connection);
    confirm_query($streams_set);

in my DB there are filds

ID, UID, SID, TIME (all INT type exept time)

So I am triing to print query relult into form

          <form>

  <select class="multiselect" multiple="multiple" name="SIDs">

           <?php        

    global $connection;
    $query = "SELECT * 
    FROM streams ";
    $streams_set = mysql_query($query, $connection);
    confirm_query($streams_set);


            $streams_count = mysql_num_rows($streams_set);
            for ($count=1; $count <= $streams_count; $count++) {
        echo "<option value=\"{$count}\"";
        echo ">{$count}</option>";
    } 
          ?>
          </select>
          <br/>
          <input type="submit" value="Submit Form"/>
            </form>

How to print out as "option" "values" SID's from my sql query?

4 Answers 4

2
while ($row = mysql_fetch_array($streams_set)) {
 echo '<option value="'.$row['SID'].'">'.$row['SID'].'</option>';
}
Sign up to request clarification or add additional context in comments.

Comments

2
<form>
  <select class="multiselect" multiple="multiple" name="SIDs">
  <?php      

    global $connection;
    $query = "SELECT * 
    FROM streams ";
    $queryResult = mysql_query($query, $connection);
    while($row = mysql_fetch_assoc($queryResult)) {          
        echo '<option value="'. $row["id"] .'">'. $row["title"] .'</option>';
    } 
 ?>
 </select>
 <br/>
 <input type="submit" value="Submit Form"/>
</form>

You just have to replace the id and title index with your appropriate fields.

Comments

2

or mysql_fetch_object()

http://php.net/manual/en/function.mysql-fetch-object.php

Comments

1

Ole Jak, take a look at PHP's mysql_fetch_array http://php.net/manual/en/function.mysql-fetch-array.php, that's what you'll want to do in a while loop :-)

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.