Page 1 of 1

dynamic site updater

Posted: Sun May 22, 2005 12:02 am
by kthakore
Currently I am working on a site wherre I am making a php script that will allow me to change the text on pages without having to open code files. But I am stuck somewhere.
I am making a form that will allow the client to select the page and then change the text. This what I have right now

Code: Select all

<form name="form1" method="post" action="3">
  <p>
    <select name="select">
      <?php require_once('php/connect.php');
	$query = "select * from data ";
	$result = mysql_query($query);
	$num_results = mysql_num_rows($result);
	for ($i=0; $i + 1 <= $num_results; $i++)
													  {
														 $row = mysql_fetch_array($result);
		echo "<option>";
		echo $row['page'];
		echo "</option>";														
													  } ?>
    </select>

    <div id="f.htm#3"><textarea name="textarea" cols="45" rows="10></textarea></div>
    <input type="submit" name="Submit" value="Submit">
</form>
what I want the text area to do is as soon as a page is choosed in the menu it would what currently exist in the record for text for that php in the database.

Posted: Sun May 22, 2005 12:26 am
by php_wiz_kid
Make sure in the <option> tag you use the value attribute. Place the records index in the value attribute and in the next page do a query that finds the record using the posted forms information. Here's an example:

Query after submit:

Code: Select all

$query = &quote;SELECT row FROM data WHERE row = '$_POST&#1111;'select']'&quote;;
Then place the query information into the textarea.

Code: Select all

<textarea name="select"><?php mysql_fetch_assoc['row'] ?></textarea>

Posted: Sun May 22, 2005 9:40 am
by kthakore
how do I make the textarea contain the "text" data in the same page. And than this would change if a diffrent page is chosen in the menu.

Posted: Sun May 22, 2005 10:13 pm
by php_wiz_kid
If you're not wanting to submit before the text is displayed then use JavaScript.

An example would be if someone selected something from a drop down box and you wanted a textarea to automatically be populated without posting to another page or using a postback then you'd want to use JavaScript to dynamically fill the textarea. I don't know JavaScript well enough to tell you off the top of my head. I have to look through my gigantic JavaScript book everytime I want to do something simple so I'm not help with actually writing the code.

Posted: Mon May 23, 2005 3:30 am
by phpScott
create yourself javascript objects to contian the the text for the text area.

here is a quick intro to creating and using js objects.
http://cs.uww.edu/cs381/documents/objects.html

Posted: Mon May 23, 2005 10:00 am
by kthakore
I have come up with this code, but it only changes the textarea once and than not again!!

Code: Select all

<form name="form1" method="post" action="3">
  <p>
    <select name="select"  onChange="this.form.elements['t'].value=
	<?php  
	$id= selectedIndex;
	require_once('php/connect.php');
	$query2 = "select * from data where id='".$id."'";
	$result2 = mysql_query($query2);
	$row2 = mysql_fetch_array($result2);
	echo "'";
	echo $row2['text'];
	echo "'";
	?>">
      <?php require_once('php/connect.php');
$query = "select * from data ";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i + 1 <= $num_results; $i++)
													  {
														$row = mysql_fetch_array($result);
		echo "<option>";
		echo $row['page'];
		echo "</option>";														
													  } ?>
    </select>
    textarea name="t" cols="45" rows="10"></textarea>
    <input type="submit" name="Submit" value="Submit">
</form>

Posted: Tue May 24, 2005 10:14 am
by kthakore
any one here!!