Good afternoon Stackoverflow,
Today I got f'd by IE as usual when using the jQuery library with Ajax.
So whats my problem, well take a look at my live demo: http://194.247.30.66/~keizer/iemakesmesad/
Try ordening the items in FF / Chrome, then test it in IE and we'll all facepalm because of Bill Gates.
Possible explanation: IE grabs the whole ul instead of the ul inside the ul.. any solution?
Code of index.php
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
// When the document is ready set up our sortable with it's inherant function(s)
$(document).ready(function() {
<?php
include_once("../ond/inc/php/connect.php");
$i = 0;
$result = mysql_query("SELECT * FROM paginas WHERE type='0' ORDER BY id ASC");
while($row = mysql_fetch_array($result))
{
$i++;
$result2 = mysql_query("SELECT * FROM paginas WHERE type=".$row{"id"}." ORDER BY id ASC LIMIT 1");
while($row2 = mysql_fetch_array($result2))
{
echo ' $("#submenu_list'.$i.'").sortable({
handle : \'.handle\',
update : function () {
var order = $(\'#submenu_list'.$i.'\').sortable(\'serialize\');
$("#info").load("process-sortable.php?"+order);
}
});
';
}
}
?>
$("#menu_list").sortable({
handle : '.handle',
update : function () {
var order = $('#menu_list').sortable('serialize');
$("#info").load("process-sortable.php?"+order);
}
});
});
</script>
</head>
<body>
<?php
$result = mysql_query("SELECT * FROM paginas_test WHERE type='0' ORDER BY position ASC");
echo '<table cellspacing="2" cellpadding="2">';
echo ' <tr>';
echo ' <th colspan="2" scope="col"><img src="../ond/inc/afb/report.png" />Volgordebepaling</th>';
echo ' </tr>';
echo '</table>';
echo '<ul id="menu_list">';
$i = 0;
while ($row = mysql_fetch_array($result))
{
$i++;
echo '<li style="list-style:none;" id="listItem_'.$row{"id"}.'">';
echo ' <img src="../testajax/arrow.png" alt="move" width="16" height="16" class="handle" /> '.$row{"titel"}.'<br />';
#mysql_query("SELECT * FROM paginas WHERE type='0' ORDER BY id ASC");
$result2 = mysql_query("SELECT * FROM paginas_test WHERE type=".$row{"id"}." ORDER BY position ASC");
echo '<ul id="submenu_list'.$i.'">';
while($row2 = mysql_fetch_array($result2))
{
echo '<li style="list-style:none;margin-left:15px;" id="sublistItem_'.$row2{"id"}.'">';
echo '<img src="../testajax/arrow.png" alt="move" width="16" height="16" class="handle" /> '.$row2{"titel"}.'<br />';
echo '</li>';
}
echo '</ul></li>';
}
echo '</ul>';
echo '<div id="info"></div>';
?>
</body>
</html>
Code of process-sortable.php:
<?php
include("../ond/inc/php/connect.php");
if(isset($_GET['listItem']))
{
foreach ($_GET['listItem'] as $position => $item)
{
$sql = "UPDATE `paginas_test` SET `position` = $position WHERE `id` = $item";
mysql_query($sql);
}
}
if(isset($_GET['sublistItem']))
{
foreach ($_GET['sublistItem'] as $position2 => $item2)
{
$sql = "UPDATE `paginas_test` SET `position` = $position2 WHERE `id` = $item2";
mysql_query($sql);
}
}
print_r ($sql);
?>
check this one: jQuery unexpected sortable behaviour
Related
<?php
require "includes/dbh_l4d2.php";
$sql = "
SELECT *
FROM vpk
JOIN maps
ON vpk.vpk_id = maps.vpk_id";
$result = mysqli_query($conn, $sql);
?>
<!DOCTYPE html><html><head><title>Website Title</title>
<link rel = "stylesheet" type = "text/css" href = "assets/css/tek_style.css" /></head>
<body>
<table>
<tr><th>VPK</th><th>MAP</th></tr>
<?php
$result_num_rows = mysqli_num_rows($result);
if( $result_num_rows> 0) {
//while($row = mysqli_fetch_array($result)) {
while($row = $result->fetch_assoc()) {
echo '<tr><td id="'.$row["alpha_anchor"].'" rowspan="'.$row["map_count"].'" class="first_row">'.
'<h3 id="'.$row["anchor"].'">'.$row["vpk_title"].'</h3>'.$row["vpk_file"].'<br>'.
'<a class="details" href="'.$row[details].'">Details</a> '.
'<i>Download vpk</i>'.
'</td></tr>';
for ($i=0; $i < $row["map_count"]-1; $i++) {
echo '<tr><td>'.$row["map_name"].'></td></tr>';
}
}
}
?>
</table></body></html>
Here is the output from the code
This is what I want it to look like
What needs to be done to make this work correctly??? Thanks in advance for any help.
Your nested loop is getting map_name from the same row, not each row of results.
What you can do is use GROUP_CONCAT() to combine all the map names into a single row of results, then use explode() to split them up when creating the table.
<?php
require "includes/dbh_l4d2.php";
$sql = "SELECT vpk.*, GROUP_CONCAT(maps.map_name) AS map_names
FROM vpk
INNER JOIN maps ON vpk.vpk_id = maps.vpk_id
GROUP BY vpk.vpk_id";
//$sql = "SELECT * FROM vpk, maps JOIN vpk ON vpk.vpk_id = maps.vpk_id";
$result = mysqli_query($conn, $sql);
?>
<!DOCTYPE html><html><head><title>Website Title</title>
<link rel = "stylesheet" type = "text/css" href = "assets/css/tek_style.css" /></head>
<body>
<table>
<tr><th>VPK</th><th>MAP</th></tr>
<?php
$result_num_rows = mysqli_num_rows($result);
if( $result_num_rows> 0) {
//while($row = mysqli_fetch_array($result)) {
while($row = $result->fetch_assoc()) {
$map_names = explode(',', $row['map_names']);
echo '<tr><td id="'.$row["alpha_anchor"].'" rowspan="'.$row["map_count"].'" class="first_row">'.
'<h3 id="'.$row["anchor"].'">'.$row["vpk_title"].'</h3>'.$row["vpk_file"].'<br>'.
'<a class="details" href="'.$row[details].'">Details</a> '.
'<i>Download vpk</i>'.
'</td></tr>';
foreach ($map_names as $map_name) {
echo '<tr><td>'.$map_name.'></td></tr>';
}
}
}
?>
</table></body></html>
Imagine that I have 1 2 3 4pages in my table, then if I click the page 1 the number 1 will be background: black Then the problem is the whole pages will be black, when I executing. Please help me out of this problem. I want to change the background color of the page if what page I click. Tyia
Here's the code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<div class="table-responsive" id="pagination_data"></div>
<script>
$(document).ready(function(){
load_data();
function load_data(page)
{
$.ajax({
url:"pagination.php",
method:"POST",
data:{page:page},
success:function(data){
$('#pagination_data').html(data);
$(".pagination_link").css({"background":, "black"});
}
})
}
$(document).on('click', '.pagination_link', function(){
var page = $(this).attr("id");
load_data(page);
$(".pagination_link").css({"background":, "black"});
});
});
</script>
PHP code:
<?php
//pagination.php
$connect = mysqli_connect("localhost", "root", "", "psbr");
$record_per_page = 6;
$page = '';
$output = '';
if(isset($_POST["page"]))
{
$page = $_POST["page"];
}
else
{
$page = 1;
}
$start_from = ($page - 1)*$record_per_page;
$query = "SELECT * FROM accounts ORDER BY id DESC LIMIT $start_from, $record_per_page";
$result = mysqli_query($connect, $query);
$output .= "
<div class='grid-container'>
";
while($row = mysqli_fetch_array($result))
{
$output .= '
<div class="grid-content">
<img src="../accounts/table/upload/'.$row['image'].'" class="grid-image">
</div>
';
}
$output .= '</div> <br /><div align="right">';
$page_query = "SELECT * FROM accounts ORDER BY id DESC";
$page_result = mysqli_query($connect, $page_query);
$total_records = mysqli_num_rows($page_result);
$total_pages = ceil($total_records/$record_per_page);
for($i=1; $i<=$total_pages; $i++)
{
$output .= "<span class='pagination_link' id='".$i."'>".$i."</span>";
}
$output .= '</div><br /><br />';
echo $output;
?>
I'm not very sure how can I put them into words. I'm trying to display result in each div as shown in the image but unfortunately I'm only able to make it appear only in the "request for quote" div.
May I know where have I gone wrong?
<?php
$query2 = "SELECT * FROM client c, sales_card s WHERE c.id = s.client_id and emp_id_followup = '".$_SESSION["ID"]."'";
$result2 = mysql_query($query2);
if (mysql_num_rows($result2) > 0) {
while($row2 = mysql_fetch_assoc($result2)) {
$swimlaneID = $row2['swimlane_id'];
}
}
$query = "SELECT * FROM swimlane";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result)) {
echo '<div id="right">';
echo '<div style="border-style:solid; height:1020px;">';
echo '<h2>'. $row["swimlane_name"].'</h2>';
echo '<ul id="'. $row["shortform"].'">';
if ($swimlaneID == $row["id"])
{
echo $display-> $row["shortform"]();
}
echo '</ul>';
echo '</div>';
echo '</div>';
}
}else{
echo "no row";
}
?>
We have a basic PHP script to extract the title and description for each job from a MySQL database as simply display this information. This is what it looks like:
$sql = "SELECT `title`, `desc` FROM jobs WHERE active = 'y'";
$query = mysql_query($sql) or die('<em><strong>SQL Error:</strong> ' . mysql_error() . '</em>');
$results = mysql_fetch_assoc($query);
<?php while($result = mysql_fetch_assoc($query)) {
echo '<div class="left_content" style="margin-top: 15px;">';
echo "<h2>{$results['title']}</h2>";
echo "<p>{$results['desc']}</p>";
echo '</div>';
} ?>
Now, this only extracts one row from the database, but it should extract two. So, I tried the following to replace the while statement:
<?php foreach($results as $result) {
echo '<div class="left_content" style="margin-top: 15px;">';
echo "<h2>{$result['title']}</h2>";
echo "<p>{$result['desc']}</p>";
echo '</div>';
} ?>
This statement doesn't work either. This just displays (weirdly) the first character of each column in the first row in the table.
Does anyone have any idea as to why this isn't working as it should?
In your while use same variable $result as you started:
while($result = mysql_fetch_assoc($query)) {
echo '<div class="left_content" style="margin-top: 15px;">';
echo "<h2>{$result['title']}</h2>";
echo "<p>{$result['desc']}</p>";
echo '</div>';
}
and remove the first $results = mysql_fetch_assoc($query);
Result variable you have used is result not results
Replace
$sql = "SELECT `title`, `desc` FROM jobs WHERE active = 'y'";
$query = mysql_query($sql) or die('<em><strong>SQL Error:</strong> ' . mysql_error() . '</em>');
**$results = mysql_fetch_assoc($query);** // remove this line
<?php while($result = mysql_fetch_assoc($query)) {
echo '<div class="left_content" style="margin-top: 15px;">';
echo "<h2>{$results['title']}</h2>";
echo "<p>{$results['desc']}</p>";
echo '</div>';
} ?>
to
$sql = "SELECT `title`, `desc` FROM jobs WHERE active = 'y'";
$query = mysql_query($sql) or die('<em><strong>SQL Error:</strong> ' . mysql_error() . '</em>');
<?php while($result = mysql_fetch_assoc($query)) {
echo '<div class="left_content" style="margin-top: 15px;">';
echo "<h2>{$result['title']}</h2>";
echo "<p>{$result['desc']}</p>";
echo '</div>';
} ?>
You already fetched the first row before your loop started, which is why it only prints the second row. Simply comment out that line:
#$results = mysql_fetch_assoc($query); # here is your first row,
# simply comment this line
<?php while($result = mysql_fetch_assoc($query)) {
echo '<div class="left_content" style="margin-top: 15px;">';
echo "<h2>{$result['title']}</h2>";
echo "<p>{$result['desc']}</p>";
echo '</div>';
} ?>
You are also looping over $result but using $results in your while loop body.
Check this:
$sql = "SELECT `title`, `desc` FROM jobs WHERE active = 'y'";
$query = mysql_query($sql) or die('<em><strong>SQL Error:</strong> ' . mysql_error() . '</em>');
<?php
while($result = mysql_fetch_assoc($query)) {
echo '<div class="left_content" style="margin-top: 15px;">';
echo "<h2>{$result['title']}</h2>";
echo "<p>{$result['desc']}</p>";
echo '</div>';
}
?>
Change this line
<?php while($result = mysql_fetch_assoc($query)) {
to
<?php while($results = mysql_fetch_assoc($query)) {
I can't figure out how to format my table so that there is a header for each section of attributes. I only see one header when there are actually more that I need to see.
For example I'm able to get DROID 4 by MOTOROLA and all of it's attributes go from Full Retail Price to Voice Dialing. After Voice Dialing there should be a second header for another phone. Clearly my logic is messed up and I have been struggling for about 4 hours on it. I also need the two tables to be side by side, not in a long list like this.
This is what I'm trying to achieve:
My code looks like this:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="theme.css" />
</head>
<body>
<?php
include_once 'config.php';
$conf = new config();
mysql_connect($conf->getdbServ(), $conf->getdbUser(), $conf->getdbPwd()) or die(mysql_error());
mysql_select_db($conf->getDB()) or die(mysql_error());
$selectedPhones = $_POST['phones'];
$totalSelected = count($selectedPhones);
//echo $totalSelected;
$idList = "";
for($i=0;$i < $totalSelected; $i++){
$idList .= $selectedPhones[$i] . ",";
}
$idList = substr($idList,0,-1);
$query = "Select name from ".$conf->getproductTbl()." WHERE id='$idList'";
$res=mysql_query($query);
//echo $idList;
$data = mysql_query("SELECT ".$conf->getproductTbl().".id, ".$conf->getproductAttr().".* from ".$conf->getproductTbl()."
LEFT JOIN ".$conf->getproductAttr()." ON ".$conf->getproductTbl().".id=".$conf->getproductAttr().".prodFK
Where ".$conf->getproductTbl().".id IN(" . $idList . ");");
echo "<table width = 100% border = '1' cellspacing = '2' cellpadding = '0'>";
while ($result = mysql_fetch_assoc($res))
{
echo "<th colspan='2'>".$result["name"]."</th>";
}
while ($row = mysql_fetch_assoc($data)) {
echo "<tr><td>";
echo $row["Name"];
echo "</td><td>";
echo $row["value"];
echo "</td></tr>";
}
echo "</table>";
?>
</body>
</html>
1 - You might want to look into MYSQL JOIN to combine your two queries. (http://www.tizag.com/mysqlTutorial/mysqljoins.php)
2 - Use CSS to style your result set.
You can try something like this.. I hope that will help you.
<table>
<tr>
<?php
for($i=0;$i < $totalSelected; $i++){
//$idList .= $selectedPhones[$i] . ",";
?>
<td><?php
$data = mysql_query("SELECT ".$conf->getproductTbl().".id, ".$conf->getproductAttr().".* from ".$conf->getproductTbl()."
LEFT JOIN ".$conf->getproductAttr()." ON ".$conf->getproductTbl().".id=".$conf->getproductAttr().".prodFK
Where ".$conf->getproductTbl().".id = ".$selectedPhones[$i]);
echo "<table width = 100% border = '1' cellspacing = '2' cellpadding = '0'>";
while ($result = mysql_fetch_assoc($res))
{
echo "<th colspan='2'>".$result["name"]."</th>";
}
while ($row = mysql_fetch_assoc($data)) {
echo "<tr><td>";
echo $row["Name"];
echo "</td><td>";
echo $row["value"];
echo "</td></tr>";
}
echo "</table>";
?>
</td>
<?php }?>
</tr>
</table>