cjbeck71081 Posted August 30, 2006 Share Posted August 30, 2006 I am a new to PHP and i think my question is basic, but i am having no luck finding the answer.I have an sql database on my website with data populate for fields UserID, FirstName, LastName, and Email[b]I created an HTML page called "userid.html" with this code:[/b][color=red][font=Verdana][font=Verdana]</head><body><form method="post" action="http://epicri.com/info.php"><p align="center"> </p><p align="center"> </p><p align="center"> </p><form id="form1" name="form1" method="post" action=""> <label> <div align="center"><span class="style1">Please Enter User ID: </span><br /> <br /> <input name="userid" type="text" size="10" maxlength="5" /> <br /> <br /> <input type="submit" name="Go" value="Submit" /> </div> </label></form><p align="center"> </p></body></html>[/color] [b]that sent the value of the USERID entered into a textbox to a PHP script named "info.php" that then query'd the database for the data that looked like this:[/b][color=green]</head><body><?php$hostname = "mysql.epicri.com";$username = "epicr001";$password = "xxxxx"; $usertable = "persontab"; $dbName = "epicr001"; // $word = $_POST["userid"]?><?php$con = mysql_connect($hostname,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db($dbName, $con);$result = mysql_query("SELECT firstname,lastname,email,userid FROM $usertableWHERE userid='$word'");while($row = mysql_fetch_array($result)) { echo $row['firstname'] . " " . $row['lastname']; echo "<br />"; } ?></body>[/color]What i would like to do is now populate an HTML page with the results of the Query without using the "echo" code. For example after the information is sent to the PHP the resulting HTML page would look like:[color=blue][b]John Smith[/b][/color]UserID: [color=purple]12221[/color]First Name: [color=purple]John[/color]Last Name: [color=purple]Smith[/color]Email Address: [color=purple][email protected][/color]I am almost sure my problem is the syntaxt of passing PHP Variables for use in an HTML form, but i dont knowAny help is apprecaitedThank YouChris Quote Link to comment https://forums.phpfreaks.com/topic/19175-php-variables-populate-to-html/ Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 Without echo nothing will be outputted. So you'll need to use echo to generate the html. or do you ant to create an HTML file with the output of the query? Quote Link to comment https://forums.phpfreaks.com/topic/19175-php-variables-populate-to-html/#findComment-82968 Share on other sites More sharing options...
cjbeck71081 Posted August 30, 2006 Author Share Posted August 30, 2006 I want to make an HTML file from the output of the query Quote Link to comment https://forums.phpfreaks.com/topic/19175-php-variables-populate-to-html/#findComment-82975 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 Okay use this:[code]$htmlCode = <<<HTML<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Unititled Document</title></head><body>HTML;$row = mysql_fetch_array($result);$name = $row['firstname'] . '_' . $row['lastname'];$htmlCode .= <<<HTML<b>{$name}</b><br /><b>User ID:</b> {$row['userid']}<br /><b>First Name:</b> {$row['firstname']}<br /><b>Last Name:</b> {$row['Lastname']}<br /><b>Email Address:</b> {$row['email']}</body></html>HTML;// create the HTML File// the html file will be name:// fistname_lastname.html$htmlFile = fopen($name . '.html', "w+");// write to the html filefwrite($htmlFile, $htmlCode, strlen($htmlCode));// now we close the filefclose($htmlFile);echo "HTML file created!<br />\n<br />\n<a href=\"{$name}.html\">{$name}.html</a>";[/code]instead of the following:[code]while($row = mysql_fetch_array($result)) { echo $row['firstname'] . " " . $row['lastname']; echo ""; }[/code]NOTE: This code is untested, so it may return errors. Quote Link to comment https://forums.phpfreaks.com/topic/19175-php-variables-populate-to-html/#findComment-82989 Share on other sites More sharing options...
craygo Posted August 30, 2006 Share Posted August 30, 2006 You can write any html code you like. When it comes to to put something in that comes from the database you can use this[code] <?=$row['firstname']?>[/code]So in html it will look like this[code]<td class=someclass align=center>First Name: <?=$row['firstname']?></td>[/code]or the other way around. start your table above your while statement then echo out the html code with the database results. You should start the table above the while statement that way you can loop thru each row starting with <tr> otherwise you will start a new table on every loop[code]echo "<table>"while($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['firstname']."</td><td>" . $row['lastname']."</td></tr>"; }echo "</table>"[/code]It that what you are looking for???Ray Quote Link to comment https://forums.phpfreaks.com/topic/19175-php-variables-populate-to-html/#findComment-82994 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 He wants to create a HTML file from the output generated from the query. He doesnt want to display results from the script that runs the query. Which is what my code above does. Quote Link to comment https://forums.phpfreaks.com/topic/19175-php-variables-populate-to-html/#findComment-83001 Share on other sites More sharing options...
cjbeck71081 Posted August 30, 2006 Author Share Posted August 30, 2006 Thank you both for your assistance.The output from query worked great!.Ultimately what i was looking for however was the second answer regarding the <td><?=$row['firstname']?></td> code.I realise I made a mistake in how i asked the question, but both responses were a huge help.I have been reading information on code for some 100 hours in the last 2 weeks ultimately looking for this information... i shoudlve came here in the first place.Thank You again guysChris Quote Link to comment https://forums.phpfreaks.com/topic/19175-php-variables-populate-to-html/#findComment-83011 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.