simplypixie 123 Posting Pro in Training

The reason I asked if the site was database driven was that I was thinking you could go with what the client wants but advise them that they will have to add all the images themselves (which may put them off anway :) ) and then you can load a set number of thumbnails / images each time a page is loaded and use pagination to go through the rest and this way the images won't all need loading into the page at once and your client remains happy. Just a thought (though I do completely agree that the number of photos is far too excessive and pointless but you may never be able to persuade the client).

simplypixie 123 Posting Pro in Training

As GliderPilot says - however, just to clarify as well, the error you are getting is telling you that $subcategory (in your query) is either empty or in an incorrect format.

Where is the value assigend to $subcategory coming from (I don't see anything in your code where a value is assigned to this variable)? I am presuming you are posting the value from a form therefore you need to be using $_POST to obtain the data (for example - please adjust to match your form / variable name):

if (isset($_POST) && !empty($_POST['subcategory']) {
  $subcategory = $_POST['subcategory'];

  // Do rest of query here

}
simplypixie 123 Posting Pro in Training

I really fee lfor you - sounds like a nightmare client.

Is the site (or these pages) database driven or static html?

simplypixie 123 Posting Pro in Training

Your code for the add to cart would help, but in general (this is an example) if your button has name="add_to_cart", you just need to check it that data is posted:

if (isset($_POST['add_to_cart']) {
// Do what you need to do here
}
simplypixie 123 Posting Pro in Training

To keep it really simple (unless I am missing something), you could just use

SELECT * FROM trans_table WHERE from_id NOT IN (SELECT mem_id FROM position_table)
simplypixie 123 Posting Pro in Training

You can tell I don't work with arrays very much (well not like this anyway) :) That's got it sorted, thank you again.

simplypixie 123 Posting Pro in Training

Thank you, that makes sense and I have implemented the code which is now working better, in that I have an array as I expect it to be.

The problem now arising is that I am only getting 10 array items printed out when I should have 24.
The current code

$imgDirectory = 'images/portfolio/';
$folders = scandir($imgDirectory);
$images = array();
foreach ($folders as $folder) {
    if ($folder != '.' && $folder != '..') {
        $imgDir = 'images/portfolio/'.$folder.'/';
        $images = array_merge($images + glob($imgDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE));
    }
}
print_r($images);

Gives me

Array ( 
    [0] => images/portfolio/fireplaces/empty-fireplace.jpg 
    [1] => images/portfolio/fireplaces/fireplace-work-in-progress-1.jpg 
    [2] => images/portfolio/fireplaces/fireplace-work-in-progress-2.jpg 
    [3] => images/portfolio/fireplaces/fireplace-work-in-progress-3.jpg 
    [4] => images/portfolio/fireplaces/stove-installation-2.jpg 
    [5] => images/portfolio/fireplaces/wood-burning-stove.jpg 
    [6] => images/portfolio/fireplaces/stove-installation.png 
    [7] => images/portfolio/fireplaces/stoves-main-image.png 
    [8] => images/portfolio/stonework/0_82615200_1339141214.jpg 
    [9] => images/portfolio/stonework/house-stonework.jpg 
)

As you can see there are only 2 image folders being added to the array when there should be 4 (if I echo out the $folder in the foreach I get all 4 folders) and also in the images/portfolio/stonework folder there are actually 10 images in the folder but only 2 have been added to the array.

I can see no reason why the number of array items is 'limited' and why the other 2 folders aren't being added to the array.

Any ideas?

simplypixie 123 Posting Pro in Training

My brain is not functioning! I am trying to select a number of random images (lets say 3) from a selection of folders within one other folder and I am either over complicating the code or am missing something as I can't quite get it to work.

What I have so far is

$imgDirectory = 'images/portfolio/';
$results = scandir($imgDirectory);
$images = array();
foreach ($results as $result) {
    if ($result != '.' && $result != '..') {
        $imgDir = 'images/portfolio/'.$result.'/';
        $images[] = glob($imgDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
    }
}
$randomImages = array_rand($images, 3);

foreach ($randomImages as $value) {
    echo $value.'<br>'; // this is just set up for testing at the moment
}

My code is getting all of the sub-folders as expected and then is also getting all the images in each folder. However when I try to echo those images, all I am getting is the array index number. If I dump the array, I get

Array ( 
    [0] => Array ( ) 
    [1] => Array ( 
        [0] => images/portfolio/kitchens/0_64446400_1339145292.jpg 
        [1] => images/portfolio/kitchens/0_98163100_1339145225.jpg
    ) 
    [2] => Array ( 
        [0] => images/portfolio/patios/0_08724600_1339141112.jpg 
        [1] => images/portfolio/patios/0_16298600_1339141074.jpg 
    ) 
    [3] => Array ( 
        [0] => images/portfolio/stonework/0_13904600_1339140361.jpg 
        [1] => images/portfolio/stonework/0_25698100_1339141591.jpg 
    ) 
    [4] => Array ( 
        [0] => images/portfolio/stoves-fireplaces/wood-burning-stove.jpg 
        [1] => images/portfolio/stoves-fireplaces/empty-fireplace.jpg 
    ) 
)

There are more images but I didn't think you needed to see the full list. As you can see I have a multi-dimensional array with a random empty array at index 0 and I cannot access the image files in the …

simplypixie 123 Posting Pro in Training

I would suggest re-installing wordpress as there is obviously some sort of error with its settings on the server.

simplypixie 123 Posting Pro in Training

Turn on error reporting as if you are getting a completely blank page then something is going wrong in either the code at the top of the page, or one of your include files.

<?php
session_start();

ini_set('display_errors',1); 
 error_reporting(E_ALL);

// rest of code here
?>
simplypixie 123 Posting Pro in Training

What exactly is the problem you are having (what errors etc) as WP comes with built in fuctions for adding images to posts or as featured images?

simplypixie 123 Posting Pro in Training

Can you give us a link to the page in question?

simplypixie 123 Posting Pro in Training

Have you actually tried what I suggested as the issue of padding, margins and borders being added to a div width only happens in Firefox and Chrome?

Also, you haven't got any padding, margins or borders combined with width of 100% on your header, navigation or footer as you say you have, what you have is outer containers (i.e. #navigationwrap) with a width of 100% and the margin, padding and border applied to the inner container (i.e. #navigation), this is not the same as having one div (as in your #content) that has all of these elements and therefore adds all the 'widths' together to form an overall width.

simplypixie 123 Posting Pro in Training

It is due to the fact that padding, borders and margins all add to the overall width of the div they are applied to (if you remove all these elements from your content div you will see what I mean). One solution is to add this to the top of your stylesheet (I am not saying this is the correct thing to do)

* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

Otherwise you need to calculate your margins, borders and padding as percentages and reduce the overall width of the div by the total of these percentages.

simplypixie 123 Posting Pro in Training

You won't be able to with your current layout as the telephone number is part of your header image and as that is always the same size regardless of the screen size, your widgets will only ever line up underneath the telephone number when the screen is at a certain size. Also, your header, container, columns and rows are a complete mess (sorry to be blunt) with things like your widgets being placed outside the header area and your nav inside, yet it appears below your widgets plus unecessary column divs that are empty and not doing anything.

I am afraid there is far too much work to be done to correct all this layout in my free time so all I can suggest is to learn more about the grid layout, tidy up your html and css and even strip everything out and put each bit back in one at a time so you can see how it all fits together and what is and isn't required.

I would also suggect removing your telephone number from the header image and have it as text in a div floated to the right (as with your widgets) so that they always line up and also ensure your actual header image is within a div that uses a number of columns that actually fits the size of the image.

simplypixie 123 Posting Pro in Training

Looking again at your CSS and HTML I see you are using a grid system and so you need to use that for your widgets as well and if you want to position to the right you use the .push-number-of-columns to move it across that number of columns.

Something like (I am not sure how much space you need for your widgets so adjust accordingly, and each combination of the number of columns for the div and the number to push over from the left must always add up to 12 unless you have other divs in the same row)

<dv class="two columns push-nine">Widgets here</div>

However, not only do you need to sort all your multiple stylesheets but your grid CSS is bloated and most of it unecessary so I would recommend having a look around for a pre-styled grid that has much less code in it.

simplypixie 123 Posting Pro in Training

I am not sure why you have so many stylesheets and inline style as well, but I think I have found your class for the widgets which has a right margin of 500px so it will always be pushed 500px from the right of the containing box as the page (and therefore the containing box) gets bigger or smaller.

Where exactly do you want the social icons positioned in realtion to the other content in the header?

simplypixie 123 Posting Pro in Training

Oh well, it might have helped :)

simplypixie 123 Posting Pro in Training

It cannot be anything to do with the code on your receiving page as the error is Undefined Index, meaning the variable $salesimage has received no value (no data has been posted for the image), and this has been confirmed by you printing out the file array and it being empty.

I have just noticed that you have no action defined in your opening form tag so how are you actually sending the form data to the script?? Change it to

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">

And see if that helps. If not then I have no other solutions or suggestions apart from stripping all the other form elements and php out apart from those elements related to the file upload and see if it works then and if so, slowly add bits back in to find what is causing the issue.

simplypixie 123 Posting Pro in Training

Having that empty array means that the image is not being passed through with the form, maybe the file size is too big or there is some other error with the file (have you got any checks in place for situations like this)?

simplypixie 123 Posting Pro in Training

What exactly prints out, please post here (is it just an empty array?)

simplypixie 123 Posting Pro in Training

Have you tried this to ensure you are getting the data passed through?

print "<pre>";
print_r($_FILES);
print "</pre>";
simplypixie 123 Posting Pro in Training

Try it like this

$insert_sql = "INSERT INTO detail_paket (id_paket, menu_paket) select paket.id, %s from paket where paket.nama_paket='$nama_paket'";
 $format_sql = sprintf($insert_sql, $data1[$i]);
 mysql_query($format_sql);
simplypixie 123 Posting Pro in Training

I might be totally worng, but would you not need to check for both a and b separately

SELECT *
FROM t1
WHERE a NOT IN
    (
        SELECT a
        FROM t1
        WHERE c = 5 AND d = 6
    )
AND b NOT IN
    (
        SELECT b
        FROM t1
        WHERE c = 5 AND d = 6
    )
AND b NOT IN (1, 2, 3, 4)
simplypixie 123 Posting Pro in Training

What exactly gets messed up?

simplypixie 123 Posting Pro in Training

Yes this is all fine

simplypixie 123 Posting Pro in Training

Unless you are assigning the $_POST['main_category'] to a variable called $main_category_p somewhere that we can't see, then you won't get anything echo'd out. You either need to assign the posted value to your new variable $main_category_p = $_POST['main_category'];or you should be using

if($_POST['main_category'] == "Choose..."){ $_POST['main_category'] = ""; }
echo "$_POST['main_category']";
simplypixie 123 Posting Pro in Training

Glad I could help, but please mark as Solved.

simplypixie 123 Posting Pro in Training

@blocblue - I wouldn't but the OP wanted to know how to do sub-queries as hasn't learnt about joins yet and I am just trying to help them do what they want to do at the moment (espeically if they can't do a sub-query yet then they are really going to struggle with joins).

simplypixie 123 Posting Pro in Training

If you really want to use sub-queries, and presuming you want to show all posts by each user, then this is the sort of thing you will need (I don't know how you want to layout on the page or what your columns are named in your table so have guessed and you will have to adjust accordingly)

$sq= mysql_query("SELECT user_id, username FROM users");

while ($user = mysql_fetch_array($sq)) {
    $sq2 = mysql_query("SELECT * FROM posts WHERE user_id='".$user['user_id']."'");

    echo '<p>'.$user['username'].'</p>';

    while ($posts = mysql_fetch_array($sq2)) {
        echo '<p>'.$posts['title'].'</p>';
        echo '<p>'.$posts['content'].'</p>';
    }
}

If you want to only pull users that actually have posts then combine what you already have with what I have put

$sq= mysql_query("SELECT user_id, username FROM users WHERE user_id IN (SELECT user_id FROM posts)");
simplypixie 123 Posting Pro in Training

Change your Applications LI to this (and add a class to your parent ul):

<ul class="vertical-menu">
.
.
<li><a href="#">Applicants</a>
    <ul class="submenu">
      <li><a href="active-applicants.aspx">Active Applicants</a></li>
      <li><a href="inactive-applicants.aspx">Inactive Applicants</a></li>
    </ul>
</li>
.
.
</ul>

And in your CSS (please change or add any additional required styling, this is the bare bones to show the sub-menu out to the right of the main menu)

ul.submenu {
    position: absolute;
    left: -999px;
    margin-left: 160px; /* This should be the same as the width of your main menu */
    z-index: 1000;
}
.vertical-menu li:hover ul.submenu {
    left: auto;
}
simplypixie 123 Posting Pro in Training

shahai.ali - I presumed that was what it is for and if it is set to auto-increment you don't need to include any reference to it in your insert query, the database will automatically add the id for you. Have you actully tried the new code??

diafol - indeed, good advice!

simplypixie 123 Posting Pro in Training

Try this correction to your code (not sure what the NULL is for in your query and so have removed, I have also guessed at the field name in your table):

$fileName =  $_FILES["f_name"]["name"];
            $path = "uploads/" . $filename;         
            }
            mysql_query("INSERT INTO mytable file_path VALUES ('".$path."')") or die(mysql_error());
simplypixie 123 Posting Pro in Training

Why on earth do you want to store someone's password in a session - no need and very insecure???

Regardless of this, your login is obviously working as you get redirected as per your code, but the username stored in the session is incorrect, nowhere in your script have you set a variable $username, you have only set $username_p, therefore your $_SESSION['username'] = $username will never be populated with any information as it should be $_SESSION['username'] = $username_p.

As a side note, your are duplicating the PHP to check if a user is logged in (it is in both your header file and your index file, which already includes the information from your header file).

simplypixie 123 Posting Pro in Training

Looking at what you have in the other preg_replace functions, shouldn't #[^0-9#]i actually be #[^0-9]#i

With regard to your include files, that is down to you to check the paths to the files are correct I am afraid.

As for the mysql_num_rows issue, your query will presumably not work until you have resolved the preg_replace issue.

simplypixie 123 Posting Pro in Training

It really depends on what you want???

simplypixie 123 Posting Pro in Training

Just 'Google' it - there is so much information out there.

simplypixie 123 Posting Pro in Training

You need to learn responsive design / development if you want your site to work on mobile.

simplypixie 123 Posting Pro in Training

Further to diafol's advice, in your current code, you have a lot wrong. This is what is should be (based on what you have already) - please compare this code to what you have to see your mistakes:

<!-- <form action="ContactUs.php" method="POST"> this shouldn't be here -->
<?php
if (isset($_POST)) {
    $firstname = $_POST['fname'];
    $products = $_POST['products'];
    $email = $_POST['email'];
    if (isset($firstname) && isset($email) && isset($products)) {
        echo "Thank you ".$firstname." for interest in ".$products.". We will contact you soon.";      
    } else {
        echo "Please complete the form correctly";
    }
}
?>

This is a vary basic example for you using your existing code, please combine with diafol's advice above.

simplypixie 123 Posting Pro in Training

Echo out your query (echo $nypost;) and make sure that the actual query being run looks correct and if so then run it in phpmyadmin and see if you get any errors there.

simplypixie 123 Posting Pro in Training

It won't do anything as you have assigned the query to a variable that you are doing anything with so vchange it to

if(isset($_POST['submit'])){
    mysql_query("INSERT INTO arkentider (typ) VALUES('$_POST[typ]')")
    or die("Kunde inte lägga till ny räkning:<br />".mysql_error());
    }
// OR

if(isset($_POST['submit'])){
    $nypost = "INSERT INTO arkentider (typ) VALUES('$_POST[typ]')"
    or die("Kunde inte lägga till ny räkning:<br />".mysql_error());
    mysql_query($nypost);
    }
simplypixie 123 Posting Pro in Training

This is a big, complex page of code so I think the best thing (rather than keep trying to post bits of it on here) is that I will strip it right back and see if I can find a cause of the problem like that.

simplypixie 123 Posting Pro in Training

I have been wondering why you thought the query only returned one record and realised I explained things slightly incorrectly - within the running orders table there are duplicate entry_ids (one for each class number entered) but the class numbers aren't duplicated, so in the case of my query above the result will be 4 class numbers for the one entry id. Hope this clarifies it better.

simplypixie 123 Posting Pro in Training

The code calling the function is

$classes_entered = new entries;
$class_entries = $classes_entered->get_online_classes_per_dog($entries['entry_id']);

This is set within a while loop but not sure what bearing it has on the query in the function as the echo of mysql_num_rows is within the function and all other function calls within the while loop work as expected.

simplypixie 123 Posting Pro in Training

I am baffled, I have the following query which should return 4 records but for some reason it is counting 8 records and returning each row twice. I know I could use distinct, but as I also know that there are no duplicate records in this table I don't want to resolve the problem that way but find out what is causing it.

public function get_online_classes_per_dog($entry_id) {

        $sql = mysql_query("SELECT class_number FROM running_orders WHERE entry_id='".$entry_id."' ORDER BY class_number ASC");

        echo mysql_num_rows($sql);

        $results = mysql_fetch_array($sql);

        return $results;
    }

I have echo'd the $sql and run in directly in the database and I get 4 records as I should but echoing the mysql_num_rows gives me 8 and when I run a while or foreach loop on my main page I get each class_number eching out twice (for example it should be 1, 2, 3, 4 but I am getting 1, 1, 2, 2, 3, 3, 4, 4).

Any ideas, never come across anything like this before and is driving me mad??

simplypixie 123 Posting Pro in Training

Sahil89 - I want to see the 'relevant' code as the poster is saying a width of 100% is creating scrollbars, which it shouldn't, and therefore I want to see the rest of the 'relevant' CSS and HTML (relevant means relevant to the question, i.e. not all of their code) so that I can see what might be causing the scrollbars.

The poster hasn't asked what width to set their page at but has an actual problem with their current code that they need help with which I could possibly help solve if I could see thier code (the same as answering any coding question)!

simplypixie 123 Posting Pro in Training

Please post the relevant sections of your stylesheet and html so we can help.

simplypixie 123 Posting Pro in Training

Sorry if I did this wrong but your query needs to include your $whereClauses variable, so it should be:

$sql = "SELECT * FROM mytable '".$whereClauses."' ORDER BY id DESC '".$limit."'";

Again, echo out your sql to see if the query is correct.

simplypixie 123 Posting Pro in Training

Can you reply rather than leave your findings as a comment :)

So basically, your query runs in the database without any errors but you are still not getting anything displayed on your page? Let's try and put everything together:

$whereClauses = '';
$numLocations = count($_POST['Locations']);
$numJobs = count($_POST['Jobs']);
$i = 0;
    if (! empty($_POST['Locations'])) {
      foreach ($_POST['locations'] as $location) {
        $whereClauses .="Locations='".mysql_real_escape_string($location)."'";
        if ($i++ == $numLocations) {
         $whereClauses .= " AND";
        }
      }
    }
    if (! empty($_POST['Jobs'])) {
      foreach ($_POST['Jobs'] as $job) {
        $whereClauses .="Jobs='".mysql_real_escape_string($job)."'";
      }
      if ($i++ == $numJobs) {
         $whereClauses .= " AND";
      }
    }
$sql = "SELECT * FROM mytable '".$where."' ORDER BY id DESC '".$limit."'";

$result=mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
echo $row['Locations'];
echo $row['Jobs'];
}

I am presuming that your column names are correct in the echo $row['....'] so try the new code and let me know what happens.

simplypixie 123 Posting Pro in Training

In your showJobs_new.php page, change this

$sql = mysql_query("SELECT * FROM mytable ORDER BY id DESC $limit" .$where);

To this

$sql = "SELECT * FROM mytable ORDER BY id DESC $limit" .$where;

In fact I can see where your query is wrong now as well - your $where clause must come before your Order By etc, so actually change the code to this

$sql = "SELECT * FROM mytable '".$where."' ORDER BY id DESC '".$limit."'";

As you can see I have temporarily removed the mysql_query from around your query so that you can echo it, therefore underneath this line add echo $sql; and comment out all code beneath so that when you run the page you will get your query displaying in the page. You can then copy the query that has been echo'd out and run it in phpmyadmin (click the SQL tab in phpmyadmin).

kumar.papneja commented: thx, it worked in PHPmyadmin but not in sql code +0