having trouble in mysql if statement - php

I just want to simplify what I am doing before, having multiple php files for all data to be listed.
Here is my html form:
<table border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D3D3D3">
<tr>
<form name="formcheck" method="post" action="list.php" onsubmit="return formCheck(this);">
<td>
<table border="0" cellpadding="3" cellspacing="1" bgcolor="">
<tr>
<td colspan="16" height="25" style="background:#5C915C; color:white; border:white 1px solid; text-align: left"><strong><font size="3">List Students</td>
</tr>
<tr>
<td width="30" height="35"><font size="3">*List:</td>
<td width="30"><input name="specific" type="text" id="specific" maxlength="25" value="">
</td>
<td><font size="3">*By:</td>
<td>
<select name="general" id="general">
<font size="3">
<option>Year</option>
<option>Address</option>
</select></td></td>
</tr>
<tr>
<td width="10"><input align="right" type="submit" name="Submit" value="Submit" > </td>
</tr>
</form>
</table>
And here's the form action:
<?php
$con = mysql_connect("localhost","root","nitoryolai123$%^");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("school", $con);
$gyear= $_POST['general'];
if ("YEAR"==$_POST['general']) {
$result = mysql_query("SELECT * FROM student WHERE YEAR='{$_POST["specific"]}'");
echo "<table border='1'>
<tr>
<th>IDNO</th>
<th>YEAR</th>
<th>LASTNAME</th>
<th>FIRSTNAME</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['IDNO'] . "</td>";
echo "<td>" . $row['YEAR'] . "</td>";
echo "<td>" . $row['LASTNAME'] . "</td>";
echo "<td>" . $row['FIRSTNAME'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
mysql_close($con);
?>
Please help, how do I equate the YEAR(column in mysql database) and the option box(general).
if ("YEAR"==$_POST['general'])
please correct me if I'm wrong.

<option>Year</option>
you just need to change that to
<option value="YEAR">Year</option>
also definitely have a read of this page : http://en.wikipedia.org/wiki/SQL_injection because otherwise your code is wide open to nasty attacks.
[edit : also pay heed to the comments on your original question, posting your real root username/password on a website isn't a very good idea.]

if ("YEAR"==$_POST['general']) {
$result = mysql_query("SELECT * FROM student WHERE date_format(YEAR, '%Y')='{$_POST["specific"]}'");

Related

How can I do a next or preview button

I neeed some help with the next and preview buttons, i want to make a button show me the next or preview information of my data but I donĀ“t know how, also it have to stay in the same webpage. What i mean is that i have thousands of data and im showing only 10, so the next botton is to refresh and show the next 10 rows of information. Here is my code:
<td><table border="2" cellpadding="0">
<tr>
<th colspan='9'>Ejemplares</th>
<tr>
<td width="150">
Titular
</td>
<td width="150">
Criador
</td>
<td width="125">
Nombre
</td>
<td width="80">
Chip
</td>
<td width="80">
Estado
</td>
<td width="60">
Capa LG
</td>
<td width="50">
Sexo
</td>
<td width="125">
Grado Generacional
</td>
</tr>
<?php
$database="caballos"; //database name
$con = mysqli_connect("127.0.0.1","root" ,"",$database)
or die('Could not connect to database server ');
$query = "SELECT * FROM caballo";
$result = mysqli_query($con,$query);
$nfilas = mysqli_num_rows ($result);
for ($i=0; $i<$nfilas; $i++)
{
$resultado = mysqli_fetch_array ($result);
print ("<TR>\n");
print ("<TD width='150px'>" . $resultado['titular'] . "</TD>\n");
print ("<TD width='150px'>" . $resultado['criador'] . "</TD>\n");
print ("<TD width='125px'>" . $resultado['nombre'] . "</TD>\n");
print ("<TD width='75px'>" . $resultado['chip'] . "</TD>\n");
print ("<TD width='75px'>" . $resultado['estado'] . "</TD>\n");
print ("<TD width='150px'>" . $resultado['capalg'] . "</TD>\n");
print ("<TD width='50px'>" . $resultado['sex'] . "</TD>\n");
print ("<TD width='150px'>" . $resultado['grado_gen'] . "</TD>\n");
print ("</TR>\n");
}
mysqli_close($con);
?>
</tr>
</td>
<tr>
<td colspan="2">
<input type="button" value="INGRESAR" onclick= "self.location.href = 'ing_caballos.php'" /></td>
<td colspan="2">
<input type="button" value="GENEALOGIA" onclick= "self.location.href = 'genealogia.php'" /></td>
<td>
<!--hear goes the next and preview buttons-->
</td>
<td colspan="2">
<input type="button" value="ELIMINAR" onclick= "self.location.href = 'del_caballo.php'" />
</td>
</tr>
</tr>
You are looking for a pagination script , try this tutorial

View SQL table on HTML page(SQL SERVER MANAGEMENT STUDIO)

I am creating a website that will be connected with the database. I have created a database in SQL Server.
I want to connect one table with one html page, so that I can view the table on that page. In this way I will connect all the SQL tables with each html page.
I know I have to use php/javaquery!
Please help me with appropriate codes!
Also I am new to SQL. I am learning!
Please explain the changes that I will have to do in the codes you provide to enable it in my system.
i got these 2 codes:which will work for my requirement?
code1:
$result = mysqli_query($con,"SELECT * FROM Orders");
echo "<table>";
echo "<table border='1'>
<tr>
<th>ID</th>
<th>orderNumber</th>
<th>Price</th>
<th>customerName</th>
<th>salesRep</th>
<th>DatePicker</th>
<th>shipMethod</th>
<th>trackingNumber</th>
<th>Statuscheck</th>
<th>Edit</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['orderNumber'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
echo "<td>" . $row['customerName'] . "</td>";
echo "<td>" . $row['salesRep'] . "</td>";
echo "<td>" . $row['DatePicker'] . "</td>";
echo "<td>" . $row['shipMethod'] . "</td>";
echo "<td>" . $row['trackingNumber'] . "</td>";
echo "<td>" . $row['Statuscheck'] . "</td>";
echo "<td>" . $row['Edit'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
code2:
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
}
$result=mysql_query($sql);
?>
<html>
<head>
<script type="text/javascript" charset="utf-8" src="jquery.js"></script>
</head>
<table id="forum" width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<thead>
<tr>
<th width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<th width="43%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<th width="10%" align="center" bgcolor="#E6E6E6"><strong>Author</strong></td>
<th width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<th width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<th width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>
</thead>
<?php
// Start looping table row
while($rows=mysql_fetch_array($result)){
?>
<tbody>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['threadtype']; ?></td>
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>">
<? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['email']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
</tr>
</tbody>
<?php
// Exit looping and close connection
}
mysql_close();
?>
<tfoot>
<tr>
<td colspan="6" align="right" bgcolor="#E6E6E6"><strong>Create New Topic</strong> td>
</tr>
</tfoot>
</table>
</html>
If I understood your questions correctly, you want to display the data that's retrieved from database. I am not a php expert, but based on the code, let me try to explain.
1) First connect to the database using the connections string provided and fetch the data
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
}
$result=mysql_query($sql);
?>
2) Create an HTML table to display the data. (First create the table header)
<table id="forum" width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<thead>
<tr>
<th width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<th width="43%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<th width="10%" align="center" bgcolor="#E6E6E6"><strong>Author</strong></td>
<th width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<th width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<th width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>
</thead>
3) Now dynamically add the data returned by the php code to this HTML table
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['orderNumber'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
echo "<td>" . $row['customerName'] . "</td>";
echo "<td>" . $row['salesRep'] . "</td>";
echo "<td>" . $row['DatePicker'] . "</td>";
echo "<td>" . $row['shipMethod'] . "</td>";
echo "<td>" . $row['trackingNumber'] . "</td>";
echo "<td>" . $row['Statuscheck'] . "</td>";
echo "<td>" . $row['Edit'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
4) Complete the HTML table
<tfoot>
<tr>
<td colspan="6" align="right" bgcolor="#E6E6E6"><strong>Create New Topic</strong> td>
</tr>
</tfoot>
</table>
5) Finally as best practice to close the connection to the database to avoid any unwanted issues + performance gain.
<?php
// Exit looping and close connection
}
mysql_close();
?>

How to show the clicked table row id in the address bar

I have a PHP based website for jobs. I echo all the jobs from database in a table below. When i click on a job in table row it shows the job details in an iframe beside the table.
This is the code of the table and iframe index.php
<table class="table1">
<tr>
<td colspan="3">
<?php
include "job.header.php";
?>
</td>
</tr>
<tr>
<td width="30%">
<div>
<?php
require "module/job.call.php";
?>
</div>
</td>
<td width="60%">
<iframe name="content" src="../module/job.unclicked.php">
</iframe>
</td>
<td width="20%"> </td>
</tr>
</table>
This is the code that i call jobs from the database job.call.php
<?php
$result = mysqli_query($conn,"SELECT * FROM job where approved='1' ORDER BY `CreatedTime` DESC");
echo "<table id='maintable' class='table-fill' border='0' cellpadding='0' cellspacing='0'>
<tr>
<th position='fixed' overflow='hidden' width='10%'>Job Title</th>
<th position='fixed' width='5%'>Company Name</th>
<th width='5%'>Closing Date</th>
</tr>";
while($row = mysqli_fetch_array($result) ) {
if (strlen($row['positiontitle']) > 20)
$row['positiontitle'] = substr($row['positiontitle'], 0, 60) . "...";
echo "<tr ref='job.details.php?id=".$row['id']."' target='content' class='positiontitle-link'>";
echo "<td><font style='text-shadow: none;'>" . $row['positiontitle'] . "</font></a></td>";
echo "<td>" . $row['companyname'] . "</td>";
echo "<td>" . $row['closingdate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
I want that when i click on the job in the table row then the address bar should take the id of the job. because if someone wants to share the job then they should just send that address for specific job.
Now it show like this
I want that it should look like this

input type="image" is not working in PHP using AJAX [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In my PHP application, I'm using AJAX so as to display the search results in the div, without refreshing the page.
here's my search_profile.php
<?php
session_start();
ob_start();
include('connection.php');
$query_religion="SELECT DISTINCT religion FROM religion_caste_table";
$result_religion = mysql_query($query_religion, $con);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="AJAX/religion_caste.js"></script>
</head>
<body>
<div id="search">
<table width="650px" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="460px">
<div id="search_box">
<h2>Search With Filter</h2>
<form method="post" action="javascript:search_profile(document.getElementById('search_form'));"
id="search_form" name="search_form">
<table cellpadding="0" width="460px" cellspacing="0" border="0" align="center">
<tr>
<td width="11px" height="5"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="12px"/>
</tr>
<tr>
<td align="center" width="11px"/>
<td align="center" width="100px">
<label for="search">&nbsp Searching:</label>
</td>
<td align="center" width="11px"/>
<td align="center" colspan="5" width="322" bgcolor="">
<select name="search_gender" id="search_gender" style="width:322px;">
<option value="Female">Bride</option>
<option value="Male">Groom</option>
</select>
</td>
<td align="center" width="12"/>
</tr>
<tr>
<td width="11px" height="5px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="12px"/>
</tr>
<tr>
<td align="center" width="11px"/>
<td align="center" width="100px">
<label for="from_age">&nbsp From:</label>
</td>
<td align="center" width="11px"/>
<td align="center" width="100px">
<select name="from_age" id="from_age" class="dropdown" style="width: 100px">
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="32">32</option>
<option value="33">33</option>
<option value="34">34</option>
<option value="35">35</option>
<option value="36">36</option>
<option value="37">37</option>
</select>
</td>
<td align="center" width="11px"/>
<td align="center" width="100px">
<label for="to_age">&nbsp To:</label>
<td align="center" width="11px"/>
<td align="center" width="100px">
<select name="to_age" id="to_age" class="dropdown" style="width: 100px">
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="32">32</option>
<option value="33">33</option>
<option value="34">34</option>
<option value="35">35</option>
<option value="36">36</option>
<option value="37">37</option>
</select>
<td align="center" width="12px"/>
</tr>
<tr>
<td width="11px" height="5px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="12px"/>
</tr>
<tr>
<td align="center" width="11px"/>
<td align="center" width="100px">
<label for="religion">&nbsp Religion:</label>
</td>
<td align="center" width="11px"/>
<td align="center" width="100px">
<select name="religion" id="religion" class="dropdown"
onChange="showcaste(this.value)" style="width: 100px">
<?php
while($q_rel_data = mysql_fetch_array($result_religion))
{?>
<option value="<?php echo $q_rel_data[0]; ?>"<?php if($row_social[religion] == $q_rel_data[0]) echo ' selected="selected"'; ?>>
<?php echo $q_rel_data[0]; ?>
</option>
<?php }?>
</select>
</td>
<td align="center" width="11px"/>
<td align="center" width="100px">
<label for="caste">&nbsp Caste:</label>
<td align="center" width="11px"/>
<td align="center" width="100px" >
<select name="caste" id="caste" class="dropdown" style="width: 100px">
</select>
<td align="center" width="12px"/>
</tr>
<tr>
<td width="11px" height="4px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="12px"/>
</tr>
<tr>
<td align="center" width="11px"/>
<td align="center" width="100px">
<label for="community">&nbsp Comunity:</label>
</td>
<td align="center" width="11px"/>
<td align="center" width="100px">
<select name="community" id="community" class="dropdown" style="width: 100px">
<?php
$community=array("Assami","Bengali","Bihari","Gujarati","Marwari","Rajasthani","Tamil","Telugu");
foreach ($community as $value)
{?>
<option value="<?php echo $value; ?>"<?php if($row_social[community] == $value) echo ' selected="selected"'; ?>><?php echo $value; ?>
</option>
<?php } ?>
</select>
</td>
<td align="center" width="11px"/>
<td align="center" width="100px">
<label for="occupation">&nbsp Occupation:</label>
<td align="center" width="11px"/>
<td align="center" width="100px">
<select name="occupation" id="occupation" style="width: 100px">
<?php
$occupation=array("Doctor","Engineer","Dentist","Civil Service","Military","Police","Govt. Service","Judiciary","Business","Private Job", "IT Professional","Teacher","Faculty","Sportsperson");
foreach ($occupation as $value)
{?>
<option value="<?php echo $value; ?>"<?php if($row_professional[occupation] == $value) echo ' selected="selected"'; ?>><?php echo $value; ?>
</option>
<?php } ?>
</select>
<td align="center" width="12px"/>
</tr>
<tr>
<td width="11px" height="4px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="12px"/>
</tr>
<tr>
<td align="center" colspan="9">
<input type="submit" name="Search" value="Search" class="button" style="width: 250px;"/>
</td>
</tr>
<tr>
<td width="11px" height="4px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="11px"/>
<td width="100px"/>
<td width="12px"/>
</tr>
</table>
</form>
</div>
</td>
<td width="190px">
<div id="search_by_name">
<h2>Search By Name</h2>
<form method="post" action="">
<table width="190px" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td align="center">Enter Name</td>
<td align="center">
<input type="text" id="name_to_search" name="name_to_search" class="textfield"
style="width: 100px;"/>
</td>
</tr>
<tr>
<td colspan="2">&nbsp
</td>
<tr>
<td align="center" colspan="2">
<input type="submit" id="search_pro" name="search_pro" class="button"
style="width: 100px;" align="center" />
</td>
</tr>
</table>
</form>
</div>
</td>
</tr>
<tr>
<td colspan="2">
<div id="search_profile_result">
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
now here's my ajax script AjaxSearchProfile.js
var http_request = false;
function makePOSTRequestProfile(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertSearchContents;
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}
function alertSearchContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById('search_profile_result').innerHTML = result;
} else {
alert(http_request.status);
}
}
}
function search_profile(obj)
{
alert("huhu");
var poststr = "gender=" + encodeURI( document.getElementById("search_gender").value ) +
"&from_age=" + encodeURI( document.getElementById("from_age").value ) +
"&to_age=" + encodeURI( document.getElementById("to_age").value ) +
"&religion=" + encodeURI( document.getElementById("religion").value ) +
"&caste=" + encodeURI( document.getElementById("caste").value ) +
"&community=" + encodeURI( document.getElementById("community").value ) +
"&occupation=" + encodeURI( document.getElementById("occupation").value );
alert(poststr);
makePOSTRequestProfile('search.php', poststr);
}
and the ultimately the search.php where the query is worked on..
<?php
include('connection.php');
$sex=$_POST['gender'];
$from_age=$_POST['from_age'];
$to_age=$_POST['to_age'];
$religion=$_POST['religion'];
$caste=$_POST['caste'];
$community=$_POST['community'];
$occupation=$_POST['occupation'];
$sql_search="SELECT t1.username, t1.name, t1.age, t1.dob, t1.propic, t2.religion, t2.caste, t3.education, t3.occupation
FROM candidate_register_table as t1
LEFT JOIN candidate_social_table as t2 ON
t1.username = t2.username and t2.caste = '$caste' and t2.religion ='$religion' and t2.community ='$community'
LEFT JOIN candidate_professional_table as t3 ON
t1.username = t3.username and t3.occupation = '$occupation' WHERE t1.sex = '$sex'";
$result_search=mysql_query($sql_search,$con);
if($result_search)
{
echo "<table border='0' cellspacing='0' cellpadding='0' width='650px' align='center'>";
while($row=mysql_fetch_array($result_search))
{
echo "<tr>";
echo "<form method='post' action='profile/exp.php' name='showid' id='showid'>";
echo "<td><input type='hidden' name='pro_username' value='" . $row['username'] . "'/></td>";
echo "<td><input type='image' src='" . $row['propic'] ."' style='width:30px;'/></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['username'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['name'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['religion'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['caste'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['occupation'] . " ::" . "</font></td>";
echo "<td><input type='submit' name='submit' id='submit'/></td>";
echo "</form>";
echo"</tr>";
}
echo "</table>";
}
else
die('Error: ' . mysql_error());
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
Now if you can see, the search results are displayed inside the div id="search_profile result" in the search_profile.php.
The fact is, the search result are displayed as the desired way, but now
as you can see, in the search.php I am printing the results as well as i'm using a input type="image" which ought to act like a submit button so that when it will be clicked, the username which is assigned to the input type="hidden" will be posted to the file "profile/exp.php".
But the result I mean value of the input type="hidden" is not getting posted or rather only blaNK value is posted.
here's the profile/exp.php:
<?php
session_start();
ob_start();
$showpro=$_POST['pro_username'];
echo $showpro;
?>
It ought to display the result i.e username, but its not displaying. I can't find the answer why; I have used this method earlier in another album cretaing application but it worked. My search query and procedure is perfect, otherwise it won't have displayed the result, but don't know why the input type="image" not working. Similarly I experimented with a submit button also as you can see, but that submit button is also not working.
Update
This following lines are not working, i.e the input type="image" and input type="submit"
$result_search=mysql_query($sql_search,$con);
if($result_search)
{
echo "<table border='0' cellspacing='0' cellpadding='0' width='650px' align='center'>";
while($row=mysql_fetch_array($result_search))
{
echo "<tr>";
echo "<form method='post' action='profile/exp.php' name='showid' id='showid'>";
echo "<td><input type='hidden' name='pro_username' value='" . $row['username'] . "'/></td>";
echo "<td><input type='image' src='" . $row['propic'] ."' style='width:30px;'/></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['username'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['name'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['religion'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['caste'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['occupation'] . " ::" . "</font></td>";
echo "<td><input type='submit' name='submit' id='submit'/></td>";
echo "</form>";
echo"</tr>";
}
echo "</table>";
}
else
die('Error: ' . mysql_error());
I hoped for an answer, and I found it myself...
I was doing a wrong thing by adding the tag just under the tag, which was creating the prob.
It needed to be added under the tag. So I changed my code into the following:-
echo "<table border='0' cellspacing='0' cellpadding='0' width='650px' align='center'>";
while($row=mysql_fetch_array($result_search))
{
echo "<tr>";
echo "<td>";
echo "<form method='post' action='profile/id.php' name='showid' id='showid'>
<input name='pro_username' name='pro_username' type='hidden' value='";echo $row['username']; echo "'/>
<input type='image' src='" . $row['propic'] ."' style='width:30px;'/></form></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['username'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['name'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['religion'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['caste'] . " ::" . "</font></td>";
echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['occupation'] . " ::" . "</font></td>";
echo "<td><input type='submit' name='submit' id='submit'/></td>";
echo "</form>";
echo"</tr>";
}
echo "</table>";
}

How do I php echo this SQLDatabase data into a stylized table?

I'm trying to echo data from an SQLdatabase into a table that is somewhat decent-looking. I can already echo the data properly into 5 separate basic tables, but when I can't figure out how to style it without it completely messing up. Here is the code I already have:
// OUTPUTS RESULTS //
$resultfirst = mysql_query("SELECT * FROM Students WHERE FirstPeriod='$_POST[firstperiod]'");
$resultsecond = mysql_query("SELECT * FROM Students WHERE SecondPeriod='$_POST[secondperiod]'");
$resultthird = mysql_query("SELECT * FROM Students WHERE ThirdPeriod='$_POST[thirdperiod]'");
$resultfourth = mysql_query("SELECT * FROM Students WHERE FourthPeriod='$_POST[fourthperiod]'");
$resultfifth = mysql_query("SELECT * FROM Students WHERE FifthPeriod='$_POST[fifthperiod]'");
// 1st PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>First Period</th>
</tr>";
while($row = mysql_fetch_array($resultfirst))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 2nd PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Second Period</th>
</tr>";
while($row = mysql_fetch_array($resultsecond))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 3rd PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Third Period</th>
</tr>";
while($row = mysql_fetch_array($resultthird))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 4th PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Fourth Period</th>
</tr>";
while($row = mysql_fetch_array($resultfourth))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 5th PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Fifth Period</th>
</tr>";
while($row = mysql_fetch_array($resultfifth))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
If the code above is unclear- my goal is to compare the first period teachers in which are stored in the database, and output the students names that share the same period/teacher.
This code works fine. But the tables look very bland. I would like to echo the data into a table such as this.
<table width="368" border="0" cellspacing="0" cellpadding="2" align="center" height="100">
<tr valign="middle">
<td bgcolor="#000066" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Services</font></b></font> </div>
</td>
<td width="4" height="20"></td>
<td bgcolor="#990000" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Products</font></b></font></div>
</td>
<td width="4" height="20"></td>
<td bgcolor="#C89800" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Resources</font></b></font> </div>
</td>
</tr>
<tr valign="top">
<td bgcolor="#000066" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Professional
and cost effective web design, development and promotion services
</font></p>
</td>
</tr>
</table>
</td>
<td width="4"></td>
<td bgcolor="#990000" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Interactive
Web Products - Flash Survey, poll, Guest book, Instant Quote
</font></p>
</td>
</tr>
</table>
</td>
<td width="4"></td>
<td bgcolor="#C89800" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Free
web resources - articles, tutorials, tips and tricks.
</font></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
If anyone can offer any suggestions of any sort- I would greatly appreciate it.
I see a few areas that can be improved:
As others have said, don't use tables to manage layout. However, tables are perfectly acceptable for displaying tabular data
You really want to use CSS to style your page, it's a lot easier to control your style and makes the markup easier to read. See this w3schools' artcile on CSS Tables
You can combine your multiple queries into one for better performance (though, that seems to be outside the scope of your question)
Here is an example markup and CSS for your table: http://jsfiddle.net/vxzJV/

Categories