File code: (updated version)
Copy the codeThe code is as follows:
[<a href="">Continue to add</a>]
<?php
//Here is PHP code
$sql = "SELECT * FROM `addr_list`";// SQL statements that need to be executed (here is the browsing function)
require(’’);
?>
<!--- Here HTML code, create a table--->
<table width="100%" border="1">
<tr>
<th width="13%" bgcolor="#CCCCCC" scope="col">name</th>
<th width="13%" bgcolor="#CCCCCC" scope="col">Gender</th>
<th width="13%" bgcolor="#CCCCCC" scope="col">Mobile</th>
<th width="13%" bgcolor="#CCCCCC" scope="col">Email</th>
<th width="29%" bgcolor="#CCCCCC" scope="col">Address</th>
<th width="19%" bgcolor="#CCCCCC" scope="col">Operation</th>
</tr>
<?php
//Here is PHP code
//Judge gender
while($row = mysql_fetch_row($result)) //The loop starts
{
if($row[2]==0)
{
$sex= ’Ms.’;
}
else
{
$sex= ’Mr.’;
}
?>
<!---The looped HTML table has PHP code--->
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $sex; ?></td>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[4]; ?></td>
<td><?php echo $row[5]; ?></td>
<td><div align="center">
[<a href="?id=<?php echo $row[0]; ?>">Edit</a>]
[<a href="?id=<?php echo $row[0]; ?>">Delete</a>]
</div></td>
</tr>
<?php
}
?>
</table>
Note: Our two links [edit] and [delete] point to the and pages. These two pages have not been made yet. Let’s first figure out why we should write it like this. We can see that it has the form:?id=xxx, so what is xxx? As mentioned earlier, you must not forget it. $row[0] represents the call id. We wrote it into the link using PHP statements, so it looks like that, haha. After conversion, it should display an address similar to ?id=1 in the address bar. This is a way to pass values. If you want to study it, haha, google, I won't talk about it here. OK, then let's see if they have passed the values to and pages, so let's write these two pages to test first. Remember to be a test, so it's not the full version, haha.
File code: (incomplete)
<?php
echo $id;
?>
File code: (incomplete)
<?php
echo $id;
?>
Note: The two twins look exactly the same, haha. OK, you can test it, run, click [Edit] or [Delete] to see if the value of $id can be displayed or transformed. If it succeeds, we can continue.
OK, now let’s write the Gang formally. If you have figured out how to write the Gang before, then these two will not be a problem, they are similar, so don’t be too nervous. Let's write it first.
File code: (full version)
<?php
$sql = "SELECT * FROM `addr_list`
WHERE `id`=’$id’";
// Pay attention to ID, this statement is somewhat different from
require(’’);
$row = mysql_fetch_row($result); //Save the result set of SQL execution statements as an array (queuing)
?>
<!----We just need to add the form button to the PHP code. Only the gender part needs special treatment--->
<form name="form1" method="post" action="">
<p>Name: <input name="name" type="text" value="<?php echo $row[1]; ?>" //</p>
<p>
<?php
//Specially deal with gender. If it is 0, select the lady, otherwise select the teacher, checked="checked" means selecting it.
if($row[2]==0)
{
echo ’Gender: <input type="radio" name="sex" value="0" checked="checked" />Ms.
<input type="radio" name="sex" value="1" //Sir’;
}
else
{
echo ’Gender: <input type="radio" name="sex" value="0" /Ms.
<input type="radio" name="sex" value="1" checked="checked" // Mr.’;
}
?>
</p>
<p>Mobile phone: <input name="mobi" type="text" value="<?php echo $row[3]; ?>" //</p>
<p>Email: <input name="email" type="text" value="<?php echo $row[4]; ?>" //</p>
<p>Address: <input name="addr" type="text" value="<?php echo $row[5]; ?>" //</p>
<p>
<input type="submit" name="Submit" value="Add" />
<input type="reset" name="Submit2" value="rewrite" />
</p>
</form>
Note: Actually, it’s just copying it and modify it. Haha, what you need to pay attention to here is the $sql statement. There is a SQL conditional sentence used to identify the ID and the gender processing part. checked="checked" means that the radio button has been selected. If you know these, this part will be topped. We also need to make a page to send and process modified data, and its function is almost the same. Haha, let’s hurry up and finish it soon!
File code:
<?php
// SQL statements that need to be executed (here is the function of modifying data)
$sql = "UPDATE `addr_list` SET
`name` = ’$name’,
`sex` = ’$sex’,
`mobi` = ’$mobi’,
`email` = ’$email’,
`addr` = ’$addr’
WHERE `addr_list`.`id` =12 ";
//Calling the file and performing database operations �
require(’’);
//Show the operation prompt, please note that $result is also included
if($result)
{
echo ’Congratulations, the modification was successful! <p>’;
}
?>
[<a href="">View address book</a>] [<a href="">Continue to add</a>]
Note: What you need to pay attention to here is the SQL statement of $sql. I have indented it here to facilitate everyone to see clearly. There is no need to write it like this when you write it yourself, haha. It's almost the same as everyone else, so there's no need to talk about it, let's test it. In the end, victory is right in front of you! hehe.
File code: (full version)
<?php
// SQL statements that need to be executed (here is the function of deleting data)
$sql = "DELETE FROM `addr_list` WHERE `id`=’$id’";
//Calling the file and performing database operations �
require(’’);
//Show the operation prompt, please note that $result is also included
if($result)
{
echo ’Congratulations, the deletion was successful! <p>’;
}
?>
[<a href="">View address book</a>] [<a href="">Continue to add</a>]
Note: This is also made in the same mold. Haha, it's very simple. The SQL deletion statement of $sql is a bit different. No matter what, it is recommended that you learn SQL syntax, which is very useful because it is widely used.
Okay, here we will all end this article. I won’t upload the source code for everyone to download it, so as not to let some people like to be lazy like me. Haha, this trick is quite amazing, forcing people who want to learn to read it, which is beneficial.
So, let's end it with the old closing ceremony, haha:
Important explanation, you must read it. This is just the simplest and most basic thing, just for learning and cannot be put into use. Otherwise, don’t blame me for any problems, haha. If you want to use it yourself, you need to make a lot of improvements, such as adding some verification functions, optimizing code, etc., or the same sentence: If you have any shortcomings, please correct me and make everyone laugh.
The most fundamental purpose of writing this article: I hope to give some meager help to those in need. I also teach myself by myself and know the hard work. So although I am very good at it, I also need to know how to share it. I also hope that everyone can learn together and make progress together.
I know that this kind of article is as numerous as a cow, and no matter how bad it is, it is original, so I applied for it by the way, so... Everyone is merciless, I know that I am wrong, haha.
Previous page123Read the full text