NerdConcepts Posted March 8, 2007 Share Posted March 8, 2007 I've got to do a query to get the dynamic menu(s) to display. Well since I am doing if, elseif, and else commands to display one of three possible pages I am using echo commands to display the coding. Well here is where I am having a problem...the echo command is the only thing I can seem to use to display a page. if (isset($_GET['viewid'])) { $viewid = $_GET['viewid']; $query = "SELECT vendor_id, vendor_name, vendor_desc FROM vendors WHERE vendor_id='$viewid'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $vid = $row['vendor_id']; $vname = $row['vendor_name']; $vdesc = $row['vendor_desc']; echo $vid; // just for a test. That is a little bit of the code. After that is when I do another echo to display the code for the search form again. The form has two dynamic menus which use querys to display the drop down menus. Here is the menu code. By itself it work perfect. So does the above code. <form action="view_vendors.php" method="post"> Zip Code <input type="text" name="user_zip" size="5" maxlength="5" value="<?PHP if (isset($_SESSION['user_zip'])) echo $_SESSION['user_zip']; ?>" /> Category <select name="maincat_id"> <option value="<?PHP if (isset($_POST['maincat_id'])) echo $_POST['maincat_id']; ?>"><?PHP if (isset($_POST['maincat_title'])) echo $_POST['maincat_title']; ?></option> <?PHP $query = "SELECT maincat_id, maincat_title FROM vendor_maincat ORDER BY maincat_title ASC"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['maincat_id']}\">{$row['maincat_title']}</option>\n"; } ?> </select> <input type="submit" name="submit" value="Search" /> <input type="reset" name="reset" value="Clear" /> <input type="hidden" name="submittedsearch" /> </form> I tried stopping PHP and starting it again after this form without an echo command but that just throws errors. I am not sure how to do a query inside of an echo. I tried using "\" and it just throws another error....Just tired of trying to figure this out on my own. So I hope someone can help me out...since it's almost 4am and I am going to bed, lol. Link to comment https://forums.phpfreaks.com/topic/41759-dynamic-menu-inside-echo/ Share on other sites More sharing options...
severndigital Posted March 8, 2007 Share Posted March 8, 2007 echo "<option value=\"{$row['maincat_id']}\">{$row['maincat_title']}</option>\n"; try this instead echo '<option value="' . $row['maincat_id'] . '">' . $row['maincat_title'] . '</option>\n'; I've had similar problems in the past and this has proved to be a worthy solution for me. Link to comment https://forums.phpfreaks.com/topic/41759-dynamic-menu-inside-echo/#findComment-202819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.