Jump to content

dk4210

Members
  • Posts

    154
  • Joined

  • Last visited

Posts posted by dk4210

  1. Hello Guys,

     

    I am trying to make 3 columns of checkboxes but not sure how to do it.. Currently it is just doing one column.. Any ideas?

     

    PHP code

    $result2 = mysql_query("SELECT * FROM benefits WHERE b_status='1' ");
    if($result2){
    
    while($r = mysql_fetch_array($result2)){
    
    echo "<div class=\"cbwrapper\"><label><input type=\"checkbox\" name=\"keys[]\" value=\"".$r["b_id"]."\">".$r["b_name"]."</option></label>
    </div>
      <div class=\"clear\"></div><p>
    
    ";
    
    }
    
    }
    

    Here is my css

     

    .cbwrapper {
    margin-left:20px;
    border:dashed;
    width:160px;
    padding:5px;
    border-width:1px;
    border-color:#8F8F8F;
    background-color:#FFFBEF;
    }
    
    #cbwrapper label {
    float:left;
    
    }

     

     

     

  2. Hello,

     

    I have the following function

    function make_agent_drop($dropname,$parent=''){
    $agents = mysql_query("SELECT * FROM ad_category WHERE cat_status='1'  AND parent_id='".(is_numeric($parent)?$parent:"0")."'") or die(mysql_error());
    $anum = mysql_num_rows($agents);
    if($anum>0){
    	$agentdrop='<select style="width:150px; height:20px; margin-left:100px; font-size:11px;" name="'.$dropname.'" id="'.$dropname.'" class="text" '.(is_numeric($parent)?'':'onchange="update_subcatdrop($(this).val());').'">
    	<option value="0">Select a Category</option>';
    	while($row= mysql_fetch_array($agents)){
    		$agentdrop.='<option value="'.$row['cat_id'].'">'.$row['cat_name'].'</option>';
    	}
    	$agentdrop.='</select>';
    
    }else{
    	$agentdrop= 'No '.(is_numeric($parent)?'Sub':'').'Categories Found.';
    } 
    return $agentdrop;
    
    ;
    }
    

     

    I creates a drop down from database cats and sub cats..  I am trying to figure out how to add a submit button to dynamically appear when it displays the sub category...

     

    Thanks!

    Dan

  3. I found this code but I cant seem to get it to work right. The issue is that if the parent id =0 than its the parent. If its some other number it is considered to be the child and it is referencing the parent.

     

    $nav_query = MYSQL_QUERY("SELECT * FROM ad_category WHERE cat_status='1' && Parent_id='0' ORDER BY cat_name");
    $tree = "";                         // Clear the directory tree
    $depth = 1;                         // Child level depth.
    $top_level_on = 1;               // What top-level category are we on?
    $exclude = ARRAY();               // Define the exclusion array
    ARRAY_PUSH($exclude, 0);     // Put a starting value in it
    
    WHILE ( $nav_row = MYSQL_FETCH_ARRAY($nav_query) )
    {
         $goOn = 1;               // Resets variable to allow us to continue building out the tree.
         FOR($x = 0; $x < COUNT($exclude); $x++ )          // Check to see if the new item has been used
         {
              IF ( $exclude[$x] == $nav_row['cat_name'] )
              {
                   $goOn = 0;
                   BREAK;                    // Stop looking b/c we already found that it's in the exclusion list and we can't continue to process this node
              }
         }
         IF ( $goOn == 1 )
         {
              $tree .= $nav_row['cat_name'] . "<br>";                    // Process the main tree node
              ARRAY_PUSH($exclude, $nav_row['cat_id']);          // Add to the exclusion list
              IF ( $nav_row['cat_id'] < 6 )
              { $top_level_on = $nav_row['cat_id']; }
    
              $tree .= build_child($nav_row['cat_id']);          // Start the recursive function of building the child tree
         }
    }
    
    FUNCTION build_child($oldID)               // Recursive function to get all of the children...unlimited depth
    {
         GLOBAL $exclude, $depth;               // Refer to the global array defined at the top of this script
         $child_query = MYSQL_QUERY("SELECT * FROM `ad_categoy` WHERE parent_id=" . $oldID);
         WHILE ( $child = MYSQL_FETCH_ARRAY($child_query) )
         {
              IF ( $child['cat_id'] != $child['parent_id'] )
              {
                   FOR ( $c=0;$c<$depth;$c++ )               // Indent over so that there is distinction between levels
                   { $tempTree .= " "; }
                   $tempTree .= "- " . $child['title'] . "<br>";
                   $depth++;          // Incriment depth b/c we're building this child's child tree  (complicated yet???)
                   $tempTree .= build_child($child['cat_id']);          // Add to the temporary local tree
                   $depth--;          // Decrement depth b/c we're done building the child's child tree.
                   ARRAY_PUSH($exclude, $child['cat_id']);               // Add the item to the exclusion list
              }
         }
    
         RETURN $tempTree;          // Return the entire child tree
    }
    
    ECHO $tree;
    
    

  4. Hello Guys,

     

    Need a little help here. I have a db structure like this

     

    cat_id |  cat_name | cat_status | parent_id

    1     First Test        1                  0

    2     Just testing   1                 0

    4     Books           1                 2

    5     Cars           1                 0

    6     Ford           1              5

     

    If the parent_id = 0 it is considered to be the parent.

    If it is a number it is considered a child and referencing the parent

     

    I want to be able to query the database and grab the cat and the sub cat and echo it on my page. Its like a classified ads application.

     

    Here is my while loop that I currently have which only echo's out the parent category. I would like to echo the child category under the respective parent category.

     

    I think I would have to do a loop within a loop, but not sure how to do it..

     

    $query  = "SELECT * FROM ad_category WHERE cat_status='1' && Parent_id='0' ORDER BY cat_name";
    		$result = mysql_query($query);
    
    			while($row = mysql_fetch_row($result))
    			{
    			   
    			    $cat_name = $row[1];
    			    
    
    				$cupper = UCWords($cat_name);
    
    			    echo $cupper . "<br>" ;
    			    
    			        
    			} 
    
    

     

     

    Thanks for your help in advance

  5. hmm that's interesting.. The problem is that the upload form displays in the entire form. Short of submitting will checking the session upload count and cause the upload form to disappear when 8 images have been uploaded?

  6. Abra,

     

    I do have one more question if you have a second.. How do i check to see how many fines are in a directory without refreshing or submitting (POST)

     

    Basically what I want to do is this

     

    I have an upload feature on the page and I want to allow up to 8 images to upload and when the user uploads the 8th image I want the upload option to disappear..

     

     

    This would do the trick if I was submitting the form.

     

    $subn = $_SESSION['fname'] . $_SESSION['lname'] ;
        $files = glob("temp_photo/$subn*.*");
        $count = count($files);
        
        echo $count;
    
    if (count <  {
    
    echo "upload_html";
    
    }
    
    
    

     

    I think this will have to be done with ajax.. Any input?

     

    Thanks, Dan

     

     

     

  7. Hello Guys,

     

    I have a var that contains sub strings like this

     

    test058.gif,test1058.gif,test698.jpg,

     

    I want to be able to count how many times the images appear

     

    How would I do that with substr_count?

     

    I tried this

     

    $subn = $_SESSION['fname'] . $_SESSION['lname'] ;
        foreach (glob("temp_photo/$subn*.*") as $filename3) {
       // echo "$filename<br>";
    
    
    $string = $filename3;
    $filename4 = basename($string);
    
    $phstring2 .= $filename4 . ",";
        
    echo $phstring2;
    
    echo substr_count($phstring2, ',');
        }
    
    

     

    But didn't work correctly..

     

    Thanks for your expert help

     

  8. Here ya go lite

     

    if (isset($_POST['Submitad'])) {
    
    
    echo "Congrats ad has been submitted";
    
    //print_r($_POST);
    
    $catid = $_POST['catname'];
    $ad_title = $_POST['ad_title'];
    $ad_body = $_POST['description'];
    $vname = $_POST['viewname'];
    $vphone = $_POST['vphone'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $zip = $_POST['zip'];
    $subn = $_SESSION['fname'] . $_SESSION['lname'] ;
    
    $ad_status = '1';
    
    // Future use
    $ad_type = 'free';
    
    
    
    
    
    
    // Find out what images are in the temp_photo directory
    
    foreach (glob("temp_photo/$subn*.*") as $filename) {
        echo "$filename<br>";
    
    
    $string = $filename;
    $filename2 = basename($string);
    
    // Combining all the vars into one for the query down below
    $phstring .= $filename2;
    
    // Create a folder name for each new members image in the perm directory
    if(!file_exists($subn)) 
    { 
    @mkdir("ad_photos/" . $subn); 
    }  
    
    
    //echo "This is the directory" . $dp;
    
    // Move photos to perm directory being that the form as been submitted
    copy("temp_photo/$filename2","ad_photos/$subn/$filename2");
    }
    
    // Remove all temp files
    foreach (glob("temp_photo/$subn*.*") as $filename3) {
    $tmpfile = $filename3;
    unlink($tmpfile);
    }
    
    
    
    /* Lets do some cleaning up the temp directory, If there are users that 
    upload images, but do not submit, then we want to clean that up randomly
    */
    
    $expiretime=3600; //expire time in minutes
    
    $tmpFolder="temp_photo/";
    $fileTypes="*.*";
    
    foreach (glob($tmpFolder . $fileTypes) as $Filename2) {
    //echo "$Filename2<br>";
    
    // Read file creation time
    $FileCreationTime = filectime($Filename2);
    
    // Calculate file age in seconds
    $FileAge = time() - $FileCreationTime;
    
    // Is the file older than the given time span?
    if ($FileAge > ($expiretime * 60)){
    
    // Now do something with the olders files...
    
    //print "The file $Filename2 is older than $expire_time minutes\n";
    
    //deleting files:
    unlink($Filename2);
    }
    }
    
    // If there are no images uploaded insert the default image
    if($phstring == ""){
    
    $filename2="/images/default.jpg";
    }else{
    echo "This is the file name" . $phstring;
    
    $filename2 = $phstring;
    
    $test = is_array($filename2) ? 'yes' : 'no';
    echo $test;
    
    }
    
    
    
    // Insert ad details into mysql
    $query = "INSERT INTO ads (ad_type,ad_title,ad_body,ad_category,ad_photo,ad_member,ad_status,ad_city,ad_state,ad_zip)VALUES('".$ad_type."','".$ad_title."','".$ad_body."','".$catid."','".$filename2."','".$vname."','".$ad_status."','".$city."','".$state."','".$zip."')";
    
    // Error checking to see if the query was successful
    $result = mysql_query($query) or die (mysql_error()."in <br>$query" );
    
    
    
    exit;
    }
    
    
    
    

  9. Hi ninedoors,

     

    When I run the code you provided it says no..

     

    $filename2="/images/default.jpg";
    }else{
    echo "This is the file name" . $phstring;
    
    $filename2 = $phstring;
    
    $test = is_array($filename2) ? 'yes' : 'no';
    echo $test;
    
    }
    
    
    
    // Insert ad details into mysql
    $query = "INSERT INTO ads (ad_type,ad_title,ad_body,ad_category,ad_photo,ad_member,ad_status,ad_city,ad_state,ad_zip)VALUES('".$ad_type."','".$ad_title."','".$ad_body."','".$catid."','".$filename2."','".$vname."','".$ad_status."','".$city."','".$state."','".$zip."')";
    
    // Error checking to see if the query was successful
    $result = mysql_query($query) or die (mysql_error()."in <br>$query" );
    
    
    

     

    The content for this is images names inserted into the database

  10. Hi Blue Sky,

     

    Getting an error

     

    Updated code

     

    $filename2 = $phstring;
    }
    
    $csv = $filename2;
    
    $fphoto = implode(',', $csv);
    
    // Insert ad details into mysql
    $query = "INSERT INTO ads (ad_type,ad_title,ad_body,ad_category,ad_photo,ad_member,ad_status,ad_city,ad_state,ad_zip)VALUES('".$ad_type."','".$ad_title."','".$ad_body."','".$catid."','".$fphoto."','".$vname."','".$ad_status."','".$city."','".$state."','".$zip."')";
    
    // Error checking to see if the query was successful
    $result = mysql_query($query) or die (mysql_error()."in <br>$query" );
    
    

     

     

     

    Warning: implode() [function.implode]: Invalid arguments passed in

  11. Hello Guys,

     

    I am trying to insert a value in my table like this

    image.jpg,image2.jpg,image3.jpg

    Currently it just runs the image names together

     

    Here is my code.. I tried to use explode, but it just adds the word "array" in the table.

     

    Please advise

     

    $filename2 = $phstring;
    }
    
    $csv = $filename2;
    
    $fphoto = explode(',', $csv);
    
    // Insert ad details into mysql
    $query = "INSERT INTO ads (ad_type,ad_title,ad_body,ad_category,ad_photo,ad_member,ad_status,ad_city,ad_state,ad_zip)VALUES('".$ad_type."','".$ad_title."','".$ad_body."','".$catid."','".$fphoto."','".$vname."','".$ad_status."','".$city."','".$state."','".$zip."')";
    
    
    

     

  12. Hello guys,

    I am having an issue with my if statement. Basically what I am trying to do is when there are no photos uploaded then enter default image. Like I said doesn't look like my if stmt is working at all.. Any ideas?

     

    foreach (glob("temp_photo/$subn*.*") as $filename) {
        //echo "$filename<br>";
    
    
    
    $string = $filename;
    $filename2 = basename($string);
    
    
    if($filename2 == ""){
    
    $filename2="/images/default.jpg";
    
    }
    
    
    
    
    // Insert ad details into mysql
    $query = "INSERT INTO ads (ad_type,ad_title,ad_body,ad_category,ad_photo,ad_member,ad_status,ad_city,ad_state,ad_zip)VALUES('".$ad_type."','".$ad_title."','".$ad_body."','".$catid."','".$filename2."','".$vname."','".$ad_status."','".$city."','".$state."','".$zip."')";
    
    // Error checking to see if the query was successful
    $result = mysql_query($query) or die (mysql_error()."in <br>$query" );
    

  13. Thanks guys for the expert help.. I finally got it to work with the following code

     

    $expiretime=3600; //expire time in minutes

     

    $tmpFolder="temp_photo/";

    $fileTypes="*.*";

     

    foreach (glob($tmpFolder . $fileTypes) as $Filename2) {

    echo "$Filename2<br>";

     

    // Read file creation time

    $FileCreationTime = filectime($Filename2);

     

    // Calculate file age in seconds

    $FileAge = time() - $FileCreationTime;

     

    // Is the file older than the given time span?

    if ($FileAge > ($expiretime * 60)){

     

    // Now do something with the olders files...

     

    //print "The file $Filename2 is older than $expire_time minutes\n";

     

    //deleting files:

    unlink($Filename2);

    }

     

    }

     

  14. I would rather do it in the code as opposed to the cron job

     

    I am also trying this code, but it doesn't seem to work either

     

    // Define the folder to clean

    // (keep trailing slashes)

    $checktfolder  = 'temp_photo/';

     

    // Filetypes to check (you can also use *.*)

    foreach (glob("temp_photo/*.*") as $fileTypes);

    // $fileTypes = $filetypes2;

     

    // Here you can define after how many

    // minutes the files should get deleted

    $expire_time    = 2;

     

    // Find all files of the given file type

    foreach (glob($checktfolder . $fileTypes) as $Filename) {

     

        // Read file creation time

        $FileCreationTime = filectime($Filename);

     

        // Calculate file age in seconds

        $FileAge = time() - $FileCreationTime;

     

        // Is the file older than the given time span?

        if ($FileAge > ($expire_time * 60)){

     

            // Now do something with the olders files...

     

    print "The file $Filename is older than $expire_time minutes\n";

     

            // For example deleting files:

            unlink($Filename);

        }

     

    }

×
×
  • 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.