ребята, я новичок во всей работе php, и я знаком с терминологией и всеми функциями и т. Д. Я считаю, что то, что я прошу здесь, очень просто сделать, я просто не смог его найти.Эхо определенные фрагменты текста, только если значение заполнено
В приведенном ниже коде вы заметите, что не все поля отображаются при каждом изменении выпадающего меню TYPE, и, конечно же, они этого не делают, вот и все. Я имею в виду, что я организовал для каждого ТИПА собственные поля. Дело в том, как я могу адаптировать для HTML-кода html, чтобы показывать ТОЛЬКО «метки» (давайте назовем то, что я делаю полужирным, например:. »< br />Предварительный просмотр задачи:". $ Row [ 'taskpre']) и все аналогичные элементы, которые), я имею в виду фрагменты HTML в то время ($ row = mysqli_fetch_array ($ result)) для полей, которые были заполнены? Я имею в виду, что я не хочу, чтобы в RESULT были «метки» полей, значения которых есть.
Вот код:
<?php
$con=mysqli_connect("localhost","root","","activitytest1");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST['submit'])) {
$stmt = mysqli_prepare($con, "INSERT INTO activitytest1 (type, author, taskpre, taskdescription, outcome, semipre, semiwhile, exercisedescription, practicepre, practiceinstructions, leadin, gamepre, gameinstructions, videopre, videowhile, videopost, songpre, songwhile, songpost, mimioinstructions, otherinstructions, path, books, grouping, time)
VALUES
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
mysqli_stmt_bind_param($stmt, 'sssssssssssssssssssssssss', $type, $author, $taskpre, $taskdescription, $outcome, $semipre, $semiwhile, $exercisedescription, $practicepre, $practiceinstructions, $leadin, $gamepre, $gameinstructions, $videopre, $videowhile, $videopost, $songpre, $songwhile, $songpost, $mimioinstructions, $otherinstructions, $path, $books, $grouping, $time);
$type = $_POST['type'];
$author = $_POST['author'];
$taskpre = $_POST['taskpre'];
$taskdescription = $_POST['taskdescription'];
$outcome = $_POST['outcome'];
$semipre = $_POST['semipre'];
$semiwhile = $_POST['semiwhile'];
$exercisedescription = $_POST['exercisedescription'];
$practicepre = $_POST['practicepre'];
$practiceinstructions = $_POST['practiceinstructions'];
$leadin = $_POST['leadin'];
$gamepre = $_POST['gamepre'];
$gameinstructions = $_POST['gameinstructions'];
$videopre = $_POST['videopre'];
$videowhile = $_POST['videowhile'];
$videopost = $_POST['videopost'];
$songpre = $_POST['songpre'];
$songwhile = $_POST['songwhile'];
$songpost = $_POST['songpost'];
$mimioinstructions = $_POST['mimioinstructions'];
$otherinstructions = $_POST['otherinstructions'];
$path = $_POST['path'];
$books = $_POST['books'];
$grouping = $_POST['grouping'];
$time = $_POST['time'];
$submit = $_POST['submit'];
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
$result = mysqli_query($con,"SELECT * FROM activitytest1");
while($row = mysqli_fetch_array($result))
{
echo "<table width='909' border='1' align='center' cellpadding='5' cellspacing='0'>
<tr>
<th width='125' scope='col'>Type</th>
<th width='680' scope='col'>Description</th>
<th width='120' scope='col'>Author</th>
</tr></table>
<br/>
<table width='909' border='1' align='center' cellpadding='5' cellspacing='0'>
<tr>
<td width='125'>" . $row['type'] . "</th>
<td width='680'>Time:" . $row['time'] . " min. <br><br>" . $row['books'] . "<br/>Grouping: " . $row['grouping'] . "<br/>Preview the Task:" . $row['taskpre'] . "<br/>Instructions:" . $row['taskdescription'] . "<br/>Outcome:" . $row['outcome'] . "<br/>Preview the semi-task:" . $row['semipre'] . "<br/>Instructions:" . $row['semiwhile'] . "<br/>Exercise Instructions: " . $row['exercisedescription'] . "<br/> Preview the Practice:" . $row['practicepre'] . "<br/>Practice Instructions:" . $row['practiceinstructions'] . "<br/>Lead-in:" . $row['leadin'] . "<br/>Preview the Game:" . $row['gamepre'] . "<br/>Game Instructions:" . $row['gameinstructions'] . "<br/>Song PRE:" . $row['songpre'] . "<br/>Song WHILE:" . $row['songwhile'] . "<br/>Song POST:" . $row['songpost'] . "<br/>Video PRE:" . $row['videopre'] . "<br/>Video WHILE:" . $row['videowhile'] . "<br/>Video POST:" . $row['videopost'] . "<br/>Mimio Instructions:" . $row['mimioinstructions'] . "<br/>Instructions:" . $row['otherinstructions'] . "<br/><br>Link/Path" . $row['path'] . "<br/></th>
<td width='120'>" . $row['author'] . "</th>
</tr></table> <br/> <hr size='1'/>";
}
mysqli_close($con);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test 1</title>
</head>
<body>
<br>
<table width="909" border="1" align="center" cellpadding="5" cellspacing="0">
<tr>
<th width="125" scope="col">Type</th>
<th width="680" scope="col">Description</th>
<th width="120" scope="col">Author</th>
</tr></table>
<br>
<form action="index.php" method="POST">
<table width="909" border="1" align="center" cellpadding="5" cellspacing="0">
<td width="125"><label>
</label>
<select name="type" id="type" onChange="display(this,'Task','Semi-task','Practice','Exercise','Lead-in', 'Game', 'Video','Song','Mimio','Other');">
<option value="Unselected" selected="selected">Choose one:</option>
<option value="Task">Task</option>
<option value="Semi-task">Semi-task</option>
<option value="Practice">Practice</option>
<option value="Exercise">Exercise</option>
<option value="Lead-in">Lead-in</option>
<option value="Game">Game</option>
<option value="Video">Video</option>
<option value="Song">Song</option>
<option value="Mimio">Mimio</option>
<option value="Other">Other</option>
</select></td>
<td width="680"><div id="Task" style="display:none"> Task: <br />
Lead-in/Preview the task: <textarea name="taskpre" cols="70" rows="2"></textarea>
<br />
Instructions: <textarea name="taskdescription" cols="70" rows="2"></textarea>
<br />
Outcome:
<textarea name="outcome" cols="70" rows="2"></textarea>
<br />
</div>
<div id="Semi-task" style="display:none">Semi-task:<br />
Lead-in/Preview the task: <textarea name="semipre" cols="70" rows="2"></textarea>
<br />
Instructions: <textarea name="semiwhile" cols="70" rows="2"></textarea>
<br />
</div>
<div id="Exercise" style="display:none">Exercise:<br />
Instructions/Obs.:
<textarea name="exercisedescription" cols="70" rows="2"></textarea>
</div>
<div id="Practice" style="display:none">
Practice:<br />
Lead-in/Preview the task: <textarea name="practicepre" cols="70" rows="2"></textarea>
<br />
Instructions: <textarea name="practiceinstructions" cols="70" rows="2"></textarea>
<br />
</div>
<div id="Lead-in" style="display:none">
Lead-in:<br>
<textarea name="leadin" cols="70" rows="2"></textarea><br>
</div>
<div id="Game" style="display:none">
Game:<br />
Lead-in:
<textarea name="gamepre" cols="70" rows="2"></textarea>
<br />
Instructions: <textarea name="gameinstructions" cols="70" rows="2"></textarea>
</div>
<div id="Video" style="display:none"> Video: <br />
Pre: <textarea name="videopre" cols="70" rows="2"></textarea>
<br />
While: <textarea name="videowhile" cols="70" rows="2"></textarea>
<br />
Post:
<textarea name="videopost" cols="70" rows="2"></textarea>
</div>
<div id="Song" style="display:none"> Song: <br />
Pre: <textarea name="songpre" cols="70" rows="2"></textarea>
<br />
While: <textarea name="songwhile" cols="70" rows="2"></textarea>
<br />
Post:
<textarea name="songpost" cols="70" rows="2"></textarea>
</div>
<div id="Mimio" style="display:none">Mimio:<br />
Instructions:<br>
<textarea name="mimioinstructions" cols="70" rows="2"></textarea>
</div>
<div id="Other" style="display:none">Other:<br />
Instructions:<br>
<textarea name="otherinstructions" cols="70" rows="2"></textarea><br />
</div> </td>
<td width="120"><input name="author" type="text" size="12" maxlength="25" /></td>
</tr>
<tr>
<td colspan="3">
<select name="books" id="Books">
<option value="books open" selected="selected">books open</option>
<option value="books closed">books closed</option>
</select>
<br />
<select name="grouping">
<option value="individual" selected="selected">individual</option>
<option value="pairs">pairs</option>
<option value="trios">trios</option>
<option value="groups of 3 to 4 students">groups of 3 to 4 students</option>
<option value="groups of 5 students">groups of 5 students</option>
<option value="divide the class into 2 groups">divide the class into 2 groups</option>
<option value="divide the class into 3 groups">divide the class into 3 groups</option>
<option value="divide the class into 4 groups">divide the class into 4 groups</option>
</select>
<br />
about
<input name="time" type="text" id="Time" size="1" />
min </td>
</tr>
<tr>
<td colspan="3">Link/Path: <input name="path" type="text" id="Path" size="40" /></td>
</tr>
<tr>
<td colspan="3"><input type="submit" name="submit" value="Post!" /></td>
</tr>
</table>
</form>
</body>
</html>
P.S .: Страница находится выпадающее меню, что, имея каждый из его вариантов, выбранных, измените поля, которые показывают на этой странице. Я имею в виду, когда я выбираю «Видео» в выпадающем меню, он показывает поля - это текстовые поля: «видео», «видео» и «видеопост». Однако, если я выбираю «Упражнение», единственным полем, которое он показывает, является «упражнение».
Итак, я хочу, чтобы этот фрагмент HTML «"<br/>Preview the Task:"
» показывает только значение. $ row ['taskpre'] заполняется и т. д. для всех эфирных. В противном случае, я не хочу, чтобы "<br/>Preview the Task:"
перекликался с остальной частью кода, хорошо?
Это ECHO, что я получаю, когда я представляю «задача» (значение задач является: «taskpre», «taskdescription» и «результат»):
http://i296.photobucket.com/albums/mm177/JuniorCodi/php_zps5ca6aa90.png
На картинке выше Я отмечен чеком, что хочу, чтобы эхо и что в красном, - это то, что я не хочу эха, когда я выбираю TASK.
Я новичок в этом, и я не знаю, будет ли работать оператор IF в инструкции WHILE (по крайней мере, когда я пытался появляться ошибки). Может ли кто-нибудь помочь мне, предоставив мне образец того, как этот код будет?
* "Ребята, я новичок в целом PHP вещи, и я словцо знаком с терминологией и все функции и такие »* - И вы сразу же прыгаете« в глубоком конце ». Вы должны научиться плавать, прежде чем сможете окунуться в плавательный бассейн олимпийского размера. По крайней мере, * «собака весла». * –
* «На рисунке выше я отмечен чек ...» * - Как у меня есть учетная запись PhotoBucket, поэтому я могу просмотреть этот файл. ** NO-GO **. –