Jump to content

Dynamic Menu inside echo


NerdConcepts

Recommended Posts

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
Share on other sites

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
Share on other sites

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.