I need to get a file name from a jpg without the extension to use as id in a span tag. Here's the code I'm using:

<?php
  $result = mysql_query("SELECT * FROM $data_sales_earrings ORDER BY id ASC");
  while($row = mysql_fetch_array($result))
  echo "
<span id=\"need file name from jpg front\"><img src=\"image/sale/".$row['image_item_front']."\" width=\"326\" height=\"435\" /></span>
<span id=\"need file name from jpg back\"><img src=\"image/sale/".$row['image_item_back']."\" width=\"326\" height=\"435\" /></span>

";
?>

The jpgs are image_item_front & 'image_item_back. I know how to strip the extension, but can't get it into the array.

<?php
  $result = mysql_query("SELECT * FROM $data_sales_earrings ORDER BY id ASC");
  while($row = mysql_fetch_array($result))
		$path_parts = $row['image_item_front'];
		$id_front = $path_parts['basename'], 
		$path_parts = $row['image_item_back'];
		$id_back = $path_parts['basename'], 
		echo "<span id=\"".$id_front."\"><img src=\"image/sale/".$row['image_item_front']."\" width=\"326\" height=\"435\" /></span>
                      <span id=\"".$id_back."\"><img src=\"image/sale/".$row['image_item_back']."\" width=\"326\" height=\"435\" /></span>";
	}
?>

This will get the name without extension put it in a variable and use that inside the id tag.

I get this error with this code:

Parse error: parse error in C:\wamp\www\Frank\sales-earrings-db.php on line 140, which is this line:

$id_front = $path_parts,

I get this error with this code:

Parse error: parse error in C:\wamp\www\Frank\sales-earrings-db.php on line 140, which is this line:

$id_front = $path_parts,

Sorry, my mistake. Sometimes I think to quick and press reply to quickly.
It should be:

$path_parts = pathinfo($row['image_item_front']);
$id_front = $path_parts['filename'];
$path_parts = pathinfo($row['image_item_back']);
$id_back = $path_parts['filename'];

basename gives the filename + extension.

Now I get this error:

Parse error: parse error in C:\wamp\www\Frank\sales-earrings-db.php on line 145

It's the last line, the last }

Now I get this error:

Parse error: parse error in C:\wamp\www\Frank\sales-earrings-db.php on line 145

It's the last line, a }

Overlooked your while loop. It should always be while .... { if there are more commands after the while. You only had an echo and I just added a } at the end, but didn't see there was no { at the start.

Duh! I forgot the brackets. It works now. Thanks loads!

Here's the code:

<?php
  $result = mysql_query("SELECT * FROM $data_sales_earrings ORDER BY id ASC");
  while($row = mysql_fetch_array($result)){
		        $path_parts = pathinfo($row['image_item_front']);
                $id_front = $path_parts['filename'];
                $path_parts = pathinfo($row['image_item_back']);
                $id_back = $path_parts['filename'];
		echo "<span id=\"".$id_front."\"><img src=\"image/sale/".$row['image_item_front']."\" width=\"326\" height=\"435\" /></span>
                      <span id=\"".$id_back."\"><img src=\"image/sale/".$row['image_item_back']."\" width=\"326\" height=\"435\" /></span>";
	}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.