Page 1 of 1

arrays!! aahhggggrrr

Posted: Sun Oct 04, 2009 10:11 pm
by uilleann
Hello, To anyone who could help me. I am trying to create an array that would hold file names ( just file names, not the full file path) specific to each user id. What I am trying to do is set up an if statement to either start an array or add onto an existing array from a mysql_query. I already know what should go in between the {} of each statement. I believe that it should be organized in such fashion:

Code: Select all

 if(   WHAT GOES HERE?   ){
}
else{
}

I have used count( explode(',',$query) ), although if the field is empty it returns 1 (from what I have realized, because of the defined delimiter), compared to, if the field actually had one key (or in my case, one file name) within the array...that too returns 1. How do I define wither a field is empty or not in an if statement from a query? I would imagine this solves my problem if I can place something that can be defined in the if statement that would reflect wither the field is blank or not rather then how many keys are in the array .I believe their might be a better way around this that I just might not see.

any help on this would be great, thanks in advance!

Posted: Mon Oct 05, 2009 2:42 am
by HavokDelta6
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Re: arrays!! aahhggggrrr

Posted: Mon Oct 05, 2009 7:45 am
by uilleann
Hazaa! Thanks HavokDelta! Once I get some time today I'll throw it in and see what I get.

Re: arrays!! aahhggggrrr

Posted: Tue Oct 06, 2009 7:28 pm
by uilleann
solved that problem

Code: Select all

 
$row = mysql_num_rows($query);
if ($row < '1' ){
}
else{
}
 

Although, still have some problems. if anyone is willing to help, that would be GREAT!

Code: Select all

 
<?php
include('Connection');
 
$userid='24';
 
$query = mysql_query("SELECT person_path_string FROM person_root WHERE username_root_id = '$userid'") or die(mysql_error());
 
$query2 = mysql_fetch_array($query, MYSQL_BOTH);
$query1=explode(',',$query);
 
    $row = mysql_num_rows($query);
 
     $people = array('tim');
 
    if ($row < '1' ){       
    print $userid;
    $peoplei=implode(",",$people);
    $sql2 = mysql_query("INSERT INTO person_root (username_root_id,person_path_string) 
    VALUES('$userid','$peoplei')")  
   or die (mysql_error());      
     }
    else {  
    $si = explode(",",$query2);
    array_push($si, 'josh');
 
    $queryft = "UPDATE picture_root SET picture_path_string = '$si' WHERE username_root_id = '$userid'";
    mysql_query($queryft) or die(mysql_error());
    }
?>
 
 
when there is an empty field, in relation to user id's, the array is set and is viewable in phpmyadmin. When refreshed I get this:
Array ( [0] => Array [1] => josh )
Every time I reload this is what I get, which is aggravatingly different from what I would like to see:
Array ( [0] => tim [1] => josh [2] => john [3] => robert [4] => and so on...... )
I'm not really getting the concept of this, might someone shed some light my way? Thank you.