Jump to content

Mysql query problem to create menu


Go to solution Solved by dreamz boy,

Recommended Posts

i am new in programming and creating my first dynamic website. and problem i am facing is that when i parse the query in the php for menu of my website it gives only one menu link and hides the other pages created in the database.if i create a new page in mysql the parse code hides the previous page link in the menu and shows the newly created page link. i want to make that every page created in database link is shown in menu. and also guide me what changes i have to do if i want to make menu with sub menu option.thanks

here are the msql code

CREATE TABLE `pages` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `pagetitle` varchar(255) COLLATE latin1_general_ci NOT NULL,

  `linklabel` varchar(255) COLLATE latin1_general_ci NOT NULL,

  `pagebody` text COLLATE latin1_general_ci NOT NULL,

  `pageorder` int(11) NOT NULL,

  `showing` enum('0','1') COLLATE latin1_general_ci NOT NULL DEFAULT '1',

  `keywords` varchar(255) COLLATE latin1_general_ci NOT NULL,

  `description` varchar(255) COLLATE latin1_general_ci NOT NULL,

  `lastmodified` date NOT NULL,

  `extra` varchar(255) COLLATE latin1_general_ci NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ;


for parsing

$sqlCommand = "SELECT id, linklabel FROM pages WHERE showing='1' ORDER BY id ASC";

$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());



$menuDisplay = '';

while ($row = mysqli_fetch_array($query)) {

    $pid = $row["id"];

    $linklabel = $row["linklabel"];

    

    $menuDisplay = '<li><a href="index.php?pid=' . $pid . '">' . $linklabel . '</a></li>';


and to display menu php code i am using is

<?php echo $menuDisplay; ?>
Link to comment
https://forums.phpfreaks.com/topic/275170-mysql-query-problem-to-create-menu/
Share on other sites

  • Solution

i have solved the issue the problem was in php syntax changed

 $menuDisplay = 
to
 $menuDisplay .= 

 

and its work for me.

 

i have second issue related to above table(db queries) that i want to create title, keywords and descriptions dynamic for pages created in database. for title i used this sytax

 

 

$sqlCommand = "SELECT pagetitle FROM pages WHERE showing='1' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
    $title = $row["pagetitle"];
    
}
mysqli_free_result($query);

 

but this is not working for me it only insert the first page title to all pages. please guide or tell me what will be php syntax to get title, keywords, and description dynamically. thanks in advanced

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.