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 6133013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:10:23+00:00 2026-05-23T17:10:23+00:00

So I have this simple PHP loop that is generating html table data with

  • 0

So I have this simple PHP loop that is generating html table data with UPC code numbers (I have 129 total) and the UPC barcode images next to them.

The barcode images vs the upc numbers in the SQL is different by the first and last character. So if I have in SQL 123456789, the jpg barcode is listed as 012345678.jpg. So I have to do some substring work where I add a zero character at the beginning and remove the last one.

All the images appears except for the very last one, and I can’t figure out why this is and why the substring doesn’t seem right either.

I have the substring working like this in order to remove the last character only:

$upcNum = $r[upcNumber];        
$imageName = substr($upcNum, 0, -2);

I thought it was supposed to be -1, not -2 to just to remove the last character… by using the above substr method, this is what I get…

$upcNum = “123456789”
substr($upcNum, 0, -2); //12345678

anyhow here’s my for loop code, hopefully you can help me shed some light on this annoying issue…thanks!

$spiceType[0] = "Chiles";
$spiceType[1] = "Teas";
$spiceType[2] = "Botanicals";
$spiceType[3] = "Spices";
$spiceType[4] = "Herbs";

$counter = 1;       
for($i=0; $i<count($spiceType); $i++){
    $result = mysql_query("SELECT * FROM `spices` WHERE `type`='$spiceType[$i]' ORDER BY ID")or die(mysql_error());
    $spiceCat = $spiceType[$i];
    echo '<tr>
            <td></td><td>'.$spiceCat.'</td>
          <tr>';


    while($r=mysql_fetch_array($result)){
        $pname = $r[productName];
        $qty = $r[qty];
        $price = $r[price];
        $upcNum = $r[upcNumber];
        $imageName = substr($upcNum, 0, -2);
        $imageName = "0".$imageName.".jpg";
        echo'
            <tr>
                <td width="10">'.$counter.'</td>
                <td width="200">'.$pname.'</td>
                <td width="20"><p align="right">'.$qty.'</p></td>
                <td width="50">'.$price.'</td>
                <td width="200"><p align="center">'.$upcNum.'</p></td>
                <td><img src="upcjpeg/'.$imageName.'" height="30%" width="41%"></td>
            <tr>';
        $counter++;

    }
}
  • 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. Editorial Team
    Editorial Team
    2026-05-23T17:10:23+00:00Added an answer on May 23, 2026 at 5:10 pm

    If you have to chop just one character then it should be -1. Check again those strings.

    If only the last image doesn’t appear then it’s either missing or has a different name.

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

Sidebar

Related Questions

i have a site with a simple PHP-Navigation (using $_GET-Variables). HTML-code for navigation links
i have this very simple php script: <?php require 'functions.php'; $token = some-number; $id
I'm writing a simple php/mysql script that gets all ads I have in my
I have this simple function function Login() { var x=prompt(Please enter your name,); var
I have a simple PHP script using imagecreatefromjpeg to create a thumbnail version of
I use simple php dom parser . I have a link in my loaded
Ok so I have an array that holds the following elements: $array['a']['b'][0]['c']; $array['a']['b'][1]['c']; $array['a']['d'][0]['c']['c'];
I have a modal window using jqmodal. I need a button within that modal
Still wrapping my head around SQL and PHP, but hope someone can help with
currently ironing out a way to parse the data of a page: http://www.foundationfinder.ch/ i

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.