Jump to content

create an array , add a value get value from an array plz help !


immunity

Recommended Posts

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 ? :D

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.