Jump to content

Select drop menu unable to populate


zark

Recommended Posts

Hi there,

i am relatively new to php, mysql, css etc but learning fast.

My problem is such;

i have a php file which is doing a SELECT mysql_query, WHILE results to strings, then ECHO the resulting rows to produce a list  formatted using  <table> and finally this <table> is inside a <form> which will POST the  changes back to the specific database.tble.row.

 

I wish to have a drop down menu within the <form><table> which will be populated from a separate database.table.

 

I have accomplished the drop down menu outside the <?php ?> tags inside  <form><table> which POSTS to a php file but my problem is to add the populating drop down menu inside <?php ?> an already ECHOing resulting rows from the sql query.

 

i.e <?php blurb and stuff ?>

<form><table><tr><td>

<select name etc>

<?php

$result = mysql_query("SELECT * FROM tbl WHERE string = tble.rw ORDER BY column");

while($row=mysql_fetch_array($result)){

echo "<OPTION VALUE=".$row['column'].">".$row['column']."</OPTION>";

}

?>

</select> WORKS!!!!

 

but placing this inside

 

<?php $x =mysql_query[select] while {strings = conditions; echo ("<form><table><tr><td>

insert populated drop menu here

</td> etc ");

echo"";}?>

 

doesnt work and just leaves the select drop menu blank

 

Hoep you understand my problem.

I do not think i can attached the population WHILE loop to a string and just insert the string to the form but maybe i am wrong.

 

thanks in advance and if you go tthis far reading you must be on lots and lots of coffee

 

zark

Link to comment
Share on other sites

yup;

 

this works as a simple insert form

<?php

$sid = $member_details_array['id'];

?>

<div id="boxlist">

<form  enctype=multipart/form-data method=post action='upgift.php'>

<p>

<p>

<p>

<p>Please enter the title :<input name='descrip'  size='10px' id='title'></p>

<p>Please enter the price: <input name='price' size='10px' id='price' value='£'></p>

<p>Upload picture:<input type=file name='image' size='10px'></p>

<p> Celebration? <select name='celeb' size='1'>

<?php

$evea = mysql_query("SELECT * FROM events WHERE $sid = events.id ORDER BY event");

 

while($row=mysql_fetch_array($evea)){

 

echo "<OPTION VALUE=".$row['event'].">".$row['event']."</OPTION>";

 

}

?>

</select>

<p>Page of item on internet:<input name='blank1' size='10px' maxlength='200' value='http://' >

<p><input type=submit name='upgift' value='upload'></form>

</div>

 

whereas i wish to have the drop down menu as below;

 

<div id="boxlist">

 

<?php

$sid = $member_details_array['id'];

 

$list = mysql_query("

SELECT

flumpurls.descrip, flumpurls.url, flumpurls.price, flumpurls.celeb, flumpurls.blank1, events.event, events.datedue, flumpurls.cal_id

FROM

flumpurls, events

WHERE

flumpurls.id = '$sid'

AND events.id = '$sid'

AND blank2 = 'A'

AND events.event = flumpurls.celeb

 

ORDER BY

events.datedue ASC");

 

while($giresult = mysql_fetch_array($list))

 

{$words = $giresult['descrip'];

$cost = $giresult['price'];

$picture = $giresult['url'];

$celeb = $giresult['celeb'];

$thedate = strtotime ($giresult['datedue']);

$date = date("j M Y",$thedate);

$pict2 = SECURE_RTI_FOLDER;

$avatar = "$pict2$picture";

$gid = $giresult['cal_id'];

 

$words_input="<input TYPE=\"text\" SIZE=\"20\" NAME=\"words\" maxlength=\"20\" value=\"".$giresult['descrip']."\" >";

 

$cost_input="<input TYPE=\"text\" SIZE=\"20\" NAME=\"price\" maxlength=\"8\" value=\"".$giresult['price']."\" >";

 

$celeb_input="<select name=\"celeb\" SIZE=\"1\" maxlength=\"15\">

<option value=\"".$giresult['celeb']."\">".$giresult['celeb']."</option>

</select>";

 

$gid_input="<input TYPE=\"hidden\" SIZE=\"20\" NAME=\"gid\" maxlength=\"10\"

value=\"$gid\" >";

 

 

 

 

 

echo ("<form enctype=multipart/form-data  method=post action='giftupdate.php'><table width='400' height='150' align='center' border='0'  >

 

  <tr>

 

    <td width='80' >Event: $celeb_input<div align='right'></div></td>

 

    <td rowspan='4' width='120'><a ><img src='$avatar' width='110' height='80'/></a></td>

 

    <td  width='96'></td>

 

  </tr>

 

  <tr>

 

    <td width='80'>Title:$words_input</td>

 

<td  width='96'>Update this gifts details<p>

 

      <input type=submit name=update value='update'><input type=hidden name=gid value=$gid></td>

 

  </tr>

 

  <tr>

 

    <td width='80'>Price:$cost_input</td>

<td  width='96'><?php

$evea = mysql_query("SELECT * FROM events WHERE $sid = events.id ORDER BY event");

 

while($row=mysql_fetch_array($evea)){

 

echo "<OPTION VALUE=".$row['event'].">".$row['event']."</OPTION>";

 

}

?></td>

 

  </tr>

 

  <tr>

    <td colspan='2' >Date:<p>$date</td>

<td  width='96'></td>

</tr>

<br>

</table></form>");

 

echo "";

 

}

?>

</div>

 

p.s i am getting round to the \' s 

 

Link to comment
Share on other sites

It's your query that's causing the issue.  Should be:

SELECT * FROM events WHERE events.id = $sid ORDER BY event

NOT

SELECT * FROM events WHERE $sid = events.id ORDER BY event

 

and if events.id is not an integer you will need single quotes around $sid.

Link to comment
Share on other sites

Looks like you're missing the terminating '}' for this while loop:

while($giresult = mysql_fetch_array($list))

{

 

Missing the terminating ')' for this line:

echo ("</pre>
<form enctype="multipart/form-data " method="post" action="'giftupdate.php'"><

 

Also the terminating ?> for the previous <?php tag.

 

To view all the errors add these 2 lines in directly after your opening <?php tag:

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Link to comment
Share on other sites

ah, hang on, to be clear.

i want the populated drop down menu inside the form so it will be another element i can manipulate in giftupdate.php.

 

once i have the menu working in the echo i can then use the selected function to display the associated value with the specific row from the array with the option of the menu choice to alter the associated value.

 

i.e

$giresult row 1 + 

<select >

<option selected="selected" value="1">row 1s associated value</option>

<option value="2">choice 2</option>

<option value="3">choice 3 </option>

<option value="4">choice 4 </option>

</select>

 

$giresult row 2 +

<select >

<option selected="selected" value="2">row 2s associated value</option>

<option value="2">choice 1</option>

<option value="3">choice 3 </option>

<option value="4">choice 4 </option>

</select>

 

etc throughout the Echoed array $giresult

Link to comment
Share on other sites

I've tried sleeping on it but still no clue how to accomplish this;

 

tried creating a separate php page with the while loop and tried including page inside form but still nothing.,

 

Problem as far as i can work out is that the FORM is inside an ECHO of a WHILE loop {} which is producing a list.

 

writing <?php ?> inside this FORM being echoed is being rejected.

 

Am i failing on the syntax or the methodology?

 

Page producing rows to populate the dropdown menu named "page.php"

<?php

 

$sid = $member_details_array['id'];

$event = mysql_query("SELECT * FROM events WHERE events.id = '$sid' ORDER BY cal_id ASC");

while($row=mysql_fetch_array($event)){

echo "

<OPTION VALUE=".$row['event'].">".$row['event']."</OPTION>";

 

}

 

?>

the above produces the list i want and can be produced outside the echo"<form><table>

see here

 

 

page displaying information named "display.php"

$sid = $member_details_array['id'];

 

$list = mysql_query("

SELECT

columns

FROM

tables

WHERE

conditions

 

ORDER BY

column5  ASC");

 

while($giresult = mysql_fetch_array($list))

 

{

$words = $giresult['a'];

$cost = $giresult['b'];

$picture = $giresult['c'];

include("page.php");

echo ("<form enctype=multipart/form-data  method=post action='giftupdate.php'><table width='400' height='150' align='center' border='0'  >

 

  <tr>

 

    <td width='80' >Event: <select name='celeb' size='1'></select></td>

 

</table></form>");

 

echo "";

}

?>

</div>

 

once the include is attempted to be placed within the FORM it produces an empty dropdown menu

<div id="boxlist">

 

<?php

$sid = $member_details_array['id'];

 

$list = mysql_query("

SELECT

columns

FROM

tables

WHERE

conditions

 

ORDER BY

column5  ASC");

 

while($giresult = mysql_fetch_array($list))

 

{

$words = $giresult['a'];

$cost = $giresult['b'];

$picture = $giresult['c'];

 

 

echo ("<form enctype=multipart/form-data  method=post action='giftupdate.php'><table width='400' height='150' align='center' border='0'  >

 

  <tr>

 

    <td width='80' >Event: <select name='celeb' size='1'><?php include("page.php"); ?></select></td>

 

</table></form>");

 

echo "";

}

?>

</div>

.

 

help? Is it the php inside a form inside php tags? or syntax?

 

thanks

 

Link to comment
Share on other sites

yeah i am pretty sure an include in an echo statement wont work.

 

try creating a string with the options in, rather than echoing them directly, and then include that string into the echo statement instead of the include so something like

<?php
$options = '';
$sid = $member_details_array['id'];
$event = mysql_query("SELECT * FROM events WHERE events.id = '$sid' ORDER BY cal_id ASC");
while($row=mysql_fetch_array($event)){
echo "
$options .= <OPTION VALUE=".$row['event'].">".$row['event']."</OPTION>";

}

?>

 

then echo out that $options string along with the rest of the form.

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.