Jump to content

Selection field


iRoot121

Recommended Posts

Hi all, I've a problem with my PHP code.

 

I've a page, where you can select multiple pages, which will be displayed at the related section on my site.

So far, you can select the pages, and they will be injected into the database, and they will be displayed on the site.

My only problem is: the pages won't be selected on the edit page.

I've this piece of code, and I don't know what I'm doing wrong.

<?php
				$id = $_POST["id"];
				$sql=mysql_query("SELECT `title`,`url`,`volg`, `headerpicture`, `picture`, `product_id` FROM `pagina` WHERE `id`='".$id."' LIMIT 0,1");
				$row=mysql_fetch_assoc($sql);
				echo '<select MULTIPLE name="related[]">';
				if ($row['related'] != '')
				$related_array=explode(',',$row['related']);
				else
				$related_array=array();
				$query="SELECT `id` FROM `producten`";
				$sql=mysql_query($query) or die(mysql_error());
				while($line=mysql_fetch_array($sql))
				{
					$query1="SELECT `title` FROM `pagina` WHERE `product`=1 AND `product_id`='".$line['id']."'";
					$sql1=mysql_query($query1);
					if(mysql_num_rows($sql1) >0)
					{
						$line1=mysql_fetch_array($sql1);
						$selected=' ';
						foreach($related_array as $related_line)
						{
							if ($related_line == $line['id'])
							$selected=' selected ';
						}
						echo '<option'.$selected.'value="'.$line['id'].'">'.$line1['title'].'</option>';
					}
				}
				echo '</select>';
				?>

What am I doing wrong? Is there a piece of code I need to script?

Link to comment
Share on other sites

$id = $_POST["id"];
				$sql=mysql_query("SELECT `title`,`url`,`volg`, `headerpicture`, `picture`, `product_id` FROM `pagina` WHERE `id`='".$id."' LIMIT 0,1");
				$row=mysql_fetch_assoc($sql); 

Should be this xD: 

$id = $_POST["id"];
				$sql=mysql_query("SELECT `title`,`url`,`volg`, `headerpicture`, `picture`, `product_id` FROM `pagina` WHERE `id`='".$id."' LIMIT 0,1");
				$row_pagina=mysql_fetch_assoc($sql);
                                $product_id2 = $row_pagina['product_id'];
				
				$sql2=mysql_query("SELECT * FROM `producten` WHERE `id`='".$product_id2."' LIMIT 0,1");
				$row=mysql_fetch_assoc($sql2);
Edited by iRoot121
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.