PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 25th, 2002, 11:05 PM
662corp 662corp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 17 662corp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old August 25th, 2002, 11:45 PM
662corp 662corp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 17 662corp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #3  
Old August 26th, 2002, 12:06 AM
662corp 662corp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 17 662corp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old August 26th, 2002, 12:07 AM
662corp 662corp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 17 662corp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: php & mysql menu system

it seems it doesn't like the while loop and i have no idea why

Reply With Quote
  #5  
Old August 26th, 2002, 12:53 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to EvilivE
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

Reply With Quote
  #6  
Old August 26th, 2002, 05:01 PM
662corp 662corp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 17 662corp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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)

Reply With Quote
  #7  
Old August 26th, 2002, 05:04 PM
662corp 662corp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 17 662corp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: php & mysql menu system

can anybody point me at a tutorial which grgabs an entire table from the datbase and prints the contents?

Reply With Quote
  #8  
Old August 26th, 2002, 05:39 PM
662corp 662corp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 17 662corp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php & mysql menu system


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 9 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek