wright67uk Posted December 11, 2012 Share Posted December 11, 2012 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>'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/271854-checking-this-code/ Share on other sites More sharing options...
MDCode Posted December 11, 2012 Share Posted December 11, 2012 You can not select form two tables like that, if you echoed mysql error you would see an error. Quote Link to comment https://forums.phpfreaks.com/topic/271854-checking-this-code/#findComment-1398690 Share on other sites More sharing options...
wright67uk Posted December 11, 2012 Author Share Posted December 11, 2012 Ok, I was unaware of this. Although it does still output from two tables? Eg. www.treequoter.co.uk/tabledisplay.php But not working; www.treequoter.co.uk/tabledisplay2.php I tested the sql in phpadmin and it seemed ok. How do I do this query correctly? Quote Link to comment https://forums.phpfreaks.com/topic/271854-checking-this-code/#findComment-1398699 Share on other sites More sharing options...
trq Posted December 11, 2012 Share Posted December 11, 2012 How do you expect us to help without a description of your problem? Quote Link to comment https://forums.phpfreaks.com/topic/271854-checking-this-code/#findComment-1398712 Share on other sites More sharing options...
wright67uk Posted December 11, 2012 Author Share Posted December 11, 2012 One piece of code loads a sortable table, but the other one doesnt. The two links above display the files. The two files are similar, and I can't understand why jQuery processes one and not the other. Why is this? And is my code above written correctly? Quote Link to comment https://forums.phpfreaks.com/topic/271854-checking-this-code/#findComment-1398716 Share on other sites More sharing options...
trq Posted December 11, 2012 Share Posted December 11, 2012 So your issue is with jQuery? This is the php help forum. Quote Link to comment https://forums.phpfreaks.com/topic/271854-checking-this-code/#findComment-1398727 Share on other sites More sharing options...
wright67uk Posted December 11, 2012 Author Share Posted December 11, 2012 "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. Quote Link to comment https://forums.phpfreaks.com/topic/271854-checking-this-code/#findComment-1398736 Share on other sites More sharing options...
Christian F. Posted December 12, 2012 Share Posted December 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271854-checking-this-code/#findComment-1398872 Share on other sites More sharing options...
wright67uk Posted December 12, 2012 Author Share Posted December 12, 2012 Thank you Christian, I will do some more reading on the ANSI syntax. Quote Link to comment https://forums.phpfreaks.com/topic/271854-checking-this-code/#findComment-1399027 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.