iRoot121 Posted August 5, 2013 Share Posted August 5, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/280840-selection-field/ Share on other sites More sharing options...
iRoot121 Posted August 5, 2013 Author Share Posted August 5, 2013 (edited) $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 August 5, 2013 by iRoot121 Quote Link to comment https://forums.phpfreaks.com/topic/280840-selection-field/#findComment-1443516 Share on other sites More sharing options...
iRoot121 Posted August 5, 2013 Author Share Posted August 5, 2013 Nobody ? Quote Link to comment https://forums.phpfreaks.com/topic/280840-selection-field/#findComment-1443579 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.