本帖最后由 xiaoc3 于 2011-02-24 12:22:39 编辑

解决方案 »

  1.   

    接上面 if($blogarr['catid']) {
    DB::query("UPDATE ".DB::table('home_blog_category')." SET num=num+1 WHERE catid='$blogarr[catid]'");
    } $blogarr['uid'] = $_G['uid'];
    $blogarr['username'] = $_G['username'];
    $blogarr['dateline'] = empty($POST['dateline'])?$_G['timestamp']:$POST['dateline'];
    $blogid = DB::insert('home_blog', $blogarr, 1); DB::update('common_member_status', array('lastpost' => $_G['timestamp']), array('uid' => $_G['uid']));
    DB::update('common_member_field_home', array('recentnote'=>$POST['subject']), array('uid'=>$_G['uid']));
    } $blogarr['blogid'] = $blogid; $fieldarr = array(
    'message' => $message,
    'postip' => $_G['clientip'],
    'target_ids' => $POST['target_ids'],
    'tag' => $POST['tag']
    ); if(!empty($titlepic)) {
    $fieldarr['pic'] = $titlepic;
    } if($olds) {
    DB::update('home_blogfield', $fieldarr, array('blogid'=>$blogid));
    } else {
    $fieldarr['blogid'] = $blogid;
    $fieldarr['uid'] = $blogarr['uid'];
    DB::insert('home_blogfield', $fieldarr);
    } if($isself && !$olds && $blog_status == 0) {
    updatecreditbyaction('publishblog', 0, array('blogs' => 1)); include_once libfile('function/stat');
    updatestat('blog');
    } if($POST['makefeed'] && $blog_status == 0) {
    include_once libfile('function/feed');
    feed_publish($blogid, 'blogid', $olds?0:1);
    } if(!empty($__G)) $_G = $__G; return $blogarr;
    }function getmessagepic($message) {
    $pic = '';
    return addslashes($pic);
    }function checkhtml($html) {
    $html = dstripslashes($html);
    if(!checkperm('allowhtml')) { preg_match_all("/\<([^\<]+)\>/is", $html, $ms); $searchs[] = '<';
    $replaces[] = '&lt;';
    $searchs[] = '>';
    $replaces[] = '&gt;'; if($ms[1]) {
    $allowtags = 'img|a|font|div|table|tbody|caption|tr|td|th|br|p|b|strong|i|u|em|span|ol|ul|li|blockquote|object|param|embed';
    $ms[1] = array_unique($ms[1]);
    foreach ($ms[1] as $value) {
    $searchs[] = "&lt;".$value."&gt;"; $value = str_replace('&', '_uch_tmp_str_', $value);
    $value = dhtmlspecialchars($value);
    $value = str_replace('_uch_tmp_str_', '&', $value); $value = str_replace(array('\\','/*'), array('.','/.'), $value);
    $skipkeys = array('onabort','onactivate','onafterprint','onafterupdate','onbeforeactivate','onbeforecopy','onbeforecut','onbeforedeactivate',
    'onbeforeeditfocus','onbeforepaste','onbeforeprint','onbeforeunload','onbeforeupdate','onblur','onbounce','oncellchange','onchange',
    'onclick','oncontextmenu','oncontrolselect','oncopy','oncut','ondataavailable','ondatasetchanged','ondatasetcomplete','ondblclick',
    'ondeactivate','ondrag','ondragend','ondragenter','ondragleave','ondragover','ondragstart','ondrop','onerror','onerrorupdate',
    'onfilterchange','onfinish','onfocus','onfocusin','onfocusout','onhelp','onkeydown','onkeypress','onkeyup','onlayoutcomplete',
    'onload','onlosecapture','onmousedown','onmouseenter','onmouseleave','onmousemove','onmouseout','onmouseover','onmouseup','onmousewheel',
    'onmove','onmoveend','onmovestart','onpaste','onpropertychange','onreadystatechange','onreset','onresize','onresizeend','onresizestart',
    'onrowenter','onrowexit','onrowsdelete','onrowsinserted','onscroll','onselect','onselectionchange','onselectstart','onstart','onstop',
    'onsubmit','onunload','javascript','script','eval','behaviour','expression','style','class');
    $skipstr = implode('|', $skipkeys);
    $value = preg_replace(array("/($skipstr)/i"), '.', $value);
    if(!preg_match("/^[\/|\s]?($allowtags)(\s+|$)/is", $value)) {
    $value = '';
    }
    $replaces[] = empty($value)?'':"<".str_replace('&quot;', '"', $value).">";
    }
    }
    $html = str_replace($searchs, $replaces, $html);
    }
    $html = addslashes($html); return $html;
    }function blog_bbcode($message) {
    $message = preg_replace("/\[flash\=?(media|real)*\](.+?)\[\/flash\]/ie", "blog_flash('\\2', '\\1')", $message);
    return $message;
    }
    function blog_flash($swf_url, $type='') {
    $width = '520';
    $height = '390';
    if ($type == 'media') {
    $html = '<object classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" width="'.$width.'" height="'.$height.'">
    <param name="autostart" value="0">
    <param name="url" value="'.$swf_url.'">
    <embed autostart="false" src="'.$swf_url.'" type="video/x-ms-wmv" width="'.$width.'" height="'.$height.'" controls="imagewindow" console="cons"></embed>
    </object>';
    } elseif ($type == 'real') {
    $html = '<object classid="clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa" width="'.$width.'" height="'.$height.'">
    <param name="autostart" value="0">
    <param name="src" value="'.$swf_url.'">
    <param name="controls" value="Imagewindow,controlpanel">
    <param name="console" value="cons">
    <embed autostart="false" src="'.$swf_url.'" type="audio/x-pn-realaudio-plugin" width="'.$width.'" height="'.$height.'" controls="controlpanel" console="cons"></embed>
    </object>';
    } else {
    $html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'.$width.'" height="'.$height.'">
    <param name="movie" value="'.$swf_url.'">
    <param name="allowscriptaccess" value="none">
    <param name="allowNetworking" value="internal">
    <embed src="'.$swf_url.'" type="application/x-shockwave-flash" width="'.$width.'" height="'.$height.'" allowfullscreen="true" allowscriptaccess="always"></embed>
    </object>';
    }
    return $html;
    }?>
      

  2.   

    看到这么多的代码,头昏昏。思路:
    home_class提交数据时 用mysql_insert_id取得刚刚插入的 $classid = mysql_insert_id();
    查询得到catid :select catid form home_blog where classid='{$classid}';
    然后把 catid catname 插入到home_blog_category表
      

  3.   

    在 $classid = DB::insert('home_class', $setarr, 1); 下面增加几行代码://$classid = DB::insert('home_class', $setarr, 1);
                        $catid = DB::result(DB::query("SELECT catid FROM ".DB::table('home_blog')." WHERE classid='$classid'"));
                        $setarrb = array(
                          'catid'=> $catid,
                          'catname'=> $classname ;
                        );
                        DB::insert('home_blog_category', $setarrb); //这一句可能不准确,你根据实际情况修改,因为我不知道你的数据库操作的类是什么样的。只是依瓢画葫芦写的。
      

  4.   

    $setarrb = array(
                          'catid'=> $catid,
                          'catname'=> $classname ;
                        );
    这个改一下
    $setarrb = array(
                          'catid'=> $catid,
                          'catname'=> $classname
                        );
      

  5.   

    程序是discuz x 1.5文件是 function_blog.php                    $setarrb = array(
                          'catid'=> $catid,
                          'catname'=> $classname ;
                        );出错~~~ 页面变空白
      

  6.   


    成功了,但是catid没写进home_blog表里的catid
      

  7.   

    要在home_blog里插入catid,那就在刚才的代码下面继续:$setarrc = array(
       'classid'=> $classid, 
       'catid'=> $catid  
    );
    DB::insert('home_blog', $setarrc); 
      

  8.   

    这个有问题,,变成发布新内容后,会在HOME_BLOG表里建了两条记录,一条记录是有内容的(其它字段都有内容),另一条内容出了classid有ID,其它全是空的catid还是没写进home_blog里的catid
      

  9.   

    不能同时写进两个表吗,写进home_blog_category和home_blog
    DB::insert('home_blog_category', $setarrb);
      

  10.   

    原来的classid是怎么写进home_blog里的呢,顶顶
      

  11.   

    $setarrc = array(
       'classid'=> $classid, 
       'catid'=> $catid  
    );
    DB::insert('home_blog', $setarrc); 
    仔细看了下,这个错了,删除掉吧==================================
    在 $blogarr['uid'] = $_G['uid'];
    的上面加上 $blogarr['catid'] = $catid;

    就可以了
      

  12.   


    classid是自增字段,不是写进去的,是mysql自动增加的。
      

  13.   


    还是不行,home_blog里的catid=0是不是没有得到catid的值
      

  14.   

    $catid = DB::result(DB::query("SELECT catid FROM ".DB::table('home_blog')." WHERE classid='$classid'"));
                        $setarrb = array(
                          'catid'=> $catid,
                          'catname'=> $classname 
                        );'catid'=> $catid,   catid=0
    是不是这里的原因home_blog写进去后要获取home_blog_category里的catid在更新home_blog里的catid 是不是要这样我是这么想的,研究了一天了,先吃饭去
      

  15.   

    知道问题出在什么地方了
    向 home_class 插入数据后 我们可以得到新插入的classid,
    但是,home_blog并没有插入任何数据,所以依据home_blog.classid = $classid 是查不到任何数据的,
    (因为这个$classid是最新的,home_blog里的这个字段还没有这个值),所以我们就无法得到home_blog的catid。
    要向home_blog插入数据,可是我们不知道catid的值,无法插入呀。您还要提供更详细的表结构,各字段之间的关联关系。不知道 home_class 中有没有catid这个字段啊,
      

  16.   

    home_class 中没有catid
    可能就是catid没有得到值home_class的字段classid classname uid datelinehome_blog_cetegory的字段catid upid catname num displayorderhome_blog的字段blogid uid username subject classid catid viewnum replynum hot dateline picflag noreply friend password favtimes sharetimes status