Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Databasing
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-23-2009, 12:03 PM
  #1
minimark
Novice (Level 1)
 
Join Date: Oct 2009
Posts: 2
iTrader: (0)
minimark is an unknown quantity at this point
innerHTML - How do I?

After reading a mysql database with php, is it possible then to display the php variable using the innerHTML value property? (As in innerHTML="<input type='text' name='reference' value= '' size='30' />"; )
minimark is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-25-2009, 09:47 PM
  #2
Horus_Kol
Mod of the Underlay
 
Horus_Kol's Avatar
 
Join Date: Jun 2002
Location: At a desk, hooked up and ready to rock
Posts: 17,242
iTrader: (0)
Horus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of light
innerHTML is a property of the document as viewed in the browser - PHP cannot access client-side information like this..

However, PHP can be used to write information into the document before it is delivered to the client - by using echo or print statements...

echo
print
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak

The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
Horus_Kol is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-29-2009, 02:27 PM
  #3
cmetz1977
Myrmidon (Level 12)
 
cmetz1977's Avatar
 
Join Date: May 2008
Location: Lakeland, FL
Posts: 193
iTrader: (0)
cmetz1977 will become famous soon enough
minimark,

You can use IFRAMEs to complete this. Run the database query in the IFRAME source and have it print its output in the script.

Main Page
PHP Code:
<form id='userinfo' action='userinfo.php' method='post'>

<
p><select name='userid' onchange='updateform( this.value )'>
<
option value='1'>1</option>
<
option value='2'>2</option>
</
select></p>

<
p><input type='text' name='username'/></p>
<
p><input type='text' name='usertitle'/></p>
<
p><input type='submit' name='Update User'/></p>
</
form>

<
p id='errortag'>&nbsp</p>

<
form id='useridform' action='useridquery.php' target='useridframe' method='post'>
<
p><input type='hidden' name='userid'/></p>
</
form>

<
iframe name='useridframe'></iframe>

<
script type='text/javascript'>
function 
updateformuserid )
{
    
useridform document.getElementById'useridform' );
    
useridform.elements'userid' ].value userid;
    
useridform.submit( );
}
</script> 
useridquery.php
PHP Code:
<script type='text/javascript'>
<?php
$connection 
mysql_connect( ... );
$connection mysql_select_db( ... );

$userdataquery mysql_query"SELECT `username`, `usertitle` FROM  `userdb` WHERE `userid` = " .mysql_real_escape_string$_POST'userid' ], $connection ) ."'"$connection );
if( 
$userdataquery && mysql_num_rows$userdataquery ) )
{
    print( 
"    userform = parent.getElementById( 'userinfo' );\n" );

    
$userdata mysql_fetch_assoc$userdataquery );
    foreach( 
$userdata as $userkey => $uservalue )
        print( 
"    if( typeof userform.elements[ '$userkey' ] !== 'undefined' ) userform.elements[ '$userkey' ].value = '$uservalue';\n" );
}
else print( 
"parent.document.getElementById( 'errortag' ).innerHTML = 'That  user does not exist';\n" );
?></script>
NOTE: this has not been tested for syntax and the logic may not align with the expected output since I may have jumbled some variable/element names.

There are 2 forms on the main page. The first is the one your user interfaces, the second is purely functional. When the drop-down is changed in the first form, javascript sets the userid as the value in the second form then automatically submits that form. The target of the second form is the IFRAME, where the query runs and prints its results in the parent window either to the first form or to the errortag based on the outcome.
__________________
Never accept Kool-aid from someone who won't drink from the same punch bowl.
cmetz1977 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 04:14 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.