Home > Blockchain >  how do i get the data in two columns inside a database table using php
how do i get the data in two columns inside a database table using php

Time:10-17

I am trying to get data from the course table which has a primary key -course_id. the table has department and code colunm. i want to loop through all the courses and print with radio buttons, the department with the department code.

   $query = "select *
          from courses";

        $result = $dbc ->query($query);
        
        while ($row = $result ->fetch_assoc()) {
        print"<input type='radio' name='course' value='$row[course_id]'><br/>";

it loops through the courses but doesnt print out anythin next to the radio button

CodePudding user response:

1. You can use <label> to display the text title and value of radio for your dept_code

Like this

<form action="/action_page.php">
  <input type="radio" id="html" name="fav_language" value="HTML">
  <label for="html">HTML</label><br>
  <input type="radio" id="css" name="fav_language" value="CSS">
  <label for="css">CSS</label><br>
  <input type="radio" id="javascript" name="fav_language" value="JavaScript">
  <label for="javascript">JavaScript</label><br><br>
  <input type="submit" value="Submit">
</form>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Note: All radio buttons will have the same name.

2. I don't see your } close of the while

CodePudding user response:

It sounds like it should just be something like

print"<label><input type='radio' name='course' value='".$row["course_id"]."'>".$row["department"]."</label><br/>";

Assuming "department" is the name of your database column then this would print the department name next to each radio button.

  • Related