Break up an array for a query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Deaglex
Forum Newbie
Posts: 24
Joined: Thu Feb 24, 2005 10:15 am

Break up an array for a query

Post by Deaglex »

Hi guyz,

I'm having problems with the following part of the script:
before the submit

Code: Select all

if($row[6]== 1)
		{ 
		$start = 'yes';
		}	
		else {
		$start = 'no';	
		}
		echo "<tr bgcolor=\"$row_color\">
		<td align=\"left\" >$row[0]</td>
		<td align=\"left\" >$row[1]</td>
		<td align=\"left\" >$row[2]</td>
		<td align=\"left\" >$row[3]</td>
		<td align=\"center\" >$row[4]</td>
		<td align=\"center\" >$row[5]</td>
		<td align=\"center\" >$start</td>
		<td align=\"center\" ><select name=\"$row[7]\">
<option value=\"\">-</option>
<option value=\"1\">start</option>
<option value=\"0\">sit</option></td>
		";
		$row_count++;
		}
$di = $row[7];
after:

Code: Select all

if (isset($_POST['submit'])) //redirect if cookie is not set
{
session_name('user_name');
session_start();

$page_title = "My Drivers";

include('./nascarheader2.inc');



$di=$_POST['di'];
$di=explode(" ", $di);
I'm getting all the right information outputed on the original. I need the $row[7] to be identified as $di for submission to the database so it can change the binary table in the DB....

Thanks


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

..and $row[7] is the string 'di' ? Line 16 of the first block has the name of the selection as $row[7] .. meaning you expect $row[7] to ~always be a string 'di'. If $row[7] is not 'di' then switch line 16.
Deaglex
Forum Newbie
Posts: 24
Joined: Thu Feb 24, 2005 10:15 am

Reply

Post by Deaglex »

What I need to happen is the value that corralates with the row is
here is the HTML out put:

Code: Select all

&lt;td align=&quote;left&quote; &gt;Driver 1&lt;/td&gt;
		&lt;td align=&quote;left&quote; &gt;#20&lt;/td&gt;
		&lt;td align=&quote;left&quote; &gt;Chevrolet&lt;/td&gt;

		&lt;td align=&quote;left&quote; &gt;Zend&lt;/td&gt;
		&lt;td align=&quote;center&quote; &gt;134&lt;/td&gt;
		&lt;td align=&quote;center&quote; &gt;402&lt;/td&gt;
		&lt;td align=&quote;center&quote; &gt;yes&lt;/td&gt;
		&lt;td align=&quote;center&quote; &gt;&lt;select name=&quote;8&quote;&gt;&lt;option value=&quote;&quote;&gt;-&lt;/option&gt;&lt;option value=&quote;1&quote;&gt;start&lt;/option&gt;&lt;option value=&quote;0&quote;&gt;sit&lt;/option&gt;&lt;/td&gt;

		&lt;tr bgcolor=&quote;#bbbbee&quote;&gt;
		&lt;td align=&quote;left&quote; &gt;Driver 2&lt;/td&gt;
		&lt;td align=&quote;left&quote; &gt;#0&lt;/td&gt;
		&lt;td align=&quote;left&quote; &gt;Chevrolet&lt;/td&gt;
		&lt;td align=&quote;left&quote; &gt;MySQL&lt;/td&gt;
		&lt;td align=&quote;center&quote; &gt;145&lt;/td&gt;

		&lt;td align=&quote;center&quote; &gt;293&lt;/td&gt;
		&lt;td align=&quote;center&quote; &gt;no&lt;/td&gt;
		&lt;td align=&quote;center&quote; &gt;&lt;select name=&quote;12&quote;&gt;&lt;option value=&quote;&quote;&gt;-&lt;/option&gt;&lt;option value=&quote;1&quote;&gt;start&lt;/option&gt;&lt;option value=&quote;0&quote;&gt;sit&lt;/option&gt;&lt;/td&gt;
I need 8 & 12 to be the $di for the driver in that particular row. so I can use it as such

Code: Select all

$query="UPDATE drivers SET starter='$var' WHERE driver_id='$di'";
After typing this out i see this is not quite the way to go and how would I get a value for ...$var
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

name the select like so:

Code: Select all

echo '<select name="di[' . $row[7] . ']">';
When submitted, you can implode() the results of array_keys() from $_POST['di']
Deaglex
Forum Newbie
Posts: 24
Joined: Thu Feb 24, 2005 10:15 am

Post by Deaglex »

I was wondering if this would work and how could i get $di to be multidimentional.

Code: Select all

<select name=\"di[]\"><option value=\"\">-</option>
<option value=\"".$row[7]. ", 1\">start</option>
<option value=\"".$row[7]. ", 0\">sit</option>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

to get multidimensional, just reference farther into it, basically..

di[1][name][object][24], etc, etc.
Deaglex
Forum Newbie
Posts: 24
Joined: Thu Feb 24, 2005 10:15 am

Post by Deaglex »

cool thanx.
Deaglex
Forum Newbie
Posts: 24
Joined: Thu Feb 24, 2005 10:15 am

I'm still having trouble with getting the submited data out.

Post by Deaglex »

I'm still having trouble with getting the submited data out.
Image

What I want this to do is to update each row with the result of the selection.. I know it has to do with the name of the select option but can't figure out how to get have a value for each of the drivers.
Post Reply