שאלות

yair24

Member
התגובה שהכי דומה למה שאני צריך:

For those of you familiar with ASP or apache aprea_request_params_as_string, this function should be very welcome to you to turn things like <input type="hidden" name="selected_category_ids[]" value="1"> <input type="hidden" name="selected_category_ids[]" value="4"> <input type="hidden" name="selected_category_ids[]" value="5"> <input type="hidden" name="selected_category_ids[]" value="6"> <input type="hidden" name="selected_category_ids[]" value="7"> into 1, 4, 5, 6, 7 To use it, pass the name from html into this function, WITH the []'s (you can remove the log_func from this function if you want). Basically, this functgion checks for a [] at the end of the string. If it's there, it converts it to a comma delimited string, if not, it returns the value as normal. function getBlindFormData( $form_name ) { if ( !is_string( $form_name ) ) { $this->{$this->log_func} ( "File: %s. Line: %d. \$form_name is NOT a string.", __FILE__, __LINE__ ); } $offs = strlen( $form_name ) - 2; if ( strpos ( $form_name, "[]", $offs ) === $offs ) { $form_name = substr( $form_name, 0, $offs ); $isarray = 1; } else { $isarray = 0; } if ( isset( $_GET[$form_name] ) ) { $request = $_GET[$form_name]; } if ( isset( $_POST[$form_name] ) ) { $request = $_POST[$form_name]; } $ret = NULL; if ( isset( $request ) ) { if ( $isarray ) { $ret = $request[0]; for ( $i = 1; $i < count( $request ); $i++ ) { $ret .= ", ".$request[$i]; } } else { $ret = $request; } } return $ret; } Usage could be as follows To select a comma delimited list of values. $sql = sprintf( "DELETE FROM categories\n" . " WHERE category_id IN ( %s );\n" , $wrapper->getRequiredFormData( "selected_category_ids[]" ) ); or just $wrapper->getOptionalFormData( "category_id" ); for retrieval of a normal http variable. Any questions, problems, bugs you find in this email me at the abvoe email address. (remove the NO before chatgris and the SPAM after chatgris etc.)​
לא הבנתי מזה כלום... יאיר
 

N i X

New member
תראה...

תעשה לך איזה bla.php
<form action="bla.php" method="get"> <input type="text" name="myvar[]" value="1"> <input type="text" name="myvar[]" value="4"> <input type="text" name="myvar[]" value="5"> <input type="text" name="myvar[]" value="6"> <input type="text" name="myvar[]" value="7"> </form> <? print_r($_GET['myvar']); ?>​
אתה כבר תראה...
 

N i X

New member
מספיק ללחוץ enter.

זה מראה לך איך זה עובד, השדות, והמערך. הקוד של bla2.php בהודעה הקודמת. כאילו, אחריי שאתה שולח את זה אתה מקבל מערך, $_GET['myvar']; ובו יש לך את הvalues לפי הסדר.
 

N i X

New member
תראה:

bla.php:
<?php $bla = $_GET['id']; print('<pre>'); print_r($bla); print('</pre>'); ?>​
אם תקרא לזה ככה:
http://raven.nix.org.il/~yury/bla.php?id=1&id=2&id=3​
תקבל 3. כי זה הvalue האחרון.
 

yair24

Member
נכון!!

אבל אני יודע שASP ממפה בצורה אוטומטית דברים כאלה למערך ויש דרך לקרוא אותם כמערך (משהו עם * אני לא זוכר בדיוק איך אבל זה ממש רעיון יפה) כנראה שבPHP אין את השיטה הזאת...
 

Mr Boggy Man

New member
כמה מילים על session

א. ואוו זה שירשור שלם של 2 אנשים בלבד ב. בנייה נכונה של session לא תאפשר פריצות או תקלות. session בכללית יותר מאובטח מcookie כוון שcookie נשמר על המחשב של הלקוח והלקוח יכול להתחיל לשחק עם שטויות שיש שם. בכלל הפעולות של cookie וsession שניהן דומות. ג. יאיר, יש פורומים עם אלפי משתמשים שמחוברים ביחד באותו הזמן שעובדים עם session. לדוגמא phpBB, ולאף אחד מהם אין בעיות יותר מדי גדולות של ביצועים. פה זה לא asp, פה אתה לא גוזל את חייך בשביל עוד יום שהמחשב ירוץ
 

YuvalCo

New member
בקשר לשאלה הראשונה..

זה פשוט למדי... אתה לא מעביר את זה כמשתנים בתוך הלינק, אלא כ post.. ואז אתה עושה משהו כזה:
<input type="checkbox" name=pd[] value=<?=$msg[id]?>>​
ואז הוא יעביר לך מערך $pd שבו כל ה id של ההודעות שסומנו.. כך שתוכל לעשות:
$pd=$_POST[pd]; foreach ($pd as $delete) delete_post($delete);​
 
למעלה