dhpr111 Posted April 1, 2011 Share Posted April 1, 2011 <?php require_once("includes/connection.php");?> <html> <head> <style type="text/css"> <!-- a:link { color: #000000; text-decoration: none; } a:visited { text-decoration: none; color: #000000; } a:hover { text-decoration: underline; color: #FFFFFF; } a:active { text-decoration: none; color: #000000; } a { font-family: Courier New, Courier, monospace; } body,td,th { font-family: Courier New, Courier, monospace; font-size: 18px; } .style1 {font-size: 40px} #one { text-align:center; vertical-align:top; } #parent { position:absolute; left:60px; font-size:14px; } --> </style> </head> <body> <table width="100%" height="888" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="186" colspan="2" bgcolor="#CCCCCC"><div align="center" class="style1">DOWNLOAD TREASURE </div></td> </tr> <tr> <td id="one" width="16%" bgcolor="#99CCFF" ><?php $result =mysql_query("SELECT * FROM subjects",$connection); if(!$result){ die("connection error : ".mysql_error()); } while($row = mysql_fetch_array($result)){ echo $row["menu_name"]."<br/>"; } $parent = mysql_query("SELECT * FROM pages WHERE subject_id = {$row["id"]}" ,$connection); if(!$parent){ die("connection error : ".mysql_error()); } while($rowone = mysql_fetch_array($parent)){ echo $rowone["menu_name"]; } ?></td> <td width="84%"> </td> </tr> </table> </body> </html> is there any mistake here.it is a big help for me. Quote Link to comment Share on other sites More sharing options...
dhpr111 Posted April 1, 2011 Author Share Posted April 1, 2011 please help me Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted April 1, 2011 Share Posted April 1, 2011 Post your code inside code brackets. It makes it easier to read and you have more chance or a response. Quote Link to comment Share on other sites More sharing options...
nomadsoul Posted April 1, 2011 Share Posted April 1, 2011 Also, post any error messages Quote Link to comment Share on other sites More sharing options...
j9sjam3 Posted April 1, 2011 Share Posted April 1, 2011 $parent = mysql_query("SELECT * FROM pages WHERE subject_id = {$row["id"]}" ,$connection); Use: <?php $parent = mysql_query("SELECT * FROM pages WHERE subject_id = ".$row['id'], $connection) or die(mysql_error($connection)); Using "or die" statements help a lot with debugging. Edit: fixed typo Quote Link to comment Share on other sites More sharing options...
dhpr111 Posted April 1, 2011 Author Share Posted April 1, 2011 <?php $result =mysql_query("SELECT * FROM subjects",$connection); if(!$result){ die("connection error : ".mysql_error()); } while($row = mysql_fetch_array($result)){ echo $row["menu_name"]."<br/>"; } $parent = mysql_query("SELECT * FROM pages WHERE subject_id = {$row['id']}" ,$connection); if(!$parent){ die("connection error : ".mysql_error()); } while($rowone = mysql_fetch_array($parent)){ if($parent==$row["id"]){ echo $rowone["menu_name"]; } } ?> please help me this is the error message You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 1, 2011 Share Posted April 1, 2011 Put your queries into variables so you can echo them out when you get an error, this way you will know which query caused the error. Something like this: <?php $q = "SELECT * FROM pages WHERE subject_id = {$row['id']}"; $rs = mysql_query($q) or die("Problem with the query: $q at line " . __LINE__ . '<br>' . mysql_error()); ?> Ken Quote Link to comment Share on other sites More sharing options...
dhpr111 Posted April 1, 2011 Author Share Posted April 1, 2011 Put your queries into variables so you can echo them out when you get an error, this way you will know which query caused the error. Something like this: <?php $q = "SELECT * FROM pages WHERE subject_id = {$row['id']}"; $rs = mysql_query($q) or die("Problem with the query: $q at line " . __LINE__ . '<br>' . mysql_error()); ?> Ken $q = "SELECT * FROM pages WHERE subject_id = {$row['id']"; this line has the error. Quote Link to comment Share on other sites More sharing options...
j9sjam3 Posted April 1, 2011 Share Posted April 1, 2011 mysql_query("SELECT * FROM pages WHERE subject_id = '".$row['id']."', $connection) or die(mysql_error($connection)); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 1, 2011 Share Posted April 1, 2011 Using the "{}" around an array reference within a string delimited by double quotes is fine. With MySQL you don't need to include the connection in the MySQL function call, it is optional. You need to include it in the MySQLi function call. To the OP, please use my code and post the exact message that is displayed on the browser and please don't SHOUT. Ken Quote Link to comment Share on other sites More sharing options...
dhpr111 Posted April 1, 2011 Author Share Posted April 1, 2011 Using the "{}" around an array reference within a string delimited by double quotes is fine. With MySQL you don't need to include the connection in the MySQL function call, it is optional. You need to include it in the MySQLi function call. To the OP, please use my code and post the exact message that is displayed on the browser and please don't SHOUT. Ken This is the error Parse error: syntax error, unexpected '"', expecting '}' in C:\wamp\www\downloads\index.php on line 69 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 1, 2011 Share Posted April 1, 2011 If this is the line <?php $q = "SELECT * FROM pages WHERE subject_id = {$row['id']"; ?> you're missing the terminating "}" after the "]": <?php $q = "SELECT * FROM pages WHERE subject_id = {$row['id']}"; ?> Ken Quote Link to comment Share on other sites More sharing options...
dhpr111 Posted April 2, 2011 Author Share Posted April 2, 2011 If this is the line <?php $q = "SELECT * FROM pages WHERE subject_id = {$row['id']"; ?> you're missing the terminating "}" after the "]": <?php $q = "SELECT * FROM pages WHERE subject_id = {$row['id']}"; ?> Ken still it isn't working friend.. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 2, 2011 Share Posted April 2, 2011 You have to explain why it's not working. "still isn't working" doesn't tell us very much. PHP errors? MySQL errors? Logic errors? Ken Quote Link to comment Share on other sites More sharing options...
dhpr111 Posted April 3, 2011 Author Share Posted April 3, 2011 You have to explain why it's not working. "still isn't working" doesn't tell us very much. PHP errors? MySQL errors? Logic errors? Ken error message is the same.I mentioned above it. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 3, 2011 Share Posted April 3, 2011 Which one? We aren't mind readers, you know. How about posting the current code and any errors it's currently returning. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 3, 2011 Share Posted April 3, 2011 There have been at least two different error messages mentioned above. In programming help forums, you must be exact in your statement of what your code is doing or not doing and what you specifically need help with because we are not standing right next to you. So, statements like 'still it isn't working' and 'mentioned above' when more than one error/problem has been mentioned above are a pointless waste of bandwidth. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 3, 2011 Share Posted April 3, 2011 Please post your current code. Ken Quote Link to comment Share on other sites More sharing options...
dhpr111 Posted April 3, 2011 Author Share Posted April 3, 2011 Please post your current code. Ken <?php $result =mysql_query("SELECT * FROM subjects",$connection); if(!$result){ die("connection error : ".mysql_error()); } while($row = mysql_fetch_array($result)){ echo $row["menu_name"]."<br/>"; } $q = "SELECT * FROM pages WHERE subject_id = {$row['id']}"; $parent = mysql_query($q,$connection); if(!$parent){ die("connection error : ".mysql_error()); } while($rowone = mysql_fetch_array($parent)){ if($parent==$row["id"]){ echo $rowone["menu_name"]; } } ?> This is the error message. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment Share on other sites More sharing options...
blacknight Posted April 3, 2011 Share Posted April 3, 2011 im using the same web server for windows you are try full formatting my sql $q = "SELECT * FROM `pages` WHERE `subject_id` = '".$row['id']."' "; Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 3, 2011 Share Posted April 3, 2011 In reply #6 in this thread, kenrbnsn posted some code that would have displayed the actual sql that is failing. However, I'll take a guess that the error means that $row['id'] is empty. Do you even have a column named id in your subjects table? Quote Link to comment Share on other sites More sharing options...
dhpr111 Posted April 3, 2011 Author Share Posted April 3, 2011 In reply #6 in this thread, kenrbnsn posted some code that would have displayed the actual sql that is failing. However, I'll take a guess that the error means that $row['id'] is empty. Do you even have a column named id in your subjects table? yep.It has the primary key.actually this is what I want to do.I want to create a navigation menu.and subject means main items.so I want to relate pages to the exact subject.It means pages are sub items of subjects.for this I want to create a relationship with two tables(subjects and pages)in the subject table it has field called id with the primary key.And for creating the relationship I created a new field in the pages table called subject_id.so I'm trying to create the relationship with these two fields.Are there any other way of doing this?I mean for creating a navigation menu with sub menu items. Quote Link to comment Share on other sites More sharing options...
blacknight Posted April 3, 2011 Share Posted April 3, 2011 i think i understand Subjects id | name|.. 1 | bobs | x | x Pages subject_id | name |.. if im correct you want to list each catagory with its subcatagories? try this.. while($row = mysql_fetch_array($result)){ echo $row["menu_name"]."<br/>"; $parent = mysql_query("SELECT * FROM `pages` WHERE `subject_id` = '".$row["id"]."' " ,$connection); if(!$parent){ die("connection error : ".mysql_error()); } while($rowone = mysql_fetch_array($parent)){ echo $rowone["menu_name"]; } echo '<br><hr><br>'; } your parent query is failing because you closed $row['id'] when you closed teh where statement this will loop each subject and then list each page for it under it end with a echo '<br><hr><br> so sep them for the nest then you can do your formatting try this i could be wrong... Quote Link to comment Share on other sites More sharing options...
dhpr111 Posted April 3, 2011 Author Share Posted April 3, 2011 i think i understand Subjects id | name|.. 1 | bobs | x | x Pages subject_id | name |.. if im correct you want to list each catagory with its subcatagories? try this.. while($row = mysql_fetch_array($result)){ echo $row["menu_name"]."<br/>"; $parent = mysql_query("SELECT * FROM `pages` WHERE `subject_id` = '".$row["id"]."' " ,$connection); if(!$parent){ die("connection error : ".mysql_error()); } while($rowone = mysql_fetch_array($parent)){ echo $rowone["menu_name"]; } echo '<br><hr><br>'; } your parent query is failing because you closed $row['id'] when you closed teh where statement this will loop each subject and then list each page for it under it end with a echo '<br><hr><br> so sep them for the nest then you can do your formatting try this i could be wrong... Thanx for your reply.but it isn't working frnd.But one improvement is there.Your code doesn't give an error message.The problem is,it echo back the main menu items only.It doesn't echo back pages. Quote Link to comment Share on other sites More sharing options...
blacknight Posted April 3, 2011 Share Posted April 3, 2011 befor echo $rowone["menu_name"]; put print_r($rowone); that will give you the values you can call from that query.. Quote Link to comment 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.