cbaker
cbaker

Reputation: 21

Adding css to a form

I am trying to add CSS to my form but not sure how to do this. The form is created in php and MySQL, in browser it looks like: http://gyazo.com/5d099ead9bd6ea83859a5114b2438748

I need to allign the text and drop downs so they are in the equal throughout and add some spacing. Anyone help with CSS for this?

html currently:

  <div class="wrap">
              <img src="/images/logo.png" alt="Highdown logo" />
              <h1>Entry form</h1> 
            </div>

css currently:

.wrap {
                position: relative;
                }

The form is produced with this:

if ($event_result = $con->query("SELECT Event.Name FROM event")) {  
                echo "<form method =\"POST\" action=\"save.php\"> ";
                            while ($row = $event_result->fetch_assoc()) {               
                            echo $row['Name']. ' ';

                                if ($student_result = $con->query("SELECT Student.Form, Teacher.Form, Student.Forename, Student.Surname, Student_ID " .
                                    "FROM Student, Teacher " .
                                        "WHERE Student.Form = Teacher.Form AND Teacher.Username = '" . $_SESSION['Username'] . "'")) {

                                    if ($student_result->num_rows) {                                                                                
                                                echo "<select name ='". $row['Name']."'>";  
                                                    while ($row1 = $student_result->fetch_assoc()) {
                                                    echo '<option value="" style="display:none;"></option>';
                                                    echo "<option value ='" . $row1['Student_ID'] . "'>" . $row1['Forename'] . ' ' . $row1['Surname'] . "</option>";
                                                }
                                                echo "</select> <br />";                    
                                    }                                                                   
                                }
                            }   
                        echo '<input type="submit" value ="Submit">';
                        echo '<input type="reset" value ="Reset">';

                        echo '<input type="button" value = "Add student" onclick="location.href=\'http://localhost/sportsday/addstudent.php\'">';
                        echo '<input type="button" value = "Delete student">';
                echo "</form>"; 
            }

Upvotes: 0

Views: 102

Answers (4)

MONTS_MIND_Hacker
MONTS_MIND_Hacker

Reputation: 1727

First , check your database... May be there is Another Issue not related to Tabular Output.

So , First remove Table Tag..and check whether its working ?

Then try in HTML TABLE TAG

Otherwise give me sample database .sql File and complete PHP code in google drive or on shared drive.

So that I can check and identify where is problem ?

Upvotes: 0

Yash Thakur
Yash Thakur

Reputation: 1201

This should work i did not try as i dont have the database

        //Query to display all events                                                  
                if ($event_result = $con->query("SELECT Event.Name FROM event")) {                     
                        echo "<form method =\"POST\" action=\"save.php\"> ";
                                echo '<table>';
                                        echo '<tr>';
                                        echo '<td>';
                                                while ($row = $event_result->fetch_assoc()) {                          

                                                        echo $row['Name']. ' ';
                                        echo '</td>';          

                                                if ($student_result = $con->query("SELECT Student.Form, Teacher.Form, Student.Forename, Student.Surname, Student_ID " .
                                                        "FROM Student, Teacher " .
                                                                "WHERE Student.Form = Teacher.Form AND Teacher.Username = '" . $_SESSION['Username'] . "'")) {


                                                        if ($student_result->num_rows) {                                                                                                                                                                                                                                       

                                                                echo '<td>';
                                                                echo "<select name ='". $row['Name']."'>";     

                                                                        while ($row1 = $student_result->fetch_assoc()) {


                                                                        echo "<option value ='" . $row1['Student_ID'] . "'>" . $row1['Forename'] . ' ' . $row1['Surname'] . "</option>";       

                                                                }              

                                                                echo "</select> <br />";
                                                                echo '</td>';          
                                                                echo '</tr>';                                                                          
                                                        }                                                                                                                                      
                                                }
                                        }
                                        echo '</table>';                                               
                                        echo '<input type="submit" value ="Submit">';
                                        echo '<input type="reset" value ="Reset">';

                                        echo '<input type="button" value = "Add student" onclick="location.href=\'http://localhost/sportsday/addstudent.php\'">';
                                        echo '<input type="button" value = "Delete student">';                                         
                        echo "</form>";

                        }





?>

Upvotes: 1

Aditya Joshi
Aditya Joshi

Reputation: 1

you can directly write in css

form {
  ⋮ declare css
}

or give name to form

form[name="value"]{
    ⋮ declare css
}

or add any class or id on form

#formid{
    ⋮ declare css
}

.formclass{
       ⋮ declare css
} 

Upvotes: 0

Yash Thakur
Yash Thakur

Reputation: 1201

Use

<form>
    <table>
      <tr> //1st Table row
        <td></td> //Table column data
        <td></td> //table column data
      </tr> //1st row ends

      <tr> // 2nd Table row
        <td></td> //Table column data
        <td></td> //table column data
      </tr> //2nd row ends
    </table>
</form>

This will give you a better layout of the form.

Upvotes: 2

Related Questions