Okay, so I am trying to display text when something goes wrong. I want to have it so that if the page number is too high (above 3 in my case) it will display an error. Disregard the accessing mySQL database.
<?php
function get($name)
{
return isset($_REQUEST[$name]) ? $_REQUEST[$name] : '';
}
function is_valid_index($index,$array)
{
return $index >= 0 && $index < count($array);
}
?>
<?php
//Variables
$dbhost = "localhost";
$dbuser = "admin";
$dbpass = "pass";
$dberror = "You have failed to connect to the database!";
$conn = mysqli_connect($dbhost,$dbuser,$dbpass) or die ($dberror);
$select_db = mysqli_select_db($conn, "database") or die ("Couldn't Select Database");
?>
<form>
<?php
$page = array('Select List','Users', 'Groups');
echo '<select name="Lists">';
for($i = 0;
$i < count($page);
$i++)
{
echo '<option value="'.($i + 1).'">'.$page[$i].'</option>';
}
echo '</select>';
?>
<input type='submit'>
</form>
<?php
if(get('page'))
{
$page_id = get('page');
if(is_valid_index($page_id-1,$page))
{
echo "You have selected".$page[$page_id-1];
}
else
{
echo '<span style="color:red">Invalid Page</span>';
}
}
?>
Got the tutorial from this video: https://www.youtube.com/watch?v=SaRh2HauIXY
答案 0 :(得分:2)
更改此
<div class="wrapper">
<div class="box-content">
<div class="fixed-element">
</div>
</div>
</div>
<style type="text/css">
.wrapper {
transform: translateX(50px);
background: pink;
}
.box-content {
height: 1000px;
background: green;
}
.fixed-element{
position: fixed;
top: 0;
left: 0;
width: 50px;
height: 50px;
background: blue;
}
</style>
进入这个
echo '<select name="Lists">';
这样,函数echo '<select name="page">';
将返回get('page')
,true
块将会执行,您的if
调用也会执行