Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 116369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:10:02+00:00 2026-05-11T03:10:02+00:00

I have a simplified ajay script, from which I have removed all nonrelevant code.

  • 0

I have a simplified ajay script, from which I have removed all nonrelevant code. The problem I am having is first with my columns array and the subsequent foreach loop. I want to go through each element and change the corresponding element to YES if true and NO if false, I don’t see why it isn’t working.

If there are any problems such as syntax errors or braces or such, they are a problem from simplifying my code, and are not present in the version on my machine.

<?php $con = mysqli_connect('localhost', '', '', ''); if (!$con) {     echo 'Can't connect to MySQL Server. Errorcode: %s\n'. mysqli_connect_error();     exit; } $con->set_charset('utf8');     $query1 = 'SELECT EGGS, SALAD, TREES, REVISED FROM AUCTIONS WHERE ARTICLE_NO = ?';     if ($getRecords = $con->prepare($query1)) {         $getRecords->bind_param('s', $pk);         $getRecords->execute();         $getRecords->bind_result($EGGS, $SALAD, $TREES, $REVISED);         while ($getRecords->fetch()) {         $columns = array('EGGS', 'SALAD', 'TREES', 'REVISED');             foreach($columns as $column) {                 $$column = $columns[$column] ? 'YES' : 'NO';             }             imageSize = imageResize($PIC_URL, 250, 300);             echo '<h1>'.$EGGS.'</h1>';         }     } function imageResize($imageURL, $maxWidth, $maxHeight) {     $imageSize['width'] = 0;     $imageSize['height'] = 0;     $size = getimagesize($imageURL);     if ($size) {         $imageWidth  = $size[0];         $imageHeight = $size[1];         $wRatio = $imageWidth / $maxWidth;         $hRatio = $imageHeight / $maxHeight;         $maxRatio = max($wRatio, $hRatio);         if ($maxRatio > 1) {             $imageSize['width'] = $imageWidth / $maxRatio;             $imageSize['height'] = $imageHeight / $maxRatio;             return $imageSize;         } else {             $imageSize['width'] = $imageWidth;             $imageSize['height'] = $imageHeight;             return $imageSize;         }     } else {         die(print_r(error_get_last()));     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:10:02+00:00Added an answer on May 11, 2026 at 3:10 am

    Your loop is wrong – $columns[‘EGGS’] doesn’t exist:

    $columns = array('EGGS', 'SALAD', 'TREES', 'REVISED'); foreach($columns as $column) {     $$column = $columns[$column] ? 'YES' : 'NO'; } 

    it should be:

    $columns = array('EGGS', 'SALAD', 'TREES', 'REVISED'); foreach($columns as $column) {     $$column = $$column ? 'YES' : 'NO'; } 

    or better still:

    $tmp = array(); $columns = array('EGGS', 'SALAD', 'TREES', 'REVISED'); foreach($columns as $column) {     $tmp[$column] = $$column ? 'YES' : 'NO'; } 

    so that you’re not over-writing your bound variables.

    also note that you should move that constant array declaration outside of your while() loop for performance reasons.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simplified an issue that I've been having trying to isolate the problem,
I have a problem in a VB.Net class library which I have simplified greatly
I have simplified and reproduced my problem in the code below. The error that
I have the following code, which loops through an array of menuoptions and on
I have simplified my code to this internal class Program { private static void
I have a (simplified) table consisting of three columns: id INT PRIMARY KEY NOT
I have the following code (asp.net-mvc, jquery) (i have simplified the example to show
I am trying to retrieve the AST from scala souce file. I have simplified
I have a string lots\t of\nwhitespace\r\n which I have simplified but I still need
I'm trying to write an application using QNetworkManager. I have simplified the code down

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.