Jump to content

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


bryweb
Go to solution Solved by bsmither,

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
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/
Link to comment
Share on other sites

  • Solution

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);

Link to comment
Share on other sites

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 );
Edited by bryweb
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.