Hello all,
I am having this very frustrating issue, I am trying to print this query i got from my SQL table. However, If the query returns 10 [1,2,3,4,5,6,7,8,9] results it just prints 5 [2,4,6,8,10] . I have no idea what to do.
<!--Error Reporting Production Only[start]-->
<?php
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors','1');
//Error Reporting Production Only[end]-->
//Connect to Database [start]-->
require_once 'sqllogin.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());
//Connect to Database [end]-->
//Process the search [start]-->
//Initialize the search output variable
$search_output = "";
$sql_command = "SELECT * FROM `Alpha` WHERE 1";
//See if the posted search field is set and has a value
if (isset($_POST['searchquery']) && $_POST['searchquery'] !="")
{//IF START 1
//run code if condition is met
//Filter the search query user input
$searchquery = preg_replace('#[a-z 0-9 A-Z]#i', '', $_POST['searchquery']);
// Search Query*********************
if($_POST['filter1'] == "All")
{//all filter code goes her
$sql_command = "SELECT id, lastname, firstname, building, room FROM `Alpha` WHERE firstname LIKE '%$_POST[searchquery]%' OR lastname LIKE '%$_POST[searchquery]%' OR id LIKE '%$_POST[searchquery]%'";
}
else if($_POST['filter1'] == "Last Name")
{//Last Name filter code goes her
$sql_command = "SELECT id, lastname, firstname, building, room FROM `Alpha` WHERE lastname LIKE '%$_POST[searchquery]%'";
}
else if($_POST['filter1'] == "First Name")
{//First Name filter code goes her
$sql_command = "SELECT id, lastname, firstname, building, room FROM `Alpha` WHERE firstname LIKE '%$_POST[searchquery]%'";
}
else if($_POST['filter1'] == "First Name")
{//ID filter code goes her
$sql_command = "SELECT id, lastname, firstname, building, room FROM `Alpha` WHERE id LIKE '%$_POST[searchquery]%'";
}
}//IF END 1
$query = mysql_query($sql_command) or die(mysql_error());
$count = mysql_num_rows($query);
if ($count>0)
{
$search_output.= "<hr /> $count results for <strong>$_POST[searchquery]</strong><hr /> $sql_command <hr />**IF**POST = $_POST[searchquery] Count=$count, Query= $query<hr />";
/*for ($j = 0 ; $j < $rows ; ++$j)
{
$id = $row["id"];
$lastname = $row["lastname"];
$firstname = $row["firstname"];
$building = $row["building"];
$room = $row["room"];
$search_output .= "$id \t $firstname \t\t $lastname \t\t $building \t$room<br />";
}
***************
Can be used instead but not here try putting it where $search_output is
echo 'ID: ' . $row[0] . '<br />';
echo 'Last Name: ' . $row[1] . '<br />';
echo 'First Name: ' . $row[2] . '<br />';
echo 'Building: ' . $row[3] . '<br />';
echo 'Room: ' . $row[4] . '<br /><br />';
***********************
*/
while($row = mysql_fetch_array($query))
{
$row = mysql_fetch_array($query);
$id = $row[0];
$lastname=$row[1];
$firstname=$row[2];
$building=$row[3];
$room=$row[4];
$search_output .= "$id $firstname $lastname $building $room<br />";
}
}
else
{
$search_output ="<hr /> 0 results for <strong>$searchquery</strong><hr /> $sql_command <hr />****ELSE**POST = $_POST[searchquery] Count=$count, Query= $query<hr /" ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MC Reslife WEB APP Developed by; JB</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="Header">Monroe College Resident's Life Web App</div>
<div id="Page">
<div id="Menu">
<h1>Search</h1>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input name="searchquery" type="text" maxlength="19" size="19"/>
<input name="myBTN" type="submit" />
<br />
Search By:
<select name="filter1">
<option value="All">All</option>
<option value="Last Name">Last Name</option>
<option value="First Name">First Name</option>
<option value="ID Number">ID Number</option>
</select>
</form>
<hr />
<h1>Menu</h1>
<p><a href="#">Alpha List</a></p>
<p><a href="#">Lock Out Log</a></p>
<p><a href="#">Current Probations</a></p>
</div>
<div id="Content">
<h1>Alpha List</h1>
<?php
echo $search_output;
?>
<p>*************************</p>
<?php echo "this is what in post $_POST[searchquery]"?>
</div>
</div>
<div id="Footer">Content for id "Footer" Goes Here</div>
</body>
</html>
please help me