arrays!! aahhggggrrr

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
uilleann
Forum Newbie
Posts: 10
Joined: Fri Jul 03, 2009 10:51 am

arrays!! aahhggggrrr

Post 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!
HavokDelta6
Forum Newbie
Posts: 16
Joined: Mon Sep 28, 2009 4:11 pm

Post by HavokDelta6 »

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Last edited by HavokDelta6 on Tue Mar 20, 2012 5:55 am, edited 1 time in total.
uilleann
Forum Newbie
Posts: 10
Joined: Fri Jul 03, 2009 10:51 am

Re: arrays!! aahhggggrrr

Post by uilleann »

Hazaa! Thanks HavokDelta! Once I get some time today I'll throw it in and see what I get.
uilleann
Forum Newbie
Posts: 10
Joined: Fri Jul 03, 2009 10:51 am

Re: arrays!! aahhggggrrr

Post 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.
Post Reply