Note that there are some explanatory texts on larger screens.

plurals
  1. POsubstring issue/question
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>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.</p> <p>I have the substring working like this in order to remove the last character only:</p> <pre><code>$upcNum = $r[upcNumber]; $imageName = substr($upcNum, 0, -2); </code></pre> <p>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...</p> <p>$upcNum = "123456789" substr($upcNum, 0, -2); //12345678</p> <p>anyhow here's my for loop code, hopefully you can help me shed some light on this annoying issue...thanks!</p> <pre><code>$spiceType[0] = "Chiles"; $spiceType[1] = "Teas"; $spiceType[2] = "Botanicals"; $spiceType[3] = "Spices"; $spiceType[4] = "Herbs"; $counter = 1; for($i=0; $i&lt;count($spiceType); $i++){ $result = mysql_query("SELECT * FROM `spices` WHERE `type`='$spiceType[$i]' ORDER BY ID")or die(mysql_error()); $spiceCat = $spiceType[$i]; echo '&lt;tr&gt; &lt;td&gt;&lt;/td&gt;&lt;td&gt;'.$spiceCat.'&lt;/td&gt; &lt;tr&gt;'; 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' &lt;tr&gt; &lt;td width="10"&gt;'.$counter.'&lt;/td&gt; &lt;td width="200"&gt;'.$pname.'&lt;/td&gt; &lt;td width="20"&gt;&lt;p align="right"&gt;'.$qty.'&lt;/p&gt;&lt;/td&gt; &lt;td width="50"&gt;'.$price.'&lt;/td&gt; &lt;td width="200"&gt;&lt;p align="center"&gt;'.$upcNum.'&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;img src="upcjpeg/'.$imageName.'" height="30%" width="41%"&gt;&lt;/td&gt; &lt;tr&gt;'; $counter++; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload