dynamic site updater

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kthakore
Forum Newbie
Posts: 4
Joined: Sat May 21, 2005 11:55 pm
Location: here and there

dynamic site updater

Post 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.
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post 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>
kthakore
Forum Newbie
Posts: 4
Joined: Sat May 21, 2005 11:55 pm
Location: here and there

Post 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.
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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
kthakore
Forum Newbie
Posts: 4
Joined: Sat May 21, 2005 11:55 pm
Location: here and there

Post 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>
kthakore
Forum Newbie
Posts: 4
Joined: Sat May 21, 2005 11:55 pm
Location: here and there

Post by kthakore »

any one here!!
Post Reply