Jump to content

echo $row['RIGHT(fm_auction,4)'] Not working.


bryweb

Recommended Posts

Trying to convert an old ASP script to PHP .

 

I have a script and have trouble getting  echo $row['RIGHT(fm_auction,4)'] to work

 

I have a MySQL database that has table called "auction"  with content like  auction2013,  silent2013,  silent2012 ..... etc.

 

I have 1000's of pictures in a folders called Pics2012,  Pics2013..... etc.

 

Trying to pull the photos out of the directories depending on which auction listed in the "fm_auction" table.  Silent2013 and Auction2013 photos are in  Pics2013,  Silent2012 and Auction2012 photos are in Pics2012,  etc.  So I am trying to pull the last 4 digits from "fm_auction" table

 

This does not work.

 

<a target="_blank" href="/Pics<?php echo $row['RIGHT(fm_auction,4)'] ?>/<?php echo $row['fm_picture'] ?>" />;
<img src="/Pics<?php echo $row['RIGHT(fm_auction,4)'] ?>/Thumbs/<?php echo $row['fm_picture'] ?>" alt="" name="fm_picture" border="0" id="fm_picture" />;
 
results in  
 
<img src="/Pics/Thumbs/63053_FMCA Auction August 26 012.jpg" alt="" name="fm_picture" border="0" id="fm_picture" />;
 
which is not picking up the last 4 of fm_auction as part of the directory name Pics????.
 
 
This does work (pulling the fm_picture name)
<a target="_blank" href="/Pics2013/<?php echo $row['fm_picture'] ?>" />;
<img src="/Pics2013/Thumbs/<?php echo $row['fm_picture'] ?>" alt="" name="fm_picture" border="0" id="fm_picture" />;
 
Hope that makes sense,
 
Any help appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/288076-echo-rowrightfm_auction4-not-working/
Share on other sites

Sorry,   the fm_auction table  data looks like   auction2013,  silent2013,  silent2012,,  auction2009,  silent2008. 

 

I am trying to grab the year from the end,  and append it to the end of the folder name "pics" in this part of the code

<img src="/Pics<?php echo $row['RIGHT(fm_auction,4)'] ?>/Thumbs/
<img src="/Pics2013/Thumbs/

Using the above is just netting me 

 

<img src="/Pics/Thumbs/63053_FMCA Auction August 26 012.jpg" alt="" name="fm_picture" border="0" id="fm_picture" />;

-

And its not pulling the 2012 or 2011 etc. last four of silent2012, auction2011 - that is part of fm_auction data.

It looks like you have inadvertently incorporated a BASIC string function in the key expression for $row. So, assuming what you get with $row['fm_auction'] is something like auction2013 and you just want the 2013 part, try:

echo substr($row['fm_auction'],-4);

bsmither,  

 

That worked -  

echo substr($row['fm_auction'],-4)

     

As I was trying things I tried using Substring instead of Right, but not quite the way you had it.

MANY THANKS!!!!!

 

trq,

 

Sorry,  I am still very much the PHP newbie,  the var dump or $row I believe is derived from these two lines.

$result = mysql_query("SELECT * FROM auction
WHERE fm_auction='Auction2013' ORDER BY fm_item") or die(mysql_error());
$row = mysql_fetch_array( $result );

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.