3 Replies - 2317 Views - Last Post: 04 March 2009 - 10:12 PM Rate Topic: -----

#1 arshem  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 02-March 09

Dynamic Textfield on the form, how to retreive all data and implode

Post icon  Posted 04 March 2009 - 08:56 PM

Hey everyone,

I have a quick question.

What method would be best to use to retreive information from a form that has dynamic textfields [you can add more and more textfields. The names would be textfield0,textfield1,textfield2,etc.

I'm not asking for the code, just asking what would be the best way to retreive all the textfields + the count. I was thinking a foreach, but then i couldn't think of a way to retrieve them all..unless i use [] in the textfield name param..


Thanks in advance

here is my code for the function thus far:


function cars_addspecs() {
	$info = auth_member();
	$car_id = $GLOBALS["Get"]->val("car_id");

	if(!$car_id){
		load_page(URL."/p/cars/s/manage");
	}//if

	$sql_query = "SELECT count(*) FROM cars WHERE car_id='".$car_id."' AND mem_id='".$info["mem_id"]."'";
	$exist = $GLOBALS["DB2"]->single($sql_query);

	if($exist) {
		build_error(100141,"cars","manage");
	}//if

	$sql_query = "INSERT INTO cars_specifications (engine_mods,suspension_mods,electronic_mods,wheel_mods,chasis_mods,interior_mods,brief_description,402m,0_100kmh,0_300kmh,0_1000m,car_value,modify_budget,sponsor_company,sponsor_url,':car_id:')  VALUES (
	':engine_mods:',':suspension_mods:',':electronic_mods:',':wheel_mods:',':chasis_mods:',':interior_mods:',':brief_description:',':402m:',':0_100kmh:',':0_300kmh:',':0_1000m:',':car_value:',':modify_budget:',':sponsor_company:',':sponsor_url:',':car_id:')";




as you can see i'm stuck at the point of making the values of dynamic "sponsor_company" and "sponsor URL"


Thanks again :)

Is This A Good Question/Topic? 0
  • +

Replies To: Dynamic Textfield on the form, how to retreive all data and implode

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3069
  • View blog
  • Posts: 10,750
  • Joined: 08-August 08

Re: Dynamic Textfield on the form, how to retreive all data and implode

Posted 04 March 2009 - 09:57 PM

1) This isn't defined:
$GLOBALS["Get"]->val("car_id")

2) Your function has no end brace.

3) Your function isn't called.

4) I see no form.
Was This Post Helpful? 0
  • +
  • -

#3 arshem  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 02-March 09

Re: Dynamic Textfield on the form, how to retreive all data and implode

Posted 04 March 2009 - 10:03 PM

1. Its defined in another part of the script
2. I know..its not supposed to because the function isn't finished
3. the function is called elsewhere
4. The only part of the form you would even need is the names, and again as i described above i could do it a couple ways.

I'm asking for the best way to do it, not actual code. something like "if i were doing it i would use a foreach statement and check the number of "textfield" [which is what it is named "textfield#"] by using [insert function name here].
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3069
  • View blog
  • Posts: 10,750
  • Joined: 08-August 08

Re: Dynamic Textfield on the form, how to retreive all data and implode

Posted 04 March 2009 - 10:12 PM

View Postarshem, on 5 Mar, 2009 - 12:03 AM, said:

I'm asking for the best way to do it, not actual code. something like "if i were doing it i would use a foreach statement and check the number of "textfield" [which is what it is named "textfield#"] by using [insert function name here].

Ok, then I would do something like this:
<?php 
class general {
	var	$id;
	var	$row;
	var	$table = array("some","tables");
	var	$dblink;
	var	$servername='localhost';
	var	$dbusername='root';
	var	$dbpassword='root';
	var	$dbname='somdatabase';

function __construct() {
	$this->dblink = mysql_connect ($this->servername, $this->dbusername,$this->dbpassword) or die('CONNECTION ERROR: Could not connect to MySQL');
	mysql_select_db($this->dbname,$this->dblink) or die ('Could not open database '.mysql_error());
	}

function read_table($x) {
	$query = "SELECT * FROM ".$this->table[$x]." where id = '".$this->id."'";
	$dbdata = mysql_query($query,$this->dblink) or die('Error reading from '.$this->table[$x]." ".mysql_error());
	$this->row = mysql_fetch_array($dbdata);
	}
	
function update_table($x) {
	$query = "update ".$this->table[$x]." set ";
	foreach($this->row as $key => $value) {
		if(!is_numeric($key) && $key != "id") { 
			$query .= $key." = '".$value."', ";
			}
		}
	$query = substr($query,0,-2)." where id ='".$this->id."'";
	mysql_query($query,$this->dblink) or die("Error updating ".$this->table[$x]." ".mysql_error());
	}

}	
?>


I'd add an insert function that would be similar to the update function.

This post has been edited by CTphpnwb: 04 March 2009 - 10:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1