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

  • Home
  • SEARCH
  • 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 this simple php script <?php echo '<pre>'; // Outputs all the result
I have this simple regex, [\d]{1,5} that matches any integer between 0 and 99999.
Take a very simple case as an example, say I have this URL: http://www.example.com/65167.html
I have this simple Jsp page: <%@ page language=java import=java.awt.Color%> <% Color background =
Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
This is different than the simple 2 column layout. I need to have this
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I think this must be simple but I can't get it right... I have
I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/ Like
Cron installation is vixie-cron /etc/cron.daily/rmspam.cron #!/bin/bash /usr/bin/rm /home/user/Maildir/.SPAM/cur/*; I Have this simple bash script

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.