Re: [PHP] Loop problem
On Fri, May 4, 2007 1:02 pm, Dan Shirah wrote: > type = document.Submit.request_type.value If you have only one "request_type" button, JavaScript can sorta figure out which one you want here, cuz there's only one. As soon as you have a whole bunch of them, it's got no idea which one you want... The easiest fix I can see would be to give each submit button a unique name (or id, or both) so that you are looking for something more like: var name = 'request_type_' + id; var type = document.Submit[name].value; or somesuch. I dunno JS well enough to know that I've done the right thing, but go that direction. Maybe even go whole who and use that nifty getElementById function. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Loop problem
No problem. I just prefer to use extract() for areas that are only pulling out a single set of data, or several sets with different variable names within the array. Less typing, no reassignments necessary. Personal preference, that's all. On 5/4/07, Dan Shirah <[EMAIL PROTECTED]> wrote: Thank you Daniel!! I didn't do it exactly as you suggested, but you put me in exactly the right direction! THANK YOU! Below is how I have it working if anyone else is interested. The javascript function showAlert(id,type) { alert( 'The type is:' + type + 'The ID is:' + id ); } The Form ID: Case Number: Payment Amount: $ thanks again. On 5/4/07, Daniel Brown <[EMAIL PROTECTED]> wrote: > > > I know you said it's a form but where does the browser realize > that? > > Using a hidden value such as that would require a POST or GET action > via a form. JavaScript wouldn't work for that. However, you could do > something like this: > > > > function showAlert(id,type) { > alert('The type is:' + type + ' - The ID is:' + id); > } > > while($row_payments = mssql_fetch_array($result_payments)) { > extract($row_payments); > $total += $payment_amount; > ?> > > ID: > href="javascript:showAlert('','C')"> > > Case Number: > > Payment > Amount: > align="right">$ > > > > If 'C' isn't a constant, but rather a dynamic value from a column in > a database (named the same as the convention in your example suggests), then > simply modify it as such: > href="javascript:showAlert('','')"> > > That should do it for you. > > > On 5/4/07, Dan Shirah < [EMAIL PROTECTED]> wrote: > > > > Okay, I think this is a 1/2 PHP problem and 1/2 Javascript > > problem. And I > > think my Javascript problem is being caused by my PHP. Follow? > > > > The code below is a loop of records returned from my query: > > > > 1 - If the result is not empty it will loop through the results. > > 2 - It assigns variables based on columns from the query. > > 3 - The first column of the row is the ID which is used by the > > Javascript to > > pull up the correct record. > > 4 - I put in a hidden value to assign all the rows in this loop a > > "request_type" value. > > 5 - When someone clicks on a record ID it calls the Javascript to > > "alert" > > the ID and request_type. > > 6 - If the loop only returns a single record, the "alert" displays > > correctly. Example: The type is:C The ID is:80 > > 7 - If the loop returns multiple records, the "alert" does not return > > the > > correct values. > > > > Example: The type is:undefined The ID is:80 > >The type is:undefined The ID is:85 > >The type is:undefined The ID is:104 > > > > Why do I only get "undefined" if the loop returns more than a single > > record??? > > > > ***The Javascript*** > > > > function showAlert(id) { > > var type; > > type = document.Submit.request_type.value > > > > alert( 'The type is:' + type + 'The ID is:' + id ); > > } > > > > ***The Form*** > > > > > width="680"> > > > if(!empty($result_payments)) { > > while ($row_payments = mssql_fetch_array($result_payments)) { > >$id = $row_payments['child_support_id']; > >$case_number = $row_payments['case_number']; > >$payment_amount = $row_payments['payment_amount']; > >$total += $row_payments['payment_amount']; > > ?> > > > > > > ID: > > > href='javascript:showAlert($id)'>$id" > > ?> > > Case Number: > > > > Payment Amount: > > $ > number_format($payment_amount, 2); ?> > > > > > > > > > } > > } > > ?> > > > > > -- > Daniel P. Brown > [office] (570-) 587-7080 Ext. 272 > [mobile] (570-) 766-8107 -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107
Re: [PHP] Loop problem
Thank you Daniel!! I didn't do it exactly as you suggested, but you put me in exactly the right direction! THANK YOU! Below is how I have it working if anyone else is interested. The javascript function showAlert(id,type) { alert( 'The type is:' + type + 'The ID is:' + id ); } The Form ID: Case Number: Payment Amount: $ thanks again. On 5/4/07, Daniel Brown <[EMAIL PROTECTED]> wrote: I know you said it's a form but where does the browser realize that? Using a hidden value such as that would require a POST or GET action via a form. JavaScript wouldn't work for that. However, you could do something like this: function showAlert(id,type) { alert('The type is:' + type + ' - The ID is:' + id); } ID: Case Number: Payment Amount: $ If 'C' isn't a constant, but rather a dynamic value from a column in a database (named the same as the convention in your example suggests), then simply modify it as such: That should do it for you. On 5/4/07, Dan Shirah <[EMAIL PROTECTED]> wrote: > > Okay, I think this is a 1/2 PHP problem and 1/2 Javascript problem. And > I > think my Javascript problem is being caused by my PHP. Follow? > > The code below is a loop of records returned from my query: > > 1 - If the result is not empty it will loop through the results. > 2 - It assigns variables based on columns from the query. > 3 - The first column of the row is the ID which is used by the > Javascript to > pull up the correct record. > 4 - I put in a hidden value to assign all the rows in this loop a > "request_type" value. > 5 - When someone clicks on a record ID it calls the Javascript to > "alert" > the ID and request_type. > 6 - If the loop only returns a single record, the "alert" displays > correctly. Example: The type is:C The ID is:80 > 7 - If the loop returns multiple records, the "alert" does not return > the > correct values. > > Example: The type is:undefined The ID is:80 >The type is:undefined The ID is:85 >The type is:undefined The ID is:104 > > Why do I only get "undefined" if the loop returns more than a single > record??? > > ***The Javascript*** > > function showAlert(id) { > var type; > type = document.Submit.request_type.value > > alert( 'The type is:' + type + 'The ID is:' + id ); > } > > ***The Form*** > > width="680"> > if(!empty($result_payments)) { > while ($row_payments = mssql_fetch_array($result_payments)) { >$id = $row_payments['child_support_id']; >$case_number = $row_payments['case_number']; >$payment_amount = $row_payments['payment_amount']; >$total += $row_payments['payment_amount']; > ?> > > > ID: > href='javascript:showAlert($id)'>$id" > ?> > Case Number: > > Payment Amount: > $ number_format($payment_amount, 2); ?> > > > > } > } > ?> > > -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107
Re: [PHP] Loop problem
I know you said it's a form but where does the browser realize that? Using a hidden value such as that would require a POST or GET action via a form. JavaScript wouldn't work for that. However, you could do something like this: function showAlert(id,type) { alert('The type is:' + type + ' - The ID is:' + id); } ID: Case Number: Payment Amount: $ If 'C' isn't a constant, but rather a dynamic value from a column in a database (named the same as the convention in your example suggests), then simply modify it as such: That should do it for you. On 5/4/07, Dan Shirah <[EMAIL PROTECTED]> wrote: Okay, I think this is a 1/2 PHP problem and 1/2 Javascript problem. And I think my Javascript problem is being caused by my PHP. Follow? The code below is a loop of records returned from my query: 1 - If the result is not empty it will loop through the results. 2 - It assigns variables based on columns from the query. 3 - The first column of the row is the ID which is used by the Javascript to pull up the correct record. 4 - I put in a hidden value to assign all the rows in this loop a "request_type" value. 5 - When someone clicks on a record ID it calls the Javascript to "alert" the ID and request_type. 6 - If the loop only returns a single record, the "alert" displays correctly. Example: The type is:C The ID is:80 7 - If the loop returns multiple records, the "alert" does not return the correct values. Example: The type is:undefined The ID is:80 The type is:undefined The ID is:85 The type is:undefined The ID is:104 Why do I only get "undefined" if the loop returns more than a single record??? ***The Javascript*** function showAlert(id) { var type; type = document.Submit.request_type.value alert( 'The type is:' + type + 'The ID is:' + id ); } ***The Form*** ID: $id" ?> Case Number: Payment Amount: $ -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107
[PHP] Loop problem
Okay, I think this is a 1/2 PHP problem and 1/2 Javascript problem. And I think my Javascript problem is being caused by my PHP. Follow? The code below is a loop of records returned from my query: 1 - If the result is not empty it will loop through the results. 2 - It assigns variables based on columns from the query. 3 - The first column of the row is the ID which is used by the Javascript to pull up the correct record. 4 - I put in a hidden value to assign all the rows in this loop a "request_type" value. 5 - When someone clicks on a record ID it calls the Javascript to "alert" the ID and request_type. 6 - If the loop only returns a single record, the "alert" displays correctly. Example: The type is:C The ID is:80 7 - If the loop returns multiple records, the "alert" does not return the correct values. Example: The type is:undefined The ID is:80 The type is:undefined The ID is:85 The type is:undefined The ID is:104 Why do I only get "undefined" if the loop returns more than a single record??? ***The Javascript*** function showAlert(id) { var type; type = document.Submit.request_type.value alert( 'The type is:' + type + 'The ID is:' + id ); } ***The Form*** ID: $id" ?> Case Number: Payment Amount: $
RE: [PHP] Loop Problem
Yes, my apologies. I call the script by scriptname.php?MasterPage=1 or 2 or whatever... -Original Message- From: Erik Price [mailto:[EMAIL PROTECTED] Sent: Monday, March 17, 2003 4:45 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Loop Problem [EMAIL PROTECTED] wrote: > Ok, here's what I got. I'm trying to create an entire site that grabs > all it's information (Page content, titles, link info, etc.) from a > MySQL database. In this site I would like to have sub pages of master > pages. For instance, Page 1 is a master page, Page 2 is a sub page of > Page 1, and Page 3 is a sub page of Page 2 which is a sub page of page > one. Now I would like to display this entire hierarchy if possible. > Here's what I have but either I get an infinite loop or it doesn't work > worth a damn > > mysql_connect("127.0.0.1","webuser",""); > $query="SELECT * FROM PageInfo WHERE PageID>'0' and PageID=$MasterPage > ORDER BY PageID"; I might be mistaken, but it looks like $MasterPage hasn't been defined at this point. This should be giving you an error. ($MasterPage gets defined later, but...) If you have your error-reporting turned off, it might not throw the error, so you are getting all the way to your DB. Try turning your error-reporting up and seeing if this causes you problems. The other thing is I don't understand your query -- why are you selecting where PageID is greater than something and at the same time where it is equal to something else? That is redundant. Finally, in your query, remove the single quotes around the 0. You don't need them, and it may be asking MySQL to treat the 0 as a character or string rather than an integer (and the column type is an integer). I'm not really definite on that last one though (more talking out the butt, I suppose). Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Loop Problem
[EMAIL PROTECTED] wrote: Ok, here's what I got. I'm trying to create an entire site that grabs all it's information (Page content, titles, link info, etc.) from a MySQL database. In this site I would like to have sub pages of master pages. For instance, Page 1 is a master page, Page 2 is a sub page of Page 1, and Page 3 is a sub page of Page 2 which is a sub page of page one. Now I would like to display this entire hierarchy if possible. Here's what I have but either I get an infinite loop or it doesn't work worth a damn mysql_connect("127.0.0.1","webuser",""); $query="SELECT * FROM PageInfo WHERE PageID>'0' and PageID=$MasterPage ORDER BY PageID"; I might be mistaken, but it looks like $MasterPage hasn't been defined at this point. This should be giving you an error. ($MasterPage gets defined later, but...) If you have your error-reporting turned off, it might not throw the error, so you are getting all the way to your DB. Try turning your error-reporting up and seeing if this causes you problems. The other thing is I don't understand your query -- why are you selecting where PageID is greater than something and at the same time where it is equal to something else? That is redundant. Finally, in your query, remove the single quotes around the 0. You don't need them, and it may be asking MySQL to treat the 0 as a character or string rather than an integer (and the column type is an integer). I'm not really definite on that last one though (more talking out the butt, I suppose). Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Loop Problem
Ok, here's what I got. I'm trying to create an entire site that grabs all it's information (Page content, titles, link info, etc.) from a MySQL database. In this site I would like to have sub pages of master pages. For instance, Page 1 is a master page, Page 2 is a sub page of Page 1, and Page 3 is a sub page of Page 2 which is a sub page of page one. Now I would like to display this entire hierarchy if possible. Here's what I have but either I get an infinite loop or it doesn't work worth a damn '0' and PageID=$MasterPage ORDER BY PageID"; $VARS=""; do { $result=mysql_db_query("DynamicDB",$query); $count=(mysql_num_rows($result)); if($count>0) { while($r=mysql_fetch_array($result)) { $LinkText=$r["LinkText"]; $FileName=$r["FileName"]; $LinkAlt=$r["LinkAlt"]; $MasterPage=$r["MasterPage"]; $PageID=$r["PageID"]; $VARS="$PageID ".$VARS; echo "$PageID"; // echo "$VARS"; } } else { } $query="SELECT * FROM PageInfo WHERE PageID>'0' and PageID=$MasterPage"; } while ($MasterPage>0); //echo "$VARS"; $PageIDs=explode(" ",$VARS); $i=0; while(strlen($PageIDs["$i"])>0) { $TheVar=$PageIDs["$i"]; $TheQuery="SELECT LinkText, FileName, LinkAlt FROM PageInfo where PageID=$TheVar"; $TheResult=mysql_db_query("DynamicDB",$TheQuery); $TR=mysql_fetch_array($TheResult); $TheLinkText=$TR["LinkText"]; $TheFileName=$TR["FileName"]; $TheLinkAlt=$TR["LinkAlt"]; echo "$TheLinkText"; $i++; } ?> My table structure looks like this ++--+--+-+--+--- -+ | Field | Type | Null | Key | Default | Extra | ++--+--+-+--+--- -+ | PageID | int(40) | | PRI | NULL | auto_increment | | PageType | varchar(6) | | | master | | | LinkText | varchar(20) | | | linktext | | | FileName | varchar(30) | | PRI | | | | LinkAlt| varchar(100) | YES | | alttext | | | Contents | longblob | | | | | | MasterPage | int(11) unsigned | YES | | 0| | | Active | char(3) | | | yes | | | LinkOrder | mediumint(9) | YES | | 99 | | ++--+--+-+--+--- -+ 9 rows in set (0.03 sec) Thanks in advance... Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] loop problem
Hi All, I'm currently working with a friends that want to use irc protocol at his work cause there is only http proxy. so it is very easy, i found phpIRC and everything works fine...He is very happy i've just seen that some process are always connected. this is really weird. so i started to watch that on details and it seems that the loop which dispatch messages don't stop when Apache client is away Am i wrong ? To sum up, i have a PHP script that loop and send messages to client but when client go away script continue to run. did i see some ghost that does not exist ? Thanks for your answer Manu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php