0

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.

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by bobgodwin
0
<?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.

0

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,

0

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.

Edited by colweb: n/a

0

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 }

Edited by bobgodwin: n/a

0

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.

0

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>";
	}
?>

Edited by bobgodwin: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.