![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 3
Rep Power: 0
![]() |
Returning an array value
New to PHP and just learning. Old hack at programming, but this is new.
I'm trying to return an array of data from an SQL database. Here, I'll just post the code snippets, might be easier to read than for me to explain it... <?php
$conn = mysql_connect("localhost", "admin", "******");
mysql_select_db("users",$conn);
$sqlcheck = "SELECT * FROM user_db";
$result = mysql_query($sqlcheck, $conn) or die(mysql_error());
// create edituser function
// arguments are $userid
function edituser($userid,$newarray) {
showuserform();
echo '<BR><BR>';
echo '<b>'.$newarray[address].'</b><br><br>' ;
echo '<FORM method="POST">';
echo 'Name : <input type="text" name="name" value="'.$newarray[name].'">';
echo '<BR>';
echo 'Address : <input type="text" name="address">';
echo '<BR>';
echo 'City : <input type="text" name="city">';
echo '<BR>';
echo 'Province/State : <input type="text" name="province" size=2>';
echo '<BR>';
echo 'PostalCode/Zip : <input type="text" name="postalcode">';
echo '<BR>';
echo 'Country : <input type="text" name="country">';
echo '<BR>';
echo 'Password : <input type="password" name="password">';
echo '<BR>';
}
// create the form that shows the users to edit
function showuserform() {
echo '<FORM method="POST">';
echo '<select name="userid">';
while ($newarray = mysql_fetch_array($GLOBALS["result"])) {
echo '<option value="'.$newarray[name].'">'.$newarray[name].'</option>';
}
echo '</select><BR>';
echo '<input type=submit value="Edit User" name="submit">';
return $newarray;
}
if ($_POST['submit']) {
edituser($userid,$newarray);
return;
}
else {
showuserform();
}
?>Does that make sense in my showuserform() function to return the $newarray so that it can be used in the edituser function? Should I set that as a global? |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Mar 2005
Posts: 3
Rep Power: 0
![]() |
As a note, the two lines in the code :
echo '<b>'.$newarray[address].'</b><br><br>' ;
echo '<FORM method="POST">';
echo 'Name : <input type="text" name="name" value="'.$newarray[name].'">';are just for testing purposes to see if it worked. :-) |
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
your show user form is returning a value but as with programming you need a variable in the main function to store that variable as....
so declare an array in edit user function then array = showuserform(); well thats what i think anyways i could be wrong. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Mar 2005
Posts: 3
Rep Power: 0
![]() |
My functions are actually written reversed. It does the showuserform function first, then when I select a user from it, I want it to execute the edituser function. so declaring an array variable in the edituser function, won't give me anything the first time through...
Perhaps declare it globally? |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|