我一直试图通过.$result['name'].
输出结果,但没有用。
以下是我的代码:
<?php
mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
mysql_select_db("amityada_admission") or die(mysql_error());
?>
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<title>Search Inquiry</title>
</head>
<body>
<div class="container">
<h3>Search Result</h3>
<p>
<?php
$query = $_POST['query'];
$min_length = 5;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM student_admission
WHERE (`mobile` LIKE '%".$query."%') OR (`name` LIKE '%".$query."%') OR (`university` LIKE '%".$query."%')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
echo "<table>";
while ($results = mysql_fetch_assoc($raw_results)) {
echo <<<EOD
<h2 style="background-color:#009; color:#FFF; padding: 10px; alignment-adjust:baseline">Student Admission Form</h2>
<div align="center">
<table width="90%" border="1">
<tr>
<th colspan="4" scope="row"><h3 align="left" style="background-color:#F39; color:#FFF; padding: 10px">Admission Form for | $name | Session 2015-2016</h3></th>
<td colspan="2" rowspan="7">$file</td>
</tr>
<tr>
<th colspan="4" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif" ><div align="left"><strong>Personal Details</strong></div></th>
</tr>
<tr>
<th width="29%" scope="row"><div align="left">Student Name</div></th>
<td width="9%"><div align="left">$name</div></td>
<td width="25%"><div align="left"><strong>Fathers Name</strong></div></td>
<td width="13%"><div align="left">$fname</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Mothers Name</div></th>
<td><div align="left">$mname</div></td>
<td><div align="left"><strong>Date of Birth</strong></div></td>
<td><div align="left">$dob</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Mobile Number</div></th>
<td><div align="left">$mobile</div></td>
<td><div align="left"><strong>Email ID</strong></div></td>
<td><div align="left">$email</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Gender</div></th>
<td><div align="left">$gender</div></td>
<td><div align="left"><strong>Marital Status</strong></div></td>
<td><div align="left">$maritalstatus</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Employed</div></th>
<td><div align="left">$employed</div></td>
<td><div align="left"><strong>Course Type</strong></div></td>
<td><div align="left">$coursetype</div></td>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif"><div align="left">Educational Details</div></th>
</tr>
<tr>
<th scope="row"><div align="left"><strong>Current Education</strong></div></th>
<td><div align="left">$current_educational_details</div></td>
<td><div align="left"><strong>Course Applied For</strong></div></td>
<td><div align="left">$course</div></td>
<td width="11%"><div align="left"><strong>Specialization</strong></div></td>
<td width="13%"><div align="left">$specialization</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Lateral Entry</div></th>
<td><div align="left">$lateralentry</div></td>
<td><div align="left"><strong>Lateral Entry In</strong></div></td>
<td><div align="left">$lateral_entry_in</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif"><div align="left">Correspondence Address</div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Address</div></th>
<td colspan="5"><div align="left">$corr_add</div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Country</div></th>
<td><div align="left">$countryId</div></td>
<td><div align="left"><strong>State</strong></div></td>
<td><div align="left">$stateId</div></td>
<td><div align="left"><strong>City</strong></div></td>
<td><div align="left">$cityId</div></td>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif"><div align="left">Payment Option</div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Payment Mode</div></th>
<td><div align="left">$payment_method</div></td>
<td><div align="left"><strong>Payment Option</strong></div></td>
<td><div align="left">$feesinfull</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Complete Fees</div></th>
<td><div align="left">$coursefees</div></td>
<td><div align="left"><strong>Full Fees Paid</strong></div></td>
<td><div align="left">$fullfees</div></td>
<td><div align="left"><strong>Discount</strong></div></td>
<td><div align="left">$discount</div></td>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif"><div align="left">Installment Options</div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 1</div></th>
<td><div align="left">$installment1</div></td>
<td><div align="left"><strong>Paid On</strong></div></td>
<td><div align="left">$ins1</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Installment 2</div></th>
<td><div align="left">$installment2</div></td>
<td><div align="left"><strong>Paid On</strong></div></td>
<td><div align="left">$ins2</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Installment 3</div></th>
<td><div align="left">$installment3</div></td>
<td><div align="left"><strong>Paid On</strong></div></td>
<td><div align="left">$ins3</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Installment 4</div></th>
<td><div align="left">$installment4</div></td>
<td><div align="left"><strong>Paid On</strong></div></td>
<td><div align="left">$ins4</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Installment 5</div></th>
<th scope="row"><div align="left">$installment5</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins5</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 6</div></th>
<th scope="row"><div align="left">$installment6</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins6</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 7</div></th>
<th scope="row"><div align="left">$installment7</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins7</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 8</div></th>
<th scope="row"><div align="left">$installment8</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins8</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 9</div></th>
<th scope="row"><div align="left">$installment9</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins9</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 10</div></th>
<th scope="row"><div align="left">$installment10</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$installment10</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th colspan="6" scope="row"><div align="left">
<p>This is Just an Admission Form filled for the purpose of Applying for the University. This is not an University Admission Form and Should only be traeted for Pune Institute Admission Purpose. Any Changes or Request for Updation of Student Details of Change of University has to be Submitted to the IT Admin through mail on <strong>info@puneinstitute.org</strong></p>
</div></th>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:grey; color:white; padding: 7px">© <a href="#">Ankit</a> 2003-2015 | Powered By © <a href="#">Diaphram</a> 2011-2015 </th>
</tr>
</table>
</div>
EOD;
}
echo "</table>";
}
else{
echo "No Results Found";
}
}
else{
echo "Oops !! You Pressed Refresh Button or Minimum Input Value is $min_length";
}
?>
</table>
</body>
</html>
答案 0 :(得分:2)
您将行数据设置为$results
,但从不使用它。
(在这里:while ($results = mysql_fetch_assoc($raw_results)) {
)
在上述代码之后使用extract($results)
将列名用作代码中的变量,或将变量用作$results['name']
。
答案 1 :(得分:1)
尝试使用mysql_fetch_array()
代替mysql_fetch_assoc()
,然后使用以下列的索引编号打印结果
$result[0]
例如,如果name
列是表格中的第1列,则使用$result[0]
,如果是第2列,则使用$result[1]
试试这个并告诉我
答案 2 :(得分:0)
你应该:
$name
此处应为$results['name']
$file
此处应为$results['file']
$fname
此处应为$results['fname']
$mname
此处应为$results['mname']
$mobile
此处应为$results['mobile']
依此类推你桌上的其他数据。
并且还会删除您的代码中的</table>
个原因之一。