Does anyone know how to use php to store all the values from these selects in hidden form fields?
SELECT companyname, address, telephone, fax, email, website, contactname FROM Clients ORDER BY companyname
Thanks
Store in hidden form fileds?
Moderator: General Moderators
Code: Select all
mysql_connect(host,user,pass);
mysql_select_db(database);
$res = mysql_query("SELECT companyname, address, telephone, fax, email, website, contactname FROM Clients ORDER BY companyname");
mysql_close();
for ($i=0; $data = mysql_fetch_array($res); $i++) {
foreach ($data as $field => $value) {
print("<input type='hidden' name='{$field}[$i]' value='{$value}' />");
}
}This works great but can anyone help in retrieving just one row.
I have a form on my first page which has one select box like this
page2.php is where the SELECT from db starts after retrieving the value from my post companyname //hopefully 
Does anyone have any advise on me trying to store all the row contents in hidden form fields? is this a good way to do things to pass the values?
Thanks in advance
JCART | Please use
I have a form on my first page which has one select box like this
Code: Select all
<form method="e;post"e; action="e;page2.php"e;>
<select name="e;companyname"e;>
<option>company1</option>
<option>company2</option>
</select>
<input type="e;submit"e; value="e;Submit"e;>
</form>Does anyone have any advise on me trying to store all the row contents in hidden form fields? is this a good way to do things to pass the values?
Thanks in advance
JCART | Please use
Code: Select all
tags when posting html code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]Well i'm using hidden fields in the opposite way.. I set them through javascript if a user clicks something and after that i just submit the form so those variables are usable in my next PHP script. I never did fill hidden fields from a query, however i do fill variabels in sessions from a query... 
Like i said i have used hidden fields to pass date to another page, but came to the conclusion that URL sending those variables is much easier to keep track of what you are doing, but then again using hidden fields to pass date keeps your url quite clean...
To get just one row add a where clause in your sqlquery and change the printing of your result to:
You don't need a loop if you just want to display one row, changing your sql query made sure of that. Ofcourse only if you used a proper where clause that could only return one row..
And if it didn't then your echoing will still print only 1 row (the last retrieved) since you are not using a loop to print all rows..
Hope this helps too..
JCART | Please use
Like i said i have used hidden fields to pass date to another page, but came to the conclusion that URL sending those variables is much easier to keep track of what you are doing, but then again using hidden fields to pass date keeps your url quite clean...
To get just one row add a where clause in your sqlquery and change the printing of your result to:
Code: Select all
$row=mysql_fetch_array($res); //I always use fetch_array since it's easier to maintain
$value=$row['nameoffield'];
print("<input type='hidden' name='xxx' value='$value'>");Hope this helps too..
JCART | Please use
Code: Select all
tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]