<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form action="2.php" method="post">
<table width="400" border="0">
    <tr>
        <td>Ders sayisi :</td>
        <td><input type="text" name="sayi" /></td>
    </tr>
    <tr>
        <td><input type="submit" name="gonder" value="Gonder" /></td>

    </tr>
</table>
</form>
<?php
    if(isset($_POST['gonder']))
    {

        for($i=1;$i<=$_POST['sayi'];$i++)
        {
            echo "$i.ders"." "."<input type='text' **name='e$i'** />"."   -   "." 
            <select name='dersler'><option **value='a1'**>A1</option>
             <option **value='a2'**>A2</option><option **value='b1'**>B1</option>
             <option **value='b2'**>B2</option><option **value='c'**>C</option></select>"."<br>";
        }
    }
    //......
?>
</body>

Bold Text Here
How can I use html elements in echo command with php ? for example I want to calculate the average of lessons in these ones by using name tags.

Recommended Answers

All 4 Replies

You can write out HTML tags in PHP as you would normally. The only thing you need to be aware of is by using speech marks you either need to escape them or use quotation marks instead. What I'm trying to say is you can't use the same set twice as you'll end up ending your echo before you meant to. I hope I explained that well?

Example of how not to do it:

echo("<div id = "DivisionTag" > Contents </div>");

Example of how to do it:

echo("<div id = 'DivisionTag' > Contents </div>");

Member Avatar for diafol

You're questions doesn't make sense. Average of what?

name='e$i'

Is fine, what's the problem?

However,

<select name='dersler'>

needs to be:

<select name='dersler[]'>

But the whole page makes very little sense. You're creating select dropdowns OUTSIDE the form, or do not have form tags around the dropdowns. You have no submit button to go with them. I can't see any javascript, so I'm assuming this is a mistake?

I just tried to do that when I enter a number in textbox it gives to some textboxes and then how can I use created these textboxes for another processing ? Thank you for answers.

Member Avatar for diafol

I just tried to do that when I enter a number in textbox it gives to some textboxes and then how can I use created these textboxes for another processing ? Thank you for answers.

Sorry, that doesn't make any sense to me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.