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: snip SCRIPT LANGUAGE=JavaScript function showAlert(id,type) { alert('The type is:' + type + ' - The ID is:' + id); } /SCRIPT ? while($row_payments = mssql_fetch_array($result_payments)) { extract($row_payments); $total += $payment_amount; ? tr td width=21ID:/td td width=88a href=javascript:showAlert('?=$child_support_id;?','C')?=$child_support_id;?/a/td td width=98Case Number:/td td width=252?=$case_number;?/td td width=116div align=rightPayment Amount:/div/td td width=105div align=right$?=number_format($payment_amount,2);?/div/td /tr ? /snip 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: td width=88a href=javascript:showAlert('?=$child_support_id;?','?=$request_type;?')?=$child_support_id;?/a/td 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*** table align=center border=0 cellpadding=0 cellspacing=0 width=680 ?php 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']; ? tr td width=21ID:/td td width=88?php echo a href='javascript:showAlert($id)'$id/a ?/td td width=98Case Number:/td td width=252?php echo $case_number; ?/td td width=116div align=rightPayment Amount:/div/td td width=105div align=right$?php echo number_format($payment_amount, 2); ?/div/td input type=hidden name=request_type value=C /tr ?php } } ? /table -- 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 ?php 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']; ? tr td width=21ID:/td td width=88a href=javascript:showAlert('?php echo $id; ?','C')?php echo $id; ?/a/td td width=98Case Number:/td td width=252?php echo $case_number; ?/td td width=116div align=rightPayment Amount:/div/td td width=105div align=right$?php echo number_format($payment_amount, 2); ?/div/td /tr ?php } } ? 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: snip SCRIPT LANGUAGE=JavaScript function showAlert(id,type) { alert('The type is:' + type + ' - The ID is:' + id); } /SCRIPT ? while($row_payments = mssql_fetch_array($result_payments)) { extract($row_payments); $total += $payment_amount; ? tr td width=21ID:/td td width=88a href=javascript:showAlert('?=$child_support_id;?','C')?=$child_support_id;?/a/td td width=98Case Number:/td td width=252?=$case_number;?/td td width=116div align=rightPayment Amount:/div/td td width=105div align=right$?=number_format($payment_amount,2);?/div/td /tr ? /snip 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: td width=88a href=javascript:showAlert('?=$child_support_id;?','?=$request_type;?')?=$child_support_id;?/a/td 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*** table align=center border=0 cellpadding=0 cellspacing=0 width=680 ?php 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']; ? tr td width=21ID:/td td width=88?php echo a href='javascript:showAlert($id)'$id/a ?/td td width=98Case Number:/td td width=252?php echo $case_number; ?/td td width=116div align=rightPayment Amount:/div/td td width=105div align=right$?php echo number_format($payment_amount, 2); ?/div/td input type=hidden name=request_type value=C /tr ?php } } ? /table -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107
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 ?php 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']; ? tr td width=21ID:/td td width=88a href=javascript:showAlert('?php echo $id; ?','C')?php echo $id; ?/a/td td width=98Case Number:/td td width=252?php echo $case_number; ?/td td width=116div align=rightPayment Amount:/div/td td width=105div align=right$?php echo number_format($payment_amount, 2); ?/div/td /tr ?php } } ? 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: snip SCRIPT LANGUAGE=JavaScript function showAlert(id,type) { alert('The type is:' + type + ' - The ID is:' + id); } /SCRIPT ? while($row_payments = mssql_fetch_array($result_payments)) { extract($row_payments); $total += $payment_amount; ? tr td width=21ID:/td td width=88a href=javascript:showAlert('?=$child_support_id;?','C')?=$child_support_id;?/a/td td width=98Case Number:/td td width=252?=$case_number;?/td td width=116div align=rightPayment Amount:/div/td td width=105div align=right$?=number_format($payment_amount,2);?/div/td /tr ? /snip 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: td width=88a href=javascript:showAlert('?=$child_support_id;?','?=$request_type;?')?=$child_support_id;?/a/td 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*** table align=center border=0 cellpadding=0 cellspacing=0 width=680 ?php 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']; ? tr td width=21ID:/td td width=88?php echo a href='javascript:showAlert($id)'$id/a ?/td td width=98Case Number:/td td width=252?php echo $case_number; ?/td td width=116div align=rightPayment Amount:/div/td td width=105div align=right$?php echo number_format($payment_amount, 2); ?/div/td input type=hidden name=request_type value=C /tr ?php } } ? /table -- 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
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
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