Here is the code I'm using to communicate with a microcontroller.
Everything works, however when I click on the link html, which is supposed to send data through serial i get:
http://project.sonar.com/%3C?=$_SERVER[%27PHP_SELF%27]%20.
The requested URL /< was not found on this server.
I know the communication initialization works, since this problem occurred only when I added the link
if (isset($_GET['action']))
{
error_reporting(E_ALL);
ini_set('display_errors', '1'); //displays php errors
include("php_serial.class.php");
$serial = new phpSerial();
//$serial -> deviceClose();
$serial->deviceSet('/dev/ttyUSB0'); //for linux serial /dev/ttySP(0-4) for usb /dev/ttyUSBN
// If you want to change the configuration, the device must be closed
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(2); //Stop bits (this is the "1" in "8-N-1")
$serial->confFlowControl("none");
$serial->deviceOpen();
if ($_GET['action'] == "on")
{
// To write into $serial->sendMessage("1");
for ($x = 1; $x < 20; $x++)
$serial->sendMessage("1");
}
$read = $serial->readPort(); //read stores acii value from controller
if($read > "0")
{
$numberz = 20*ord($read); // number converts the value to decimal representation of distance
//echo "$numberz";
//$database="MEASURE";
$username = "xxxx";
$password = "xxxx";
$hostname = "xxxx";
$connection = mysql_connect($hostname, $username, $password);
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("MEASURE", $connection);
mysql_query("INSERT INTO measurement (DATA)
VALUES
('$numberz')");
}
else
{
$serial -> deviceClose();
}
}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" title="currentStyle" media="screen">
#import "style.css";
</style>
<body>
<p><a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>">
Click here to turn the system on.</a></p>
<div id="wrapper">
<div id="top">
<ul id="mainmenu">
<li>HOME</li>
<li>MEASUREMENTS</li>
<li>REPORT</li>
<li>CONTACTS</li>
</ul>
</div>
<div id="pictop">
<img src="pics/header.jpg"/>
</div>
<div id="main">
<div id="indexleft">
<h2>Table</h2>
<?php
//$database="MEASURE";
$username = "xxxx";
$password = "xxxx";
$hostname = "xxxx";
$connection = mysql_connect($hostname, $username, $password);
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("MEASURE", $connection);
$result = mysql_query("SELECT * FROM measurement");
echo "<table width='80%' border='4px'>
<tr>
<th>ID</th>
<th>DATA</th>
<th>TIME</th>
</tr>";
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center'>" . $row['ID'] . "</td>";
echo "<td align='center'>" . $row['data'] . "</td>";
echo "<td align='center'>" . $row['TIME'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($connection);
?>
</div>
<div id="bottom">
</div>
</div>
</div>
</body>
</html>
Any suggestions? Thank you.
Your server probably does not have short tags enabled.
Change:
<p><a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>">
to:
<p><a href="<?php echo $_SERVER['PHP_SELF'] . "?action=on"; ?>">
although you could probably change it to just:
<p><a href="?action=on">
The %3c in your URL is the < character. It is not surprising that there is no directory or file called <. Change where you write the link to:
<?php echo $_SERVER['PHP_SELF'] . "?action=on"; ?>
Related
how could i add ajax to my php file ,that when i delete an item of the list the data should automatically reload and my list should be updated to the new list?
I made list of all my data with a button of delete
here is my code for php
<?php
function tableV1 ($row) {
echo '<tr>';
echo '<td>' .$row['id']. '</td>';
echo '<td>' . $row['firstname'] . '</td>';
echo '<td>' . $row['lastname'] . '</td>';
}
$dbPassword = "micr2001";
$dbUserName = "PHPFundamentals";
$dbServer = "localhost";
$dbName = "PHPfundamentals";
// Create connection
$conn = mysqli_connect($dbServer , $dbUserName , $dbPassword,$dbName) or die("unable to connect to host");
// Check connection
if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); }
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
table {font-size: 27px; }
tbody {}
td {border-bottom: 1px solid bisque;padding:15px;}
th {border-bottom: 1px solid bisque;padding:15px;}
thead {}
tr {}
</style>
</head>
<body>
<center>
<table>
<thead>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
<th> </th>
</thead>
<?php
// Takes all the results from the table with genre 5.
$sql = "SELECT id,firstname, lastname FROM persons";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_assoc()) {
tableV1($row);
$rowId = $row['id'];
$first_name = $row['firstname'];
$last_name = $row['lastname'];
echo '<td>'
. ' <a class="edit_btn btn" href=edit.php?id='.$rowId.'&lname='.$last_name.'&fname='.$first_name. '>Edit</a>'
. ' </td>';
echo '<td><a class="del_btn btn" href=delete.php?id='.$rowId.'>Delete</a></td>';
echo' </tr>';
}
} else {
echo '<tr><td colspan="3">0 results</td></tr>';
}
?>
</table>
</center>
</body>
</html>
<?php
$conn->close();
?>
here is the code for delete.php
<?php
require 'connection.php';
$id = $_GET['id'];
$sql = "DELETE FROM persons WHERE id = ".$id ;
if(mysqli_query($conn, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
mysqli_close($conn);
?>
i want the item that i delete should get off my list
Why do you even need AJAX? As user clicks Delete, she / he is redirected to the delete.php script. In that script after sucessful deletion you should just redirect the user back to the listing. This can be achieved by HTTP redirect (https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection). Keep it simple!
I'm trying to create an Edit option in the table showing the database on my website.
The problem is even when I click Save, the database is not updated.
There are no errors showing.
There's an EditComplaint.php, which fetches data from DB and shows it in input boxes so it can be edited and Ecomp.php, which is called on clicking Save.
<?php
$id = $_GET['id'];
$db_host = 'localhost'; // Server Name
$db_user = 'Username'; // Username
$db_pass = 'Username'; // Password
$db_name = 'Database'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = "SELECT `id`, `ref_no`, `type`, `comp_name`, `comp_no`, `station`, `pertains`, `user_remarks`, `to_whom`, `concern`, `brief_fct`, `sec_remarks`, `depart`, `cisf_remarks`, `generalcomment`, `status` FROM `Complaintstable` WHERE `Complaintstable`.`id` = '$id'";
$query = mysqli_query($conn, $sql);
if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Titillium+Web|Roboto+Condensed:400,300|Pathway+Gothic+One|ABeeZee:400,400italic" rel="stylesheet" type="text/css">
<link href="master-stylesheet.css" rel="stylesheet">
<link href="custom-stylesheet.css" rel="stylesheet">
<link href="complaintstable.css" rel="stylesheet">
<link href="dmrc-favicon.png" rel="shortcut icon" type="image/x-icon">
<title>DMRC/Login</title>
</head>
<body>
<form action="Ecomp.php" id="form1" method="post" name="form1">
<!-- header section -->
<div class="header">
<div class="header-inner">
<div class="header-top">
<div class="welcome-guest">
<span class="align-right float-right" id="lblusername" style="color:Black;">Guest</span><em><span class="welcome-cont float-right fontfamily_2" id="lblwelcome" style="padding-left:5px;padding-right:5px;color:black;">Welcome</span></em>
</div>
<div class="header-top-links">
<ul>
<li>
Home
</li>
</ul>
</div>
</div>
<div class="header-bottom">
</div>
</div>
</div>
<div class="container clearfix">
<br><br>
<table class="data-table">
<thead>
<tr>
<th>ID</th>
<th>Referral/No.</th>
<th>Type</th>
<th>Complainant Name</th>
<th>Station</th>
<th>Pertains To</th>
<th>User Remarks</th>
<th>To Whom</th>
<th>Concern</th>
<th>Brief Fact</th>
<th>Security Comments</th>
<th>Deptt</th>
<th>CISF Comments</th>
<th>General Comment</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
while($row = $query->fetch_assoc())
{
$id = $row['id'];
$ref_no = $row['ref_no'];
$type = $row['type'];
$comp_name = $row['comp_name'];
$station = $row['station'];
$pertains = $row['pertains'];
$user_remarks = $row['user_remarks'];
$to_whom = $row['to_whom'];
$concern = $row['concern'];
$brief_fct = $row['brief_fct'];
$sec_remarks = $row['sec_remarks'];
$depart = $row['depart'];
$cisf_remarks = $row['cisf_remarks'];
$generalcomment = $row['generalcomment'];
$status = $row['status'];
if ($i == 0)
{
$i++;
echo "<tr>";
echo "<td><input type='text' name='id' value='$id'/></td>";
echo "<td><input type='text' name='ref_no' value='$ref_no'/></td>";
echo "<td><input type='text' name='type' value='$type'/></td>";
echo "<td><input type='text' name='comp_name' value='$comp_name'/></td>";
echo "<td><input type='text' name='station' value='$station'/></td>";
echo "<td><input type='text' name='pertains' value='$pertains'/></td>";
echo "<td><input type='text' name='user_remarks' value='$user_remarks'/></td>";
echo "<td><input type='text' name='to_whom' value='$to_whom'/></td>";
echo "<td><input type='text' name='concern' value='$concern'/></td>";
echo "<td><input type='text' name='brief_fct' value='$brief_fct'/></td>";
echo "<td><input type='text' name='sec_remarks' value='$sec_remarks'/></td>";
echo "<td><input type='text' name='depart' value='$depart'/></td>";
echo "<td><input type='text' name='cisf_remarks' value='$cisf_remarks'/></td>";
echo "<td><input type='text' name='generalcomment' value='$generalcomment'/></td>";
echo "<td><input type='text' name='status' value='$status'/></td>";
echo "<td><a href='delete.php?id=$id' class='button-new'>Delete</a></td>";
echo "</tr>";
}
echo '<br><br>';
}
?>
</tbody>
</table>
<br><br>
<input type="submit" class="button-new" value="Save"/>
</div>
<div class="footer">
<div class="footer-top">
<div class="footer-top-inner">
<ul>
<li>
FAQs
</li>
<li>
Contact Us
</li>
<li>
Disclaimer
</li>
<li>
Terms & Conditions
</li>
</ul>
</div>
</div>
<div class="footer-bottom fontfamily_2">
<div class="footer-bottom-inner">
<div class="float-left footer-text">
</div>
</div>
</div>
</div>
</form>
</body>
</html>
And Here's the Ecomp.php that Save calls
<?php
$db_host = 'localhost'; // Server Name
$db_user = 'Username'; // Username
$db_pass = 'Username'; // Password
$db_name = 'Database'; // Database Name
// Create connection
$con = mysqli_connect($servername, $username, $password) or die("Unable to Connect to '$dname'");
// Check connection
if (!$con)
{
echo "Please try later.";
}
else
{
mysqli_select_db($con, $dname);
}
$id = $_POST['id'];
$ref_no = $_POST['ref_no'];
$type = $_POST['type'];
$comp_name = $_POST['comp_name'];
$station = $_POST['station'];
$pertains = $_POST['pertains'];
$user_remarks = $_POST['user_remarks'];
$to_whom = $_POST['to_whom'];
$concern = $_POST['concern'];
$brief_fct = $_POST['brief_fct'];
$sec_remarks = $_POST['sec_remarks'];
$depart = $_POST['depart'];
$cisf_remarks = $_POST['cisf_remarks'];
$generalcomment = $_POST['generalcomment'];
$status = $_POST['status'];
mysqli_query($con," UPDATE `Complaintstable` SET `ref_no`= '$ref_no',`type`='$type',`comp_name`=`$comp_name`,`station`='$station',`pertains`='$pertains',`user_remarks`='$user_remarks',`to_whom`='$to_whom',`concern`='$concern',`brief_fct`='$brief_fct',`sec_remarks`='$sec_remarks',`depart`='$depart',`cisf_remarks`='$cisf_remarks',`generalcomment`='$generalcomment',`status`='$status' WHERE `Complaintstable`.`id` = '$id'");
header("Location: complaintstable.php");
?>
Kindly guide me please.
Its my first time here.
Thanks in Advance.
Edit: The Update SQL query works when ran in phpmyadmin console.
What i can see is that you are wrapping one of your db values $comp_name in backticks ` but it is probably a string..
In this line look at the $comp_name:
mysqli_query($con," UPDATE `Complaintstable` SET `ref_no`= '$ref_no',`type`='$type',`comp_name`='$comp_name',`station`='$station',`pertains`='$pertains',`user_remarks`='$user_remarks',`to_whom`='$to_whom',`concern`='$concern',`brief_fct`='$brief_fct',`sec_remarks`='$sec_remarks',`depart`='$depart',`cisf_remarks`='$cisf_remarks',`generalcomment`='$generalcomment',`status`='$status' WHERE `Complaintstable`.`id` = '$id'");
I agree with Magnus. Here is how you could do the same with PDO. Although prepared statements are possible in mysql too, i would always go for PDO. See this reference if you want to spend time with it.
$db = new PDO('mysql:host=localhost;dbname=someDatabase', 'someUser', 'somePass');
$stmt = $db->prepare("UPDATE `Complaintstable` SET `ref_no`= ?,`type`= ?,`comp_name`=?,`station`= ?,`pertains`= ?,`user_remarks`=?,`to_whom`= ?,`concern`= ?,`brief_fct`= ?,`sec_remarks`= ?,`depart`= ?,`cisf_remarks`= ?,`generalcomment`= ?,`status`= ? WHERE `Complaintstable`.`id` = ?");
$stmt->execute(array($ref_no,$type,$comp_name,$station,$pertains,$user_remarks,$to_whom,$concern,$brief_fct,$sec_remarks,$depart,$cisf_remarks,$generalcomment,$status,$id));
I would like to show values in my database of a certain team when I click on the submit button. I have a code, but it doesn't work so please help!!
Here's my first code:
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="./images/favicon-32x32.png"
sizes="32x32" />
<link rel="icon" type="image/png" href="./images/favicon-16x16.png"
sizes="16x16" />
<title>MLB: Major League Baseball</title>
<link href="css folder/MLBstylesheet.css" rel="stylesheet" type="text/css"/>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("txtHint").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","getteam.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="container">
<div id="titel">
<img class="MLBTitel" src="./images/MLBtitel.jpg" alt="MLBTitel" >
<div id="titeltekst">
MAJOR LEAGUE BASEBALL
<br>
</div>
<nav>
<ul>
<li><a class= "menu" href="index.html">Home</a></li>
<li><a class= "menu" href="spelers.php">Spelers</a></li>
<li><a id = "active" class= "menu" href="teams.php">Teams</a></li>
<li><a class= "menu" href="wedstrijden.html">Wedstrijden</a></li>
<li><a class= "menu" href="contact.html">Contact</a></li>
</ul>
</nav>
<br><br>
</div>
<?php
$servername = "localhost";
$username = "id1419279_root";
$password = "nivardenjoey";
$dbname = "id1419279_mlb";
// Create connection
$conn = new mysqli($localhost, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT teamnaam FROM teams";
$result = $conn->query($sql);
$dropdownlist = '';
while($row = mysqli_fetch_array($result)) {
$teamnaam = $row['teamnaam'];
$dropdownlist .="<option value='" . $teamnaam . "'>" . $teamnaam . "
</option>";
}
if(isset($dropdownlist)){
echo "<select name='teamlijst' onchange='showUser(this.value)'>";
echo $dropdownlist;
echo "<input type='submit' value='Submit'>";
echo "</select>";
}
?>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>
</div>
</body>
</html>
And here's my second code of the retrieving part
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
$q = intval($_GET['q']);
$servername = "localhost";
$username = "id1419279_root";
$password = "nivardenjoey";
$dbname = "id1419279_mlb";
$con = new mysqli($localhost, $username, $password, $dbname);
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM teams WHERE teamnaam = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>teamnaam</th>
<th>coach</th>
<th>info</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['teamnaam'] . "</td>";
echo "<td>" . $row['coach'] . "</td>";
echo "<td>" . $row['info'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
I really hope anyone can help me
Well in the end I didn't even need 2 files. It's just one file now and this is the code:
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="./images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./images/favicon-16x16.png" sizes="16x16" />
<title>MLB: Major League Baseball</title>
<link href="css folder/MLBstylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="container">
<div id="titel">
<img class="MLBTitel" src="./images/MLBtitel.jpg" alt="MLBTitel" >
<div id="titeltekst">
MAJOR LEAGUE BASEBALL
<br>
</div>
<nav>
<ul>
<li><a class= "menu" href="index.html">Home</a></li>
<li><a class= "menu" href="spelers.php">Spelers</a></li>
<li><a id = "active" class= "menu" href="teams.php">Teams</a></li>
<li><a class= "menu" href="wedstrijden.php">Wedstrijden</a></li>
<li><a class= "menu" href="contact.html">Contact</a></li>
</ul>
</nav>
<br><br>
</div>
<?php
$localhost = "localhost";
$username = "id1419279_root";
$password = "*****";
$dbname = "id1419279_mlb";
// Create connection
$conn = new mysqli($localhost, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT teamnaam FROM teams";
$result = $conn->query($sql);
$dropdownlist = '';
while($row = mysqli_fetch_array($result)) {
$teamnaam = $row['teamnaam'];
$dropdownlist .="<option value='" . $teamnaam . "'>" . $teamnaam . " </option>";
}
if(isset($dropdownlist)){
echo "<form action='teams.php' method='POST'>";
echo "<select name='teamlijst'>";
echo $dropdownlist;
echo "<input name='submit' type='submit' value='Submit'>";
echo "</select>";
echo "</form>";
}
if(isset($_POST["submit"]) && isset($_POST["teamlijst"])){
if (!$conn) {
die('Could not connect: ' . mysqli_error($conn));
}
$sql="SELECT * FROM teams WHERE teamnaam = '" . $_POST["teamlijst"] . "'";
$result = mysqli_query($conn,$sql);
echo "<table>
<tr>
<th>teamnaam</th>
<th>coach</th>
<th>info</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['teamnaam'] . "</td>";
echo "<td>" . $row['coach'] . "</td>";
echo "<td>" . $row['info'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
}
?>
<br>
</div>
</body>
</html>
i'm unable to make comment
you need to change your servername to localhost
also you should use firebug for javascript debug
the rest of your code seems fine
and if you can't get PHP errors you should check you php.ini settings
$localhost= "localhost";
$username = "id1419279_root";
$password = "nivardenjoey";
$dbname = "id1419279_mlb";
// Create connection
$conn = new mysqli($localhost, $username, $password, $dbname);
1.Your $row is not defined while you were using while($row = mysqli_fetch_array($result)), im wondering whether this while was working.
2.Try dump your SQL results to check if your database settings was going right.
I am having a problem with pagination within the tabs. In the second tab (candidate), when I press pagination 2 to navigate to the second page of the candidate table, I am returned to the first page of the contact table. If I go to the candidate tab after that I am on the right page. Where have I gone wrong?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/start/jquery-ui.css"/>
<link type ="text/css" rel ="stylesheet" href = "testData.cs"/>
<script>
$(function(){
$('#tabs1,#tabs2').tabs();
});
</script>
<head>
<title>Candidate DB</title>
</head>
<body>
<div id ="tabs1" class ="contactForm">
<ul>
<li>List of Contacts</li>
<li>List of Candidates</li>
<li>Advanced Search</li>
</ul>
<div id ="tab1" class="contact" >
<table border="1" id="contact_info">
<tr>
<th>Contact Name</th>
<th>County</th>
</tr>
<?php
$DB_NAME = "Candidate";
$DB_USER ="root";
$DB_PASSWORD ="";
$DB_HOST ="localhost";
$con=mysql_connect("$DB_HOST", "$DB_USER", "$DB_PASSWORD") or die("Could not connect to MySQL");
mysql_select_db("$DB_NAME") or die ("No Database");
echo "Connected to Candidate Database </br></hr>" ;
$per_page=5;
$pages_query= mysql_query("SELECT COUNT(contact_id) FROM contact");
$pages = ceil(mysql_result($pages_query,0)/$per_page);
$page=(isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start=($page-1) * $per_page;
$sql=mysql_query("SELECT first_name, last_name, county from contact ORDER BY last_name ASC LIMIT $start, $per_page" );
$Fname = 'first_name';
$Lname = 'last_name';
$county = 'county';
while ( $row = mysql_fetch_object($sql)) {
echo "<tr>";
echo "<td>" . $row ->first_name . " " . $row->last_name. "</td>";
echo "<td>" . $row->county . "</td>";
echo "</tr>";
}
// close the loop
if ($pages>=1 && $page<= $pages ) {
for ($x=1; $x<=$pages; $x++)
{
echo ($x ==$page)? '<strong><a style="color:green" href="? page='.$x.'">'.$x. '</a></strong>_':''.$x. '_';
}
}
?>
</table>
</div>
<div id ="tab2" class="candidate" >
<table border="1" id="candidate_info">
<tr>
<th>Candidate Name</th>
<th>County</th>
</tr>
<?php
$per_pageR=5;
$pages_queryR= mysql_query("SELECT COUNT(candidate_id) FROM p_candidate");
$pagesR = ceil(mysql_result($pages_queryR,0)/$per_pageR);
$pageR=(isset($_GET['pageR'])) ? (int)$_GET['pageR'] : 1;
$startR=($pageR-1) * $per_pageR;
$sql2=mysql_query("SELECT R_first_name, R_last_name, R_county from p_candidate ORDER BY R_last_name ASC LIMIT $startR, $per_pageR" );
$R_name = 'R_first_name';
$R_name = 'R_last_name';
$R_county = 'R_county';
while ( $rowR = mysql_fetch_object($sql2)) {
echo "<tr>";
echo "<td>" . $rowR ->R_first_name . " " . $rowR->R_last_name. "</td>";
echo "<td>" . $rowR->R_county . "</td>";
echo "</tr>";
}
// close the loop
if ($pagesR>=1 && $pageR<= $pagesR ) {
for ($y=1; $y<=$pagesR; $y++)
{
echo ($y ==$pageR)? '<strong><a style="color:green" href="? pageR='.$y.'">'.$y. '</a></strong>_':''.$y. '_';
}
}
?>
</table>
</div>
</div>
</body>
If I understand correctly, try using the active option - http://api.jqueryui.com/tabs/#option-active - when you do .tabs() to make the candidate tab the active tab.
<script>
$(function(){
$('#tabs1,#tabs2').tabs(<?php if(isset($_GET['pageR'])) echo "{ active: 1 }"; ?>);
});
</script>
or
<script>
$(function(){
$('#tabs1,#tabs2').tabs(<?php if(isset($_GET['pageR'])) echo '"option", "active", -1'; ?>);
});
</script>
edit
You could bind the .tabs() first, and then set the active option. This should hopefully fix your formatting issue.
<script>
$(function(){
$('#tabs1,#tabs2').tabs();
<?php if(isset($_GET['pageR'])) { ?>
$('#tabs1').tabs("option", "active", -1)
<?php } ?>
});
</script>
I can populate correctly the dropbox but I cannot find a way to display the data of the selected item in a table when I click submit. Here is the code:
index.php
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Αναζήτηση Οφειλών Ανά Πολυκατοικία</title>
<link rel="stylesheet" href="tbl_style.css" type ="text/css"/>
</head>
<body>
<form id="form1" name="form1" method="POST" action="search.php">
<?php
include('config.php');
$query = "SELECT DISTINCT odos FROM ofeiles_results ORDER BY odos ASC";
mysql_query("SET CHARACTER SET 'utf8'");
mysql_query("SET NAMES 'utf8'");
$result = mysql_query($query);
echo "<select name='polykatoikia'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['odos'] . "'>" . $row['odos'] . "</option>";
}
echo "</select>";
?>
<input type="submit" name="Submit" value="Select" />
</form>
</html>
</body>
So far so good, the dropbox gets populated. Then in the file search.php I have the following code:
search.php
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Αποτελεσματα Αναζητησης Πολυκατοικιων</title>
<link rel="stylesheet" href="tbl_style.css" type ="text/css"/>
</head>
</html>
<?php
include('config_barcode.php');
if(isset($_POST['select'])){
$odoss = $_POST['select'];
mysql_query("SET CHARACTER SET 'utf8'");
mysql_query("SET NAMES 'utf8'");
$display_query = "SELECT odos FROM ofeiles_results WHERE odos LIKE '" . $odoss . "'";
$result_exoda = mysql_query($display_query) or die(mysql_error());
print $result_exoda;
$odos = $row['odos'];
$app = $row['perigrafh'];
$enoikos = $row['enoikos'];
$mhnas = $row['mhnas'];
$synolo = $row['synolo'];
echo "</br>";
echo "</br>";
echo "</br>";
echo "<table cellpadding='3' cellspacing='0'>";
echo "<tr>";
echo "<th align='center' bgcolor='#FFCC00'><strong>Οδος</strong></th>";
echo "<th align='center' bgcolor='#FFCC00'><strong>Διαμερισμα</strong></th>";
echo "<th align='center' bgcolor='#FFCC00'><strong>Όνομα</strong></th>";
echo "<th align='center' bgcolor='#FFCC00'><strong>Σύνολο</strong></th>";
echo "<th align='center' bgcolor='#FFCC00'><strong>Μήνας</strong></th>";
echo "</tr>";
echo "<td align='center'>".$odos."</td>";
echo " <td align='center'>".$app."</td>";
echo " <td align='center'>".$enoikos."</td>";
echo " <td align='center'>".$mhnas."</td>";
echo " <td align='center'>".$synolo."</td>";
echo "</table></td>";
echo $result_exoda;
}
?>
All I get is a blank page. What am I doing wrong? Thanks.
I use this to display the data in tables, you don't need to use many "echo" use LOOPS
you can add more rows in
$sql = "SELECT your_row , another_row , your_row_again FROM your_table_name";
if you had more rows in you database.
$conn = mysql_connect($dbhost, $dbuser);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = "SELECT your_row , another_row , your_row_again FROM your_table_name";
mysql_select_db('your_db');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
echo "<div align = 'center'><table border = '1'>";
echo "<th>Your_row_Header</th><th>Row_Header_again</th><th>Row_Header_again</th>";
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "<tr><td align = center>{$row['Your_row1']}</td>".
"<td align = center>{$row['Your_Row2']}</td></tr>".
"<td align = center>{$row['Your_Row3']}</td>";
}
echo "</table></div><br />";
mysql_close($conn);