Author Topic: Using php to retrieve ListMail data from lm_user  (Read 4240 times)

liberate

  • Posts: 7
    • View Profile
Using php to retrieve ListMail data from lm_user
« on: July 20, 2007, 06:11:58 pm »
Hi Dean

You can probably do this in about 6 lines of php code, me on the other hand, I am at the level of "See Spot Run" (first grade reader).

Could you post a good copy of code that does something like this:

It returns user data based on an assigned id number which is used in their URL to access the website. ie: www.site.com?id=xxxxx  The assigned id #
In my case userID is held in user3 of lm_user

The function unique which returns the unique UID is used to send email to user with link to profile.php

Basically php that finds the right line in lm_user and bring back everything from uid to user10. Other ListMailPro users can just make minor edits and do the same on their websites. OK.. Other inexperienced php'ers can do the same thing.

Or a least give me your assessment.

Thanks

Tom
(Trying to get from kindergarten to first grade in php.  I would not be able to write this from scratch, I just copy bits of code and try to make it work.)


Code: [Select]
<?php##functions.phpfunction dbc() {	//connect to database.	mysql_connect("localhost","user","pasword");	mysql_select_db("listmail");}dbc();function set_uid() {        global $id;	$result = mysql_query("select user3 from lm_users where user3='$id'") or die(mysql_error());     $field = mysql_result($result, 0, 'user3');     return $field;}// All data returned from db to be based// from the ?id=user_id $uid = set_uid();// Get f_namefunction f_name($uid) {$result = mysql_query("select fname from lm_users where user3='$uid'") or die(mysql_error());$field = mysql_result($result, 0, 'fname');return $field;}$f_name = f_name($uid);// Get l_name function l_name($uid) {$result = mysql_query("select lname from lm_users where user3='$uid'") or die(mysql_error());$field = mysql_result($result, 0, 'lname');return $field;}$l_name = l_name($uid);// Get user_name function user_name($uid) {$result = mysql_query("select user5 from lm_users where user3='$uid'") or die(mysql_error());$field = mysql_result($result, 0, 'user5');return $field;}$user_name = user_name($uid);// Get e_mail function _mail($uid) {$result = mysql_query("select email from lm_users where user3='$uid'") or die(mysql_error());$field = mysql_result($result, 0, 'email');return $field;}$email = _mail($uid);// Get offer function _offer($uid) {$result = mysql_query("select user4 from lm_users where user3='$uid'") or die(mysql_error());$field = mysql_result($result, 0, 'user4');return $field;}$_offer = _offer($uid);// Get uniquefunction unique($uid) {$result = mysql_query("select uid from lm_users where user3='$uid'") or die(mysql_error());$field = mysql_result($result, 0, 'uid');return $field;}$unique = unique($uid);?>


DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Using php to retrieve ListMail data from lm_user
« Reply #1 on: July 20, 2007, 08:49:12 pm »
Tom,

There are numerous ways this can be accomplished.  I think you chose a very complicated one. :) Here's how I would do it:
Code: [Select]

<?php// connect to mysql// select db// SQL query + addslashes prevents SQL injection (important!)$row = mysql_query("select uid,fname,lname,email,user1,user2,user3,etc from lm_users where id = '".addslashes($id)."';");// if no row returned then the userID did not exist - exitif(@mysql_num_rows($row)==0) exit('ID not found!');// row found, list user datalist($uid,$fname,$lname,$email,$user1,$user2,$user3,$etc)=mysql_fetch_row($row);echo "UID=$uid<br>First Name=$fname<br>Last Name=$lname<br>Email=$email<br>etc<br>";?>

I hope that helps!
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

liberate

  • Posts: 7
    • View Profile
Using php to retrieve ListMail data from lm_user
« Reply #2 on: July 20, 2007, 09:52:49 pm »
Thank you. And it only took you 3 lines.

I'm learning slowly.

Tom

liberate

  • Posts: 7
    • View Profile
Using php to retrieve ListMail data from lm_user
« Reply #3 on: July 21, 2007, 12:37:31 am »
Ok how is this?

I can't write this stuff, only adapt what I already have.

- Rather then the traffic being lost from a id=xxxx not found, it defaults to "1246"

- In my case sponsor's id will be in the record of users of list 2, so I have to specify list 1

- Since lm_user also contains the records of unconfirmed users I need to specify confirmed.

Here's my edit.

Let me  know if there are any, "OMG you can't do that" in it.

Thnaks
Tom


Code: [Select]
<?php##function.phpfunction dbc() {	//connect to database.	mysql_connect("localhost","user","paswrd");	mysql_select_db("listmail");}dbc();// SQL query find id=xxxx or default  + addslashes prevents SQL injection (important!)    $row1 = mysql_query("select uid,fname,lname,email,user1,user2,user3 from lm_users where list = 1 and cnf = 1 and user3 = '".addslashes($id)."';");  // if no row returned then default row2 if(@mysql_num_rows($row1)==0)     {     $row2 = mysql_query("select uid,fname,lname,email,user1,user2,user3 from lm_users where list = 1 and user3 = 1246;");         list($uid,$fname,$lname,$email,$user1,$user2,$user3)=mysql_fetch_row($row2);    }else{     list($uid,$fname,$lname,$email,$user1,$user2,$user3)=mysql_fetch_row($row1);	}// Testecho "UID=$uid<br> First Name=$fname<br> Last Name=$lname<br> Email=$email<br> id=$user3<br>"; ?>


DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Using php to retrieve ListMail data from lm_user
« Reply #4 on: July 21, 2007, 04:05:49 am »
Tom,

You should only need one list() line.  Simply add a new $row line if 0 rows are found and it will overwrite the previous value of $row.
Code: [Select]
if(@mysql_num_rows($row)==0) $row = mysql_query("select uid,fname,lname,email,user1,user2,user3 from lm_users where list = 1 and user3 = 1246;");
list($uid,$fname,$lname,$email,$user1,$user2,$user3)=mysql_fetch_row($row);

Regards
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting