immunity Posted June 24, 2007 Share Posted June 24, 2007 Hello i am confused on php array :/ (no only C++ and Java arrays) so i have $1 $2 and $3 i want to add all inside an array $a then with a for ( int i=0 ; i<x ; i++) $string = $string." ".$a how i write in php code that i want ? Quote Link to comment https://forums.phpfreaks.com/topic/56939-create-an-array-add-a-value-get-value-from-an-array-plz-help/ Share on other sites More sharing options...
trq Posted June 24, 2007 Share Posted June 24, 2007 You'll need to be allot clearer with your explination, thats makes no sense at all. Quote Link to comment https://forums.phpfreaks.com/topic/56939-create-an-array-add-a-value-get-value-from-an-array-plz-help/#findComment-281248 Share on other sites More sharing options...
immunity Posted June 24, 2007 Author Share Posted June 24, 2007 sorry about that :/ ok hear it is i have an html with input texts and i use this page to display member (from Mysql) via javascript i send the "returnvalues.php?account="+document.....value+"... so i get the page for example "returnvalues.php?account=immunity&password=000000&email=&city=" Now inside returnvalues.php I want to make query "Select * from account Where account ='immunity' AND password='000000'"; I dont know when account or password or email or city will be empty I have to use array (i think) so if ( $_GET['account'] !="" ) { add inside array "account='".$_GET['account']."' " } if ( $_GET['password'] !="") {add inside array "password='".$_GET['password']."' "} ...... So the array will be filled only from values those isnt "" No i create a string $sQuery "Select * from account "; and I want to add all the strings of array; (if array is empty = all variables was "" so we let the sQuery as it is and we get all the table member) (if array has values then we add if it's the index 0 "Where ".$a(in the index) if it's the index >0 " ".$a(in that index) Quote Link to comment https://forums.phpfreaks.com/topic/56939-create-an-array-add-a-value-get-value-from-an-array-plz-help/#findComment-281264 Share on other sites More sharing options...
sasa Posted June 24, 2007 Share Posted June 24, 2007 something like this $where = array(); if ( $_GET['account'] !="" ) { $where[] = "account='". $_GET['account']."'";} if ( $_GET['password'] !="") {$where[] = "password='".$_GET['password']."' "} ... if(count($where) > 0) $where = ' WHERE '.implode("OR", $where); $sQuery = "Select * from account". $where; Quote Link to comment https://forums.phpfreaks.com/topic/56939-create-an-array-add-a-value-get-value-from-an-array-plz-help/#findComment-281271 Share on other sites More sharing options...
immunity Posted June 24, 2007 Author Share Posted June 24, 2007 implode = add OR inside the values right ? (because i will have to put WHERE ... AND) ... Thank you very much sasa Quote Link to comment https://forums.phpfreaks.com/topic/56939-create-an-array-add-a-value-get-value-from-an-array-plz-help/#findComment-281280 Share on other sites More sharing options...
sasa Posted June 24, 2007 Share Posted June 24, 2007 her is 35 celsius (very hot) you are right implode(" AND ", $where) dont forget to add spaces Quote Link to comment https://forums.phpfreaks.com/topic/56939-create-an-array-add-a-value-get-value-from-an-array-plz-help/#findComment-281286 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.