|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
php & mysql menu system
Hi there,
I'm currently building a menu system for my website which takes all the values from a table in a mysql database and displays each record 1 at a time in a specified html format until recently i didn't have much of an idea how to do this, that was when i noticed this tutorial - http://codewalkers.com/tutorials.php?show=15 from that i had a better idea of how to go about this but theres still something wrong with my code, every record has more than 1 value in it which seems to be whats causing my problem as the code in the tutorial (just the first part, it was all i really needed) only dealt with 1 value per record i'll let you look at my code so you can see for yourself, i'll also post the error i'm receiving at the bottom <?php include("config.php"); $query = "SELECT * FROM leftmenu_design ORDER BY display_order"; $result = mysql_query($query); $menu_items = mysql_fetch_array($result); $name = $menu_items['name']; $tooltip = $menu_items['tooltip']; $href = $full_root_dir . $menu_items['href']; echo "<html>n<head></head>n<body>n<table width="140" cellpadding="0" cellspacing="0" border="0" id="left-menu">n"; while($row = mysql_fetch_array($result)) { echo "<tr>nt"; echo "<td onmouseover="this.style.backgroundColor='#F1F1F1';"; echo " this.style.cursor='hand';" onmouseout="this.style.backgroundColor='';" echo " onclick="window.location.href='$href'">nt"; // line 19 echo "<div class="left-menu-item"><a href="$href" onmouseover="window.status=''; return true">"; echo "</a></div></td>n"; echo "</tr>n"; } echo "</table>n</body>n</html>"; ?> i don't know whether what i posted above will display exactly as i intended (just the code) or if any of it has been parsed, heres hoping its just the code, and heres the error message Parse error: parse error, unexpected T_ECHO, expecting ',' or ';' in /home/corp662/public_html/script.php on line 19 i've marked where line 19 is in the code if anybody can point me in the right direction i'd greatly appreciate it many thanks |
|
#2
|
|||
|
|||
|
RE: php & mysql menu system
ok i noticed there was a ; missing so i filled that in but now i get the following errors:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/corp662/public_html/script.php on line 6 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/corp662/public_html/script.php on line 15 |
|
#3
|
|||
|
|||
|
RE: php & mysql menu system
ok i tried moving the while loop around might help, heres how the code looks now:
<?php include("config.php"); $query = "SELECT * FROM leftmenu_design ORDER BY display_order"; $result = mysql_query($query); echo "<html>n<head></head>n<body>n<table width="140" cellpadding="0" cellspacing="0" border="0" id="left-menu">n"; while($menu_items = mysql_fetch_array($result)) { $menu_items = mysql_fetch_array($result); $name = $menu_items['name']; $tooltip = $menu_items['tooltip']; $href = $full_root_dir . $menu_items['href']; echo "<tr>nt"; echo "<td onmouseover="this.style.backgroundColor='#F1F1F1';"; echo " this.style.cursor='hand';" onmouseout="this.style.backgroundColor='';"; echo " onclick="window.location.href='$href'">nt"; echo "<div class="left-menu-item"><a href="$href" onmouseover="window.status=''; return true">"; echo "</a></div></td>n"; echo "</tr>n"; } echo "</table>n</body>n</html>"; ?> and i'm receiving this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/corp662/public_html/script.php on line 10 |
|
#4
|
|||
|
|||
|
RE: php & mysql menu system
it seems it doesn't like the while loop and i have no idea why
|
|
#5
|
|||
|
|||
|
RE: php & mysql menu system
That error msg is telling you that there is something wrong with your query:
$query = "SELECT * FROM leftmenu_design ORDER BY display_order"; Looking at the query, which is very simple and should not be giving you any problems ... assuming the table leftmenu_design exists and the field display_order exists. However, I dont see anywhere in your code where you connect to the db. That would be a problem and why $result is not a valid supplied argument. HTH |
|
#6
|
|||
|
|||
|
RE: php & mysql menu system
ok this is odd, i managed to get it working last night on its own, then i tried to include it in a page and its since started giving me the same error
here is the current code: <?php include("config.php"); $dbc = mysql_connect($dbhostname, $dbusername, $dbpassword); $db = mysql_select_db($dbname, $dbc); // function print_menu() { // global $dbc, $name, $tooltip, $href; $query = "SELECT * FROM leftmenu_" . $menu_page . " ORDER BY display_order"; $result = mysql_query($query, $dbc); while($menu_items = mysql_fetch_array($result)) { $menu_items = mysql_fetch_array($result); $name = $menu_items['name']; $tooltip = $menu_items['tooltip']; $href = $menu_items['href']; echo "<tr>nt"; echo "<td onmouseover="this.style.backgroundColor='#F1F1F1';"; echo " this.style.cursor='hand';" onmouseout="this.style.backgroundColor='';"; echo " onclick="window.location.href='" . $full_root_dir . $href . "'">nt"; echo "<div class="left-menu-item"><a href="" . $full_root_dir . $href . "" onmouseover="window.status=''; return true">"; echo "</a></div></td>n"; echo "</tr>n"; } // } // print_menu(); ?> the file which this is in is being included from a file in the same directory which is querying the database (a query that actaully works!) to get the 2 templates for the page layout, these templates are being printed onto the page using eval() as there is php code within them to be parsed, this includes the calling of the print_menu() function (its still in the layout, i only added it to the bottom of the script to test it on its own) |
|
#7
|
|||
|
|||
|
RE: php & mysql menu system
can anybody point me at a tutorial which grgabs an entire table from the datbase and prints the contents?
|
|
#8
|
|||
|
|||
|
RE: php & mysql menu system
it's ok i found 1 over at webmonkey, although i'm still getting an error when i run the main script, i'm going to post the code used in each scripts being used and maybe somebody can spot something i can't (fresh pair of eyes etc.)
menu script: <?php include("config.php"); $dbc = mysql_connect($dbhostname, $dbusername, $dbpassword); $db = mysql_select_db($dbname, $dbc); function print_menu() { global $dbc, $name, $tooltip, $href; $query = "SELECT * FROM leftmenu_" . $menu_page . " ORDER BY display_order"; $result = mysql_query($query); // echo "<table width="140" cellpadding="0" cellspacing="0" border="0">n"; while($menu_items = mysql_fetch_array($result)) { echo "<tr>nt"; echo "<td onmouseover="this.style.backgroundColor='#F1F1F1';"; echo " this.style.cursor='hand';" onmouseout="this.style.backgroundColor='';"; echo " onclick="window.location.href='" . $full_root_dir . $menu_items['href'] . "'">nt"; echo "<div class="left-menu-item"><a href="" . $full_root_dir . $menu_items['href'] . "" onmouseover="window.status=''; return true">"; echo $menu_items['name'] . "</a></div></td>n"; echo "</tr>n"; } // echo "</table>"; } // print_menu(); ?> certain things have been commented out as they're already in the main script, they were just there so i could test the script standalone main script: <?php include("config.php"); include("functions.php"); $page = "home"; $menu_page = "design"; include("menu.php"); get_template(); get_page_info(); echo "<html>n"; echo "<head>n"; echo "<title>"; echo $main_title . $page_title; echo "</title>n"; echo "<style>n<!--n"; include($css_skins . $v . "/" . "css.inc"); echo "n-->n</style>n"; echo "</head>n"; echo "<body scroll="yes" onload="defaultStatus='" . $default_status_line . "'; return true">n"; eval("?>" . $page_header); echo "n"; eval("?>" . $page_footer); echo "n"; echo "</body>n"; echo "</html>"; ?> and the header ($page_header) generated by the database: <table width="570" align="center" cellpadding="0" cellspacing="0" border="0"> <tr> <td height="80" bgcolor="#565655"><img src="<?php echo $gfx_skins . $v; ?>/top01.jpg" border="0"><br> <img src="<?php echo $gfx_skins . $v; ?>/logo.jpg" border="0"></td> <td bgcolor="#565655"><img src="<?php echo $gfx_skins . $v; ?>/top02.jpg" border="0"><img src="<?php echo $gfx_skins . $v; ?>/top03.jpg" border="0"></td> </tr> <tr> <td colspan="2" height="26" bgcolor="#C6C6C6" background="<?php echo $gfx_skins . $v; ?>/menu/bg.gif"><a href="index.htm"><img src="<?php echo $gfx_skins . $v; ?>/menu/home.gif" border="0" class="top-menu" style="margin-left: 7px;"></a><a href="about.htm"><img src="<?php echo $gfx_skins . $v; ?>/menu/about.gif" border="0" class="top-menu"></a><a href="design.htm"><img src="<?php echo $gfx_skins . $v; ?>/menu/design.gif" border="0" class="top-menu"></a><a href="hosting.htm"><img src="<?php echo $gfx_skins . $v; ?>/menu/hosting.gif" border="0" class="top-menu"></a><a href="support.htm"><img src="<?php echo $gfx_skins . $v; ?>/menu/support.gif" border="0" class="top-menu"></a><a href="contact.htm"><img src="<?php echo $gfx_skins . $v; ?>/menu/contact.gif" border="0" class="top-menu"></a></td> </tr> <tr> <td colspan="2"> <table width="570" height="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="140" height="100%" bgcolor="#E1E1E1" valign="top"> <table width="140" height="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td valign="top" height="200"> <table width="140" cellpadding="0" cellspacing="0" border="0" id="left-menu"> <?php ///////////////////////////// print_menu(); /////////////////////////////?> <tr> <td bgcolor="#D4D4D4" style="border-bottom: 1px solid #C9C9C9;"><div class="left-menu-header-item"><img src="<?php echo $gfx_skins . $v; ?>/menu/left/partners.gif" border="0" width="42" height="9"> <img src="<?php echo $gfx_skins . $v; ?>/menu/left/arrows.gif" border="0"></div></td> </tr> <tr> <td></td> </tr> </table></td> </tr> <tr> <td height="22" valign="bottom" align="right"><a href="#top"><img src="<?php echo $gfx_skins . $v; ?>/top.gif" border="0" width="40" height="22"></a></td> </tr> </table></td> <td width="430" valign="top"> most of the code in between is irrelevant so i hope you'll bear with me, i know all the database details work because the headers and footers are being printed as normal, its the menu script which doesn't seem to be working i think i have a few things in the wrong order, i just need a fresh pair of eyes to point them out |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > php & mysql menu system |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|