Jump to content

Recommended Posts

<?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.

Link to comment
https://forums.phpfreaks.com/topic/232376-my-code-isnt-working/
Share on other sites

$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

<?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

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

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.

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

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

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.

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

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?

 

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.

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...

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.

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.