Topic: codeing question

okay, so i got this value in my posts table am_poster_gender and its a not null varchar(255) and the default is male. but it keeps being read as null


$user_avatar =':'  .$cur_post['am_poster_gender']. ' end';


any idea why?

Re: codeing question

Has the column been added to the query?

3 (edited by SoraCross 2007-01-20 23:41)

Re: codeing question

i dont really understand that question too much, but i did modify post.php to take in that value from user.php, oh, and i should say that my problem is in viewtopic.php

Re: codeing question

Smartys is asking if you selected am_poster_gender from the database table. You should post the sql query.

5 (edited by SoraCross 2007-01-21 00:35)

Re: codeing question

isnt
$user_avatar =':'  .$cur_post['am_poster_gender']. ' end';
the query? can you show me what the query looks like, and where its at in viewtopic.php?

okay, now i understand. i just now edited the query:

$result = $db->query('SELECT u.am_gender, u.cm_cash, u.cm_bank, u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS p.am_poster_gender, username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());


i need to get u.am_gender to go into p.am_poster_gender and than p.am_poster_gender to $cur_post['am_poster_gender'] i think, so how would i do that?

cause currently i get a cannot fetch post info error.

oh, and i'm new at this, so if you see a better way please tell me.

Re: codeing question

Now that you edited the query it should work with $cur_post['am_poster_gender'] as long as you're in the while($cur_post = $db->fetch_assoc($result)) statement.

7 (edited by SoraCross 2007-01-21 03:11)

Re: codeing question

so any idea why i'm getting an error than? did i edit it correctly?

edit:

okay, i fixed that, but its still not showing up >.<

heres my current query:

edit 2: okay, i finally fixed that, but now in post.php, i'm trying to get this code to run when i reply to a topic, but its erroring on me.

$db->query('SELECT am_gender  FROM  '.$db->prefix.'users WHERE user.id = '.$pun_user['id'].';')

or error('Unable to create post', __FILE__, __LINE__, $db->error());

$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, am_poster_gender) VALUES(\''.$db->escape($username).'\', '.$pun_user['id'].' , '.$pun_user['am_gender'].')')

or error('Unable to create post', __FILE__, __LINE__, $db->error());

$new_pid = $db->insert_id();

Re: codeing question

umm, bump?

Re: codeing question

So you're trying to add the user's gender in every post?

Re: codeing question

yup! so any idea whats wrong with that code?

Re: codeing question

Probably the issue is that the posts table doesn't have a am_poster_gender field, or it does?

Re: codeing question

it does actualy, thats why i dont get hy its erroring. i think my SQL sintax is messed up, or my user.am_gender isnt getting to $pun_user['am_gender']

Re: codeing question

echo $pun_user['am_gender'] and see what value you get. Btw, out of curiosity, why you want to include the gender in the post when you have it in the profile?

Re: codeing question

i just like having it in the post. so people with dial up dont have to load a differant page to see the gender.
i got a 24k connection, so i know how it is ^^;;

Re: codeing question

SoraCross wrote:

i just like having it in the post. so people with dial up dont have to load a differant page to see the gender.

Yeah but you can retrieve user data from the database and show it in the topic.

E.g. line 186 in the viewtopic.php file

$result = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());

Now if you have a field in the users table for the gender you can add u.gender from the selection and show it in the page.

Re: codeing question

ohh, okay, thanks!

Re: codeing question

Welcome.