saltedm8 Posted September 5, 2009 Share Posted September 5, 2009 I know I keep asking questions, but I am still learning and have come across another issue I am trying to call info from a database, and display it as a menu, here is what I have <?php include("connections.php"); $chop = mysql_query("SELECT * FROM table1(field2,field3,field4,field5,)VALUES('$field2','$field3','$field4','$field5') "); $menu = array('item'=>$chop, 'div'=>'this', 'count'=>5); function call($menu) { $var1 = '<div id="'; $var1 .= $menu['div'] . '">' ."\n"; $var1 .= '<ul>'."\n"; for ($i=0;$i<$menu[count];$i++){ $var1 .= '<li>' . $menu[item] . '</li>'."\n"; } $var1 .= '</ul>' ."\n"; $var1 .= '</div>'; return $var1; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo call($menu); ?> </body> </html> unfortunately it does not seem to be working as I hoped, its displaying the html ok, and the loop is working... but its not getting the info from the database.. I even tried an array as a test first to see if this would work, and I could not even get the array working, the best I could get was the last word in the array repeating down the menu... would you mind showing me where I am going wrong for both methods... thank you Quote Link to comment Share on other sites More sharing options...
steveangelis Posted September 5, 2009 Share Posted September 5, 2009 $chop = mysql_query("SELECT field2,field3,field4,field5 FROM table1"); Try that. Quote Link to comment Share on other sites More sharing options...
saltedm8 Posted September 5, 2009 Author Share Posted September 5, 2009 its showing, but its not showing as it should.. I am now getting <div id="this"> <ul> <li>Resource id #5</li> <li>Resource id #5</li> <li>Resource id #5</li> <li>Resource id #5</li> <li>Resource id #5</li> </ul> </div> Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 Well, you're trying to echo out the mysql_query, which you should note returns a resource. Which field, exactly, are you trying to echo out into a menu? At the top of the code below, there's a variable called $fieldName. Enter the field name you're trying to use as a string, and it should work from there. I've only checked the problem area, haven't proofread the rest of your code, but give this a shot: <?php include("connections.php"); $fieldName = 'field12345'; $chop = mysql_query("SELECT * FROM `table1`"); $fetch = mysql_fetch_assoc($chop); $menu = array ( 'div' => 'this', 'count' => 5 ); function call($menu) { $var1 = '<div id="'; $var1 .= $menu['div'] . '">' ."\n"; $var1 .= '<ul>'."\n"; for ($i=0; $i < $menu[count]; $i++) { $item = mysel)fetch_assoc($chop); $var1 .= '<li>' . $item . '</li>'."\n"; } $var1 .= '</ul>' ."\n"; $var1 .= '</div>'; return $var1; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo call($menu); ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
saltedm8 Posted September 6, 2009 Author Share Posted September 6, 2009 thanks for the shot, but I am still none the wiser my end goal is for someone to submit a list of menu items to the database ( also with another text box to say what the menu div name is called ), for example I want the end result to be whatever they put in like this <div id="theirdivname"> <ul> <li><a href="/page.html"> menu item </a></li> <li><a href="/page.html"> menu item </a></li> <li><a href="/page.html"> menu item </a></li> <ul/> </div> so, they are defining the div's name and they are also defining the menu names and the amount of menu items, possibly using the database as an array sort of thing so it grabs all the menu items... maybe im not explaining myself very well... I hope you get what I am doing now then for this script to collect that info and use a single function command call($menu) in and it displays the menu Quote Link to comment Share on other sites More sharing options...
kratsg Posted September 6, 2009 Share Posted September 6, 2009 thanks for the shot, but I am still none the wiser my end goal is for someone to submit a list of menu items to the database ( also with another text box to say what the menu div name is called ), for example I want the end result to be whatever they put in like this <div id="theirdivname"> <ul> <li><a href="/page.html"> menu item </a></li> <li><a href="/page.html"> menu item </a></li> <li><a href="/page.html"> menu item </a></li> <ul/> </div> so, they are defining the div's name and they are also defining the menu names and the amount of menu items, possibly using the database as an array sort of thing so it grabs all the menu items... maybe im not explaining myself very well... I hope you get what I am doing now then for this script to collect that info and use a single function command call($menu) in and it displays the menu instead of using just $row = mysql_fetch... try a loop: while($row = mysql_fetch...){ //obtain row data information here 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.