-1

Thanks a lot to anyone who can help me out! I've uploaded a gift-shop style website to a server running PHP v 5.4.19. The problem is that the image and page references that were fetched on xampp don't appear in the array on the server. Why is this and what is wrong with my code (apart from me not adopting msqli yet)?

        function smallDisplay()
        {

            $query = mysql_query($con, "SELECT `imageSrcQ`, `productCode` FROM `products` WHERE `displayCode` >= 11 && `displayCode` <= 12");

            while ($results_row = mysql_fetch_array($query))
            {

                $returned_results[] = array(
                                    'productCode' => $results_row['productCode'],
                                    'imageSrcQ' => $results_row['imageSrcQ']
                );

            }

            return $returned_results;

        }

        $results = smallDisplay();

        echo $results;



        $x = 0;

        foreach ($results as $result)
        {

            ${'img'.$x} = $result['imageSrcQ'];

            $x++;

        }
        echo $img0;
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
BFalcon
  • 331
  • 1
  • 3
  • 10
  • 1
    Unfortunately, "I wrote some code it doesn't work I have no idea why" is not a suitable question for this site. – Your Common Sense Oct 22 '13 at 09:37
  • anyway, most likely your question already has been answered here: http://stackoverflow.com/questions/16959576/reference-what-is-variable-scope-which-variables-are-accessible-from-where-and – Your Common Sense Oct 22 '13 at 09:41

1 Answers1

-1

Edit: mysql_query does not take $con as the first argument, see: http://php.net/manual/en/function.mysql-query.php.

Change your code to:

$query = mysql_query("SELECT `imageSrcQ`, `productCode` FROM `products` WHERE `displayCode` >= 11 && `displayCode` <= 12");

and it should work.

As a note you might want to declare your $returned_results - array before the loop, and use the mysql_fetch_assoc() instead

user2849406
  • 195
  • 1
  • 1
  • 6