Jump to content

Recommended Posts

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

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";
}
?>

<?
$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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.