How to create jquery tabs using php? - php

I used jquery-ui tabs using php but it's not working, I am unable to identify the problem, please help me.
<div id="tabs">
<div class="row">
<div class="col-md-4">
<?php
$con = mysqli_connect("localhost", "admin", "123456", "gazette");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM gazette_details");
while ($row = mysqli_fetch_array($result)) {
echo "<ul>";
$id = '#tabs-' . $row['id'];
echo "<li>" . "<a href='$id'>" . $row['gazette_id'] . "</a>" . "</li>";
echo "</ul>";
}
mysqli_close($con);
?>
</div>
<div class="col-md-4">
<div id="tabs-12">1</div>
<div id="tabs-13">2</div>
<div id="tabs-14">3</div>
</div>
</div>
<div class="col-md-4">.col-md-4</div>
</div>
I used this website example: http://jqueryui.com/tabs/

you may try
<?php
$ARR_RESULT = array();
$con = mysqli_connect("localhost", "admin", "123456", "gazette");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM gazette_details");
while ($row = mysqli_fetch_array($result)) {
$ARR_RESULT[] = $row;
}
mysqli_close($con);
?>
<div id="tabs">
<ul>
<?php
foreach($ARR_RESULT as $arr)
{
echo '<li>'.$arr['gazette_id'].'</li>';
}
?>
</ul>
<?php
foreach($ARR_RESULT as $arr)
{
echo '<div id="tabs-'.$arr['id'].'">';
echo '<p>Tab-'$arr['id'].'</p>';
echo '</div>';
}
?>
</div>

Related

How to select a result from a result that return by a SQL

I'm using SQL and PHP to pull information from my database and it returned a list of users that met the criteria. And I need to redirect to another page using the selected amount from the picture below. How can I grab this amount to another page?
For example, when I click the first select, I can go to the other page that showing $24, and Rubinsztein Abdel, 182 Crownhardt Lane...
<!--loader end-->
<!-- Main -->
<div id="main">
<!-- wrapper -->
<div id="wrapper">
<div class="content">
<!-- Map -->
<div class="map-container column-map right-pos-map">
<div id="map-main"></div>
<ul class="mapnavigation"></ul>
<div class="scrollContorl mapnavbtn" title="Enable Scrolling"><span><i class="fa fa-lock"></i></span></div>
</div>
<!-- Map end -->
<!--col-list-wrap -->
<div class="col-list-wrap left-list">
<!-- list-main-wrap-->
<div class="list-main-wrap fl-wrap card-listing">
<!-- listing-item -->
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$severname = "localhost";
$username = "root";
$password = "";
$dbname = "dbn";
//$conn = mysqli_connect('xx', 'xx', 'xx','xx');
$conn = mysqli_connect('dxx', 'xx', 'xx','xx');
//check connection
if (mysqli_connect_errno())
{echo nl2br("Failed to connect to MySQL: ". mysqli_connect_error() . "\n"); }
else
{ echo nl2br("");}
$city = mysqli_real_escape_string($conn, $_POST['city']);
$date1 = mysqli_real_escape_string($conn, $_POST['date1']);
$date2 = mysqli_real_escape_string($conn,$_POST['date2']);
$pet = mysqli_real_escape_string($conn, $_POST['pet']);
//var_dump($date2);
$sql = "SELECT CONCAT(s.lname, ' ', s.fname) AS fullName, s.ratings, s.rate, s.phone, s.address FROM Pet_Sitter AS s WHERE s.citystate='".$city."' AND s.pet_type='".$pet."' "
;
//echo $sql."<br/>";
$result = mysqli_query($conn,$sql);
if (!$result) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
if ($result=mysqli_query($conn,$sql))
{
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
printf("");
}
//var_dump($result);
$num_rows = mysqli_num_rows($result);
?> <div class="container"> <?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
//var_dump($row);
// echo "<tr><td>" . $row['fullName'] . " </td><td>" . $row['ratings'] . " </td><td>" . $row['rate'] . " </td></tr>";
// echo '<div class="listing-item">';
echo '<div class="listing-item">';
echo '<article class="geodir-category-listing fl-wrap">';
echo '<div class="geodir-category-img">';
echo '<img src="../images/all/1.jpg" alt="">';
echo '<div class="overlay"></div>';
echo '<div class="list-post-counter"><span>' . $row['rate'] . '</span></div>';
echo '</div>';
echo '<div class="geodir-category-content fl-wrap">';
echo '<a class="listing-geodir-category" href="../index.html">Pet sitting</a>';
echo '<h3>' . $row['fullName'] . '</h3>';
echo '<p>PET-SITTER INFORMATION</p>';
echo '<div class="geodir-category-options fl-wrap">';
echo '<span>' . 'Reviews ' . $row['ratings'] .'</span>';
echo '<div class="geodir-category-location">'. $row['address'] . " ยท " . $row['phone'] .
'</div>';
echo '</div>';
echo '</div>';
echo '</article>';
echo '</div>';
}?>
<?php
} else {
echo "0 results";
}
mysqli_close($conn);
?>
</div>
</div>
An easy way to do it is to create one page (the one you wanna go if you click on your items) and use GET on URL to get the page id;
On your actual page you will use a link like :
<a href="new-page.php?id=<?php echo $row['id']; ?>"
Here the ?id= on URL is a parameter, that you can get on the other page :
$pageId = $_GET['id'];
Then, you just have to make a SQL request
SELECT * FROM Pet_Sitter WHERE id=$pageId
(better to use prepare and execute for this request as the value of $pageId can be change by everybody by changing the URL).
So every time you click on a link, the page will display the matching informations.
Also you should closed <?php when you are writing HTML instead of using a lot of echo.

if stamement not working against db query

I am running the code below but can't get the if statement to work. I want to be able to remove the div if there is no content and if there is then to display it but at the moment it either removes it all if one db entry is empty instead of just removing the 1 empty row.
<?php
$con = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
extract($_GET);
{ $result = mysqli_query($con,"SELECT * FROM links ORDER by id ");
while($row = mysqli_fetch_array($result)) {
if ($section=""){
echo"";
}
elseif ($section="a"){
echo"<div class=\"page-header\">" . $row['section'] . "\</div>";
}
echo "<div class=\"links-wrap\">
<div class=\"links-box\">
<div class=\"links-image\"><img src=\"images/links/" . $row['img1'] . "\"></div>
<div class=\"links-site-txt\">" . $row['link1'] . "</div>
<div class=\"links-desc\">" . $row['desc1'] . "</div>
</div>
<div class=\"spacer-left\"></div>
<div class=\"links-box\"></div>
<div class=\"spacer-left\"></div>
<div class=\"links-box\"></div>
</div>";}}
mysqli_close($con);
?>
<?php
$con = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
extract($_GET);
{ $result = mysqli_query($con,"SELECT * FROM links ORDER by id ");
while($row = mysqli_fetch_array($result)) {
if ( $section == "" ){ //double equality for condition check
echo "";
}
else if ($section == "a" ){
echo"<div class=\"page-header\">" . $row['section'] . "\</div>";
}
echo "<div class=\"links-wrap\">
<div class=\"links-box\">
<div class=\"links-image\"><img src=\"images/links/" . $row['img1'] . "\"></div>
<div class=\"links-site-txt\">" . $row['link1'] . "</div>
<div class=\"links-desc\">" . $row['desc1'] . "</div>
</div>
<div class=\"spacer-left\"></div>
<div class=\"links-box\"></div>
<div class=\"spacer-left\"></div>
<div class=\"links-box\"></div>
</div>";}}
mysqli_close($con);
?>
To compare value by if or elseif == is required not =. = generally use to assign value to a variable. Change your codes like below.
$con = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
extract($_GET);
$result = mysqli_query($con,"SELECT * FROM links ORDER by id ");
while($row = mysqli_fetch_array($result)) {
$section = $row['section'];
if ($section == ""){
echo "";
}
elseif ($section == "a"){
echo"<div class=\"page-header\">" . $row['section'] . "\</div>";
}
echo "<div class=\"links-wrap\">
<div class=\"links-box\">
<div class=\"links-image\"><img src=\"images/links/" . $row['img1'] . "\"></div>
<div class=\"links-site-txt\">" . $row['link1'] . "</div>
<div class=\"links-desc\">" . $row['desc1'] . "</div>
</div>
<div class=\"spacer-left\"></div>
<div class=\"links-box\"></div>
<div class=\"spacer-left\"></div>
<div class=\"links-box\"></div>
</div>";
}
mysqli_close($con);

SQL Request and Display

I'm trying to display database entries on a page in an unordered list. I'm echoing my rows in my li's, my sql connection seems fine... I don't understand where I went wrong... Does anyone have an idea?
<body class="projects">
<?php
$mysqli = new mysqli("localhost", "root", "root", "project");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query = "SELECT * FROM companies";
$result = $mysqli->query($query);
?>
<div id="projects" class="container">
<h1>Projects</h1>
<?php
while($row = $result->fetch_row());
?>
<ul>
<li>
<h2><?php echo $row['name']; ?></h2>
<p><?php echo $row['description']; ?></p>
</li>
</ul>
</div>
<?php
$result->close();
$mysqli->close();
?>
</body>
<ul>
<?php
while($row = $mysqli->fetch_row($result)) {
echo "<li>
<h2>".$row['name']."</h2>
<p>".$row['description']."</p>
</li>";
}
?>
</ul>
Or you can wrap the echo with {$row['item']} instead of what I did above with going in and out of HTML.

Show all fields based on ID

I am building a blog and trying to show all comments that apply to the post.
Each post has an ID and each comment is stored with the post ID.
here is my code:
<?php
$con = mysql_connect("localhost","cl49-XXX-b","X");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cl49-XXX-b", $con)or die( "Unable to select database line 873");
$result=mysql_query("SELECT * FROM blogcomments WHERE ID='".$ID."'") or die('Error on Line 215 :'.mysql_error());
echo " <ul class='comments'> "; // first row beginning
for ($i = 1; $i <= mysql_num_rows($result); $i++)
{
$row = mysql_fetch_array($result);
$name = $row['name'];
$email = $row['email'];
$comment = $row['comment'];
$created=$row['created'];
echo" <li>
<div class='comment'>
<div class='thumbnail'>
<img class='avatar' alt='' src='img/avatar.jpg'>
</div>
<div class='comment-block'>
<div class='comment-arrow'></div>
<span class='comment-by'>
<strong>$name</strong>
<span class='pull-right'>
<span> <a href='#'><i class='icon-reply'></i> Reply</a></span>
</span>
</span>
<p>$comment</p>
<span class='date pull-right'>$created</span>
</div>
</div> ";
echo " </li>"; // it's time no move to next row
}
?>
When I run this code the page only shows one comment, although my DB has 3 comments with the correct ID.
I would consider using mysqli_ as mysql_ has been depreciated. I'd also consider using a while loop, hopefully this will help:
<?php
$DBServer = 'localhost';
$DBUser = 'xxxx';
$DBPass = 'xxxx';
$DBName = 'xxxx';
$mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if ($mysqli->connect_errno) {
echo "Failed to connect to the database: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$query = "SELECT * FROM blogcomments WHERE ID='". $ID ."'";
echo " <ul class='comments'> ";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
?>
<li>
<div class='comment'>
<div class='thumbnail'>
<img class='avatar' alt='' src='img/avatar.jpg'>
</div>
<div class='comment-block'>
<div class='comment-arrow'></div>
<span class='comment-by'>
<strong><?php echo $row['name']; ?></strong>
<span class='pull-right'>
<span><a href='#'><i class='icon-reply'></i> Reply</a></span>
</span>
</span>
<p><?php echo $row['comment']; ?></p>
<span class='date pull-right'><?php echo $row['created']; ?></span>
</div>
</div>
</div>
</li>
<?php
} $result->close();
} $mysqli ->close();
echo "</ul>";
?>
I haven't tested this for bugs, but let me know if you like further information.
When you do this :
mysql_query("SELECT * FROM blogcomments WHERE ID='".$ID."'")
You select just one comment in the database.
Maybe you have to do that :
mysql_query("SELECT * FROM blogcomments WHERE post_ID='".$post_ID."'")
Because you are selecting the row where ID field value is $ID in the table blogcomments.
I guess you store the referred post_id to whom the comment is connected in a field called something like "post_id". You better point your select query to that field ;)
If you put the structure of the table in the question, I might help :)
You're not closing your <ul>. Might it just be a HTML formatting issue?

when no rows retrieved from SQL database then dont display a div

i tried the empty selector in jquery but it doesnt work. the content is still being displayed. i am retrieving some rows from the SQL database.. if there is no database then i dont want to display that div.
<div id="scrollingText">
<div class="scrollWrapper">
<div class="scrollableArea">
<marquee behavior="scroll" direction="left">
<p>
<?php
$con = mysql_connect("localhost","fraptech_test","");
mysql_select_db("fraptech_test", $con);
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysql_select_db("fraptech_ndsnotice", $con);
$result = mysql_query("SELECT * FROM ndsnotice");
while($row = mysql_fetch_array($result))
{
echo $row['Notice'];
}
?>
</p>
</marquee>
</div>
</div>
</div>
Is that your whole code? Are you working with ajax? If you're using pure PHP without ajax just set the output div into your "if"-conditions?
If you want to use jQuery, try:
if ( ($("div.scrollableArea p").text()).length > 0 )
{
$("div.scrollableArea p").show();
}
else
{
$("div.scrollableArea p").hide();
}
But you can do it without jQuery, I guess.
You need to put the HTML inside your php if clause.
Simple example:
<div id="scrollingText">
<?php
$con = mysql_connect("localhost","fraptech_test","");
mysql_select_db("fraptech_ndsnotice", $con);
$result = mysql_query("SELECT * FROM ndsnotice");
if (mysqli_connect_errno($con)) {
<div class="scrollWrapper">
<div class="scrollableArea">
<marquee behavior="scroll" direction="left">
<p>
<?php
while($row = mysql_fetch_array($result))
{
echo $row['Notice'];
}
?>
</p>
</marquee>
</div>
</div>
<?php } else { ?>
<div class="errordiv">Display this on error</div>
<?php } ?>
</div>
thank you guys with ur help i made some change. the below code did it:
<?php
$con = mysql_connect("localhost","fraptech_test","");
mysql_select_db("fraptech_test", $con);
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysql_select_db("fraptech_ndsnotice", $con);
$result = mysql_query("SELECT * FROM ndsnotice");
if (mysql_num_rows($result) > 0)
{
?><div id="scrollingText">
<div class="scrollWrapper">
<div class="scrollableArea">
<marquee behavior="scroll" direction="left">
<p>
<?php while($row = mysql_fetch_array($result))
{
echo $row['Notice'];
}
?> </p>
</marquee>
</div>
</div>
</div>
<?php } ?>

Categories