[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php-mysql integration script problem with wildcard

Posted on 2004-11-27
11
Medium Priority
?
469 Views
Last Modified: 2008-01-09
       
I have a forum  app which requires its database table(forum_users) be updated with user info and avatars from a table in a separate mysql databse(main site dbase with profile info).  The code works fine to update except in one area: the avatars.  The reason is that the avatars in the main profile dbase are updated periodically by members and are autoincermented in numeration each time. Therfore, some type of wildcard is required as far as I can tell.

The numeration for the jpg images look like this :  3_0_1.jpg

Upon incrementing, the numbers go up 3_0_2.jpg, 3_0_3.jpg etc etc

All variables from the primary dbase table is called for with a * and it calls for and updates all the other parameters correctly.

As for the avatars, I am trying to configure with a LIKE statement and wildcard.  The following combined code as follows for all parameters works fine in this context EXCEPT for the autoincrement problem. It updates only  a  x_0_1.jpg , where x is the user ID(which is called and transferred correctly).  The jpg files are stored in the main site /id_img/ directory.

mysql_query("update forum_users set user_password='".$line["Password"]."', user_joined='".$line["LastReg"]."', user_id='".$line["ID"]."', user_email='".$line["email"]."', user_avatar='/id_img/".$line["ID"]."_0_1.jpg' where user_name='".$line["NickName"]."'");
 
I am not a programmer, but have pieced this together for the avatar transfer alone, but it does not work.  

mysql_query("update forum_users set user_avatar= 'id_img/".$line["ID"].".jpg' where .jpg LIKE '_0_%.jpg' where user_name='".$line["NickName"]."'");  

Help!
0
Comment
Question by:Steve_Newbie
  • 8
  • 2
11 Comments
 
LVL 18

Expert Comment

by:arantius
ID: 12688828
Steve_Newbie,

I'm unsure what exactly your problem is?  If it is this statement:
mysql_query("update forum_users set user_avatar= 'id_img/".$line["ID"].".jpg' where .jpg LIKE '_0_%.jpg' where user_name='".$line["NickName"]."'");  

Then this phrase in it: "where .jpg LIKE" is invalid.
0
 

Author Comment

by:Steve_Newbie
ID: 12688843
Yes, I am sure it is. It certainly is not working.  Again, I am not a programmer and am just looking to tweak the code that IS working with a wildcard so that the transfer of jpg images will include all possible numerations in the area of the number just before the .jpg.  In other words, where I have tried to put a wildcard.  There is never a situation in which two jpg files will be in that table, exclusively only one (e.g.  3_0_1.jpg only;  not 3_0_2.jpg and 3_0_3.jpg etc. )
I hope I am making this clear.

S
0
 

Author Comment

by:Steve_Newbie
ID: 12688847
This may be a stupid combination of code, but this looks a lot like other pieces of similar working code that I called upon to create this ....umm....interesting combination...
S
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
LVL 18

Accepted Solution

by:
arantius earned 1500 total points
ID: 12688943
Like I said, I just can't figure out what you're trying to do.  What i

If you're trying to update the database record to contain the filename that is constantly changing, then you're going to have to get whatever that filename is into a PHP variable, then:

mysql_query("update forum_users set user_password='".$line["Password"]."', user_joined='".$line["LastReg"]."', user_id='".$line["ID"]."', user_email='".$line["email"]."', user_avatar='/id_img/".$line["ID"]."_".$FILENAMEHERE.".jpg' where user_name='".$line["NickName"]."'");

Where $FILENAMEHERE contains "X_Y' where x and y are the two numbers that seem to keep changing.
0
 
LVL 11

Expert Comment

by:Zontar
ID: 12693209
>  where .jpg LIKE '_0_%.jpg' where user_name='".$line["NickName"]."'");

1. What's the name of the column you're trying to match against? The correct syntax for a LIKE clause is

WHERE column_name LIKE 'patterntomatch'

and I don't think .jpg is the name of the column, is it? If it is, it's not a good choice for one.

Multiple tests in the same query are connected using AND:

WHERE somecolumn LIKE 'patterntomatch' AND someothercolumn = 'value'
0
 

Author Comment

by:Steve_Newbie
ID: 12711228
Sorry for the delay and thanks for the help so far.  I am just a code challenged simpleton here.  I think I can explain what I need, modify by example, do the very basics in php and mysql, but certainly cannot write code de novo.

The sql collumn name from which the data is pulled is  Pic_0_addon and contains only a single integer of type  tinyint(3).....As noted the number autoincrements each time a user choosed to change that picture.  The integer is in the X position in the jpg name and is the ONLY one which changes when the user adds a new pic (basically it is the user's thumbnail avatar) :   _0_X.jpg  

As noted above, when it is upgraded, the old jpg and old jpg name is replaced....so, 2 replaces 1, 3 replaces 2, and so forth in the X integer part of the jpg name. The originating sql fields collumn (Pic_0_addon)  NEVER has more than one integer per user.  

I need to be able to capture the current integer, no matter what the X is, and update the other dbase field with the new jpg name.  The program then is able to recognize the jpg which is stored in the main site directory as noted above :  public/id_img/

As long as the user uploads a jpg and NEVER changes it, my integration code above works fine.  But they do, and that is my problem.

I hope this clarifies the mud a bit.

Thanks!
0
 

Author Comment

by:Steve_Newbie
ID: 12711264
Just to complete the description.  The user ID is the first part of the jpg name : so the complete jpg name is usually something like  145_0_X.jpg
0
 

Author Comment

by:Steve_Newbie
ID: 12771031
So, no one can help with this?  I thought it might be easier that this....or I am not making sense.

Help!

S
0
 

Author Comment

by:Steve_Newbie
ID: 12827321
Is this really that difficult or crazy of a question?  Hello out there.....still need help on this please.
Thanks.
SN
0
 

Author Comment

by:Steve_Newbie
ID: 12897281
??????
0
 

Author Comment

by:Steve_Newbie
ID: 12995078
Have not had time to work on this for a while, but here is the end result for those wondering at some point in the future.

I guess I was thinking in reverse with the thought that I could somehow put a wildcard '%' into something like  X_0_%.jpg such that the code asking for the avatar would pull in any file that looked like that, which would have been fine since there was only one possible file at one time in the table with that config.  So, the last integer was irrelevant...any one would work.

Whatever.....but as a I said, I am not a programmer, so the above suggestion was probably more "normal" and works fine with mods.  The final product was:

Filename Pic_0_addon was already in a variable and then,

mysql_query("update forum_users set user_password='".$line["Password"]."', user_region='".$line["City"]."', user_joined='".$line["LastReg"]."', user_id='".$line["ID"]."', user_email='".$line["email"]."', user_avatar='/id_img/".$line["ID"]."_0_".$line["Pic_0_addon"].".jpg' where user_name='".$line["NickName"]."'");

Word.

Thanks.
S  
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question