thunderbox Posted August 1, 2007 Share Posted August 1, 2007 hey guys, i have a script that drags variables in a loops. as this is the only way that i can use the mysql_fetch_array command. this is my script that gets the info. $userid = $_SESSION['userid']; $mysql = mysql_query("SELECT * FROM profile WHERE userid='$userid'"); if ($mysql > 0) { while ($row = mysql_fetch_array($mysql)) { $p_displayname = $row['displayname']; $p_quote = $row['quote']; $p_name = $row['name']; $p_age = $row['age']; $p_location = $row['location']; $p_links = $row['links']; $p_photo = $row['photo']; $p_about = $row['about']; $p_gender = $row['gender']; } } and i want the variables start with $p_ to be able to be sent over the site so i can put them in a form field so i can use the mysql 'update' command. is there any easy way to do this. cuz mine isnt really working properly. Link to comment https://forums.phpfreaks.com/topic/62822-getting-variables-from-loops/ Share on other sites More sharing options...
onlyican Posted August 1, 2007 Share Posted August 1, 2007 I don't understand The variables name with $p_ are ready You want a form, I would do something like <?php $query = "SELECT * FROM profile WHERE usersid = ".$userid; $result = mysql_query($query); //Check you have results if(mysql_num_rows($result) > 0){ $row1 = mysql_fetch_assoc($result); echo "<form method='post' action=''>\n"; echo "<input type='text' name='DisplayName' value='".$row1["DisplayName"]."' />\n"; //Continue adding fields with the value being from the Database echo "</form>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/62822-getting-variables-from-loops/#findComment-312741 Share on other sites More sharing options...
DeadEvil Posted August 1, 2007 Share Posted August 1, 2007 <? $mysql = mysql_query("SELECT * FROM profile WHERE userid='{$_SESSION['userid']}'"); if ($mysql > 0): $frm_content = ""; while ($row = mysql_fetch_array($mysql)): $frm_content .= "<input type=\"hidden\" name=\"displayname\" value=".$row['displayname'].">"; $frm_content .= "<input type=\"hidden\" name=\"quote\" value=".$row['quote'].">"; $frm_content .= "<input type=\"hidden\" name=\"name\" value=".$row['name'].">"; $frm_content .= "<input type=\"hidden\" name=\"age\" value=".$row['age'].">"; $frm_content .= "<input type=\"hidden\" name=\"location\" value=".$row['location'].">"; $frm_content .= "<input type=\"hidden\" name=\"links\" value=".$row['links'].">"; $frm_content .= "<input type=\"hidden\" name=\"photo\" value=".$row['photo'].">"; $frm_content .= "<input type=\"hidden\" name=\"about\" value=".$row['about'].">"; $frm_content .= "<input type=\"hidden\" name=\"gender\" value=".$row['gender'].">"; endwhile; endif; ?> <form name="form" action="action_page.extention_name" method="post"> <?=$frm_content?> <input type="submit" name="submit" value="submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/62822-getting-variables-from-loops/#findComment-312757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.