Jump to content

Checking This Code...


wright67uk

Recommended Posts

I have two similar bits of code.

One works and one doesn't.

 

Can you spot any errors?

 

The first piece works well in the jquery app and the second outputs but doesn't load the app.

Im guessing its a jquery issue, but thought it would be best to double check my php first.

 

<!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>
<script type="text/javascript" charset="utf-8" src="jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery.dataTables.js"></script>
<link rel="stylesheet" type="text/css" href="demo_table.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type=”text/css”>
.sort{font-size:9px;}
table.tablesorter .header {
background-image: url(“/path/to/bg.png”);
background-repeat: no-repeat;
padding-left: 30px;
padding-top: 8px;
width:auto;
}
table.tablesorter th.no_sort {
background-image: url(“/path/to/header.PNG”);
}
table.tablesorter .headerSortUp {
background-image: url(“/path/to/asc.png”);
background-repeat: no-repeat;
}
table.tablesorter .headerSortDown {
background-image: url(“/path/to/desc.png”);
background-repeat: no-repeat;
}
table.tablesorter .even {
background-color: #9999CC;
}
table.tablesorter .odd {
background-color: #FFFFFF;
}
</style>
<script type="text/javascript">
<!--jQuery.noConflict();->
var $j = jQuery.noConflict();
$j (document).ready(function() {
//$j (“#table_id”).tablesorter({widgets: ['zebra']});
$j ("#table_id").tablesorter();
}
);
</script>
</head>
<body>
<?php
#connection#
$connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);
@mysql_select_db($database_connect) or die (mysql_error());
$tbl_name = "snag_score";
$result = mysql_query("SELECT * FROM $tbl_name");
//change the next line to this
echo('<table id="table_id" class="display">
<thead><tr>
<th>id</th>
<th>user_id</th>
<th>year</th>
<th>total_score</th>
<th>date</th>
</tr></thead><tbody>'
);
while($row=mysql_fetch_array($result)) {
$id=$row["id"];
$user_id=$row["user_id"];
$year=$row["year"];
$total_score=$row["total_score"];
$r_date=$row["r_date"];

echo
"<tr>
<td>$id</td>
<td>$user_id</td>
<td>$year</td>
<td>$total_score</td>
<td>$r_date</td>
</tr>";
}
echo('</tbody></table>');
?>

 

and the piece that isnt working in jquery;

 

 

 

<!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>
<script type="text/javascript" charset="utf-8" src="jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery.dataTables.js"></script>


<link rel="stylesheet" type="text/css" href="demo_table.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type=”text/css”>
.sort{font-size:9px;}
table.tablesorter .header {
background-image: url(“/path/to/bg.png”);
background-repeat: no-repeat;
padding-left: 30px;
padding-top: 8px;
width:auto;
}
table.tablesorter th.no_sort {
background-image: url(“/path/to/header.PNG”);
}
table.tablesorter .headerSortUp {
background-image: url(“/path/to/asc.png”);
background-repeat: no-repeat;
}
table.tablesorter .headerSortDown {
background-image: url(“/path/to/desc.png”);
background-repeat: no-repeat;
}
table.tablesorter .even {
background-color: #9999CC;
}
table.tablesorter .odd {
background-color: #FFFFFF;
}
</style>

<script type="text/javascript">
<!--jQuery.noConflict();->
var $j = jQuery.noConflict();

$j (document).ready(function() {
//$j (“#table_id”).tablesorter({widgets: ['zebra']});

$j ("#table_id").tablesorter();
}
);
</script>

</head>
<body>

<?php
#connection

$connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);

@mysql_select_db($database_connect) or die (mysql_error());


$result = mysql_query
("SELECT
registration.fname,
registration.lname,
snag.club,
snag.sdate,
snag.yard,
snag.year
FROM registration, snag
WHERE registration.user_id = snag.user_id");

echo
('<table id="table_id" class="display"><thead><tr>
<th>fname</th>
<th>lname</th>
<th>Club</th>
<th>sdate</th>
<th>yard</th>
<th>year</th>
</tr></thead><tbody>'

);
while($row=mysql_fetch_array($result)) {
$fname=$row["fname"];
$lname=$row["lname"];
$club=$row["club"];
$sdate=$row["sdate"];
$yard=$row["yard"];
$year=$row["year"];

echo
"<tr>
<td>$fname</td>
<td>$lname</td>
<td>$club</td>
<td>$sdate</td>
<td>$yard</td>
<td>$year</td>
</tr>";
}
echo('</tbody></table>');
?>

Link to comment
Share on other sites

"Im guessing its a jquery issue, but thought it would be best to double check my php first"

.....

 

I know that this is a php forum, its just that I thought I might of made a mistake with the php section of the file. I can't understand why jQuery would work for the first file and not the second, whilst jQuery is seeing the same output.

Link to comment
Share on other sites

You can not select form two tables like that, if you echoed mysql error you would see an error.

I'm afraid that this statement is false. You can indeed JOIN two tables in this way, it's just not advisable. For one it's a lot harder to read, especially if you have something more advanced than the most basic of joins. Secondly it's very easy to make it a cross-join (or end up with other unwanted results), mainly because of it's harder to read syntax.

This is commonly known as the "implicit JOIN syntax".

 

That said: It's highly recommended to stick with the proper ANSI syntax for JOINs, it'll save you a LOT of headaches.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.