bryweb Posted April 27, 2014 Share Posted April 27, 2014 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 More sharing options...
trq Posted April 27, 2014 Share Posted April 27, 2014 What does the data in $row look like? Link to comment https://forums.phpfreaks.com/topic/288076-echo-rowrightfm_auction4-not-working/#findComment-1477491 Share on other sites More sharing options...
bryweb Posted April 27, 2014 Author Share Posted April 27, 2014 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 https://forums.phpfreaks.com/topic/288076-echo-rowrightfm_auction4-not-working/#findComment-1477493 Share on other sites More sharing options...
bryweb Posted April 27, 2014 Author Share Posted April 27, 2014 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. Link to comment https://forums.phpfreaks.com/topic/288076-echo-rowrightfm_auction4-not-working/#findComment-1477494 Share on other sites More sharing options...
bryweb Posted April 27, 2014 Author Share Posted April 27, 2014 I am basing what I did on this article http://www.w3resource.com/mysql/string-functions/mysql-right-function.php Link to comment https://forums.phpfreaks.com/topic/288076-echo-rowrightfm_auction4-not-working/#findComment-1477495 Share on other sites More sharing options...
trq Posted April 27, 2014 Share Posted April 27, 2014 That makes little sense. Again, what does the $row array look like? Hint, use var_dump. Link to comment https://forums.phpfreaks.com/topic/288076-echo-rowrightfm_auction4-not-working/#findComment-1477496 Share on other sites More sharing options...
bsmither Posted April 27, 2014 Share Posted April 27, 2014 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 https://forums.phpfreaks.com/topic/288076-echo-rowrightfm_auction4-not-working/#findComment-1477497 Share on other sites More sharing options...
bryweb Posted April 28, 2014 Author Share Posted April 28, 2014 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 ); Link to comment https://forums.phpfreaks.com/topic/288076-echo-rowrightfm_auction4-not-working/#findComment-1477500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.