Jump to content

dreamwest

Members
  • Posts

    1,223
  • Joined

  • Last visited

    Never

Posts posted by dreamwest

  1. Another way to do it to query the database and write the whole thing to a file

     

    /*************** config ***************/
    $mysql_host='';
    $mysql_database='' database name
    $mysql_username=''; // user name
    $mysql_password=''; // password
    
    $storing_dir = ""; // directory path with an ending slash
    
    /******************* end config ************/
    $file_name = $mysql_database."_".date('YmdHis').".sql";
    
    $link = mysql_connect($mysql_host, $mysql_username, $mysql_password);
    if (!$link)
    {
       fwrite($fh, 'Could not connect: ' . mysql_error());
       exit();
    }
    
    $db_selected = mysql_select_db($mysql_database, $link);
    if (!$db_selected)
    {
    fwrite($fh, 'Can\'t use $mysql_database : ' . mysql_error());
    exit();
    }
    
    $myFile = $storing_dir . $file_name;
    $fh = fopen($myFile, 'w') or die("can't open file");
    _mysqldump($mysql_database);
    fclose($fh);
    
    function _mysqldump($mysql_database)
    {
    global $fh;
    _mysqldump_schema_structure($mysql_database);
    $sql="show tables;";
    $result= mysql_query($sql);
    if( $result)
    {
    
    	while( $row= mysql_fetch_row($result))
    	{
    		_mysqldump_table_structure($row[0]);
    		_mysqldump_table_data($row[0]);
    	}
    }
    else
    {
    	$content =  "/* no tables in $mysql_database */\n";
    	fwrite($fh, $content);
    }
    mysql_free_result($result);
    }
    function _mysqldump_schema_structure($schema)
    {
    global $fh;
    fwrite($fh, "/* database : `$schema` */\n");
    $sql="show create schema `$schema`; ";
    $result=mysql_query($sql);
    if( $result)
    {
    	if($row= mysql_fetch_assoc($result))
    	{
    		fwrite($fh, $row['Create Database'].";\n\n");
    	}
    }
    fwrite($fh, "USE `$schema`; \n\n");
    mysql_free_result($result);
    }
    
    function _mysqldump_table_structure($table)
    {
    global $fh;
    fwrite($fh, "/* Table structure for table `$table` */\n");
    fwrite($fh, "DROP TABLE IF EXISTS `$table`;\n\n");
    $sql="show create table `$table`; ";
    $result=mysql_query($sql);
    if( $result)
    {
    	if($row= mysql_fetch_assoc($result))
    	{
    		fwrite($fh, $row['Create Table'].";\n\n");
    	}
    }
    mysql_free_result($result);
    }
    
    function _mysqldump_table_data($table)
    {
    global $fh;
    $sql="select * from `$table`;";
    $result=mysql_query($sql);
    if( $result)
    {
    	$num_rows= mysql_num_rows($result);
    	$num_fields= mysql_num_fields($result);
    
    	if( $num_rows > 0)
    	{
    		fwrite($fh, "/* dumping data for table `$table` */\n");
    
    		$field_type=array();
    		$i=0;
    		while( $i < $num_fields)
    		{
    			$meta= mysql_fetch_field($result, $i);
    			array_push($field_type, $meta->type);
    			$i++;
    		}
    
    		//print_r( $field_type);
    		fwrite($fh, "insert into `$table` values\n");
    		$index=0;
    		while( $row= mysql_fetch_row($result))
    		{
    			fwrite($fh, "(");
    			for( $i=0; $i < $num_fields; $i++)
    			{
    				if( is_null( $row[$i]))
    					fwrite($fh, "null");
    				else
    				{
    					switch( $field_type[$i])
    					{
    						case 'int':
    							fwrite($fh, $row[$i]);
    							break;
    						case 'string':
    						case 'blob' :
    						default:
    							fwrite($fh, "'".mysql_real_escape_string($row[$i])."'");
    
    					}
    				}
    				if( $i < $num_fields-1)
    					fwrite($fh, ",");
    			}
    			fwrite($fh, ")");
    
    			if( $index < $num_rows-1)
    				fwrite($fh, ",");
    			else
    				fwrite($fh, ";");
    			fwrite($fh, "\n");
    
    			$index++;
    		}
    	}
    }
    mysql_free_result($result);
    fwrite($fh, "\n");
    }

  2. You need to $_GET the page and use startfrom in your query

     

    http://site.com/index.php?q=searching&page=3

     

    This is an example

    //get the total for the search here
    $total = //query here
    
    $tpage = ceil( $total / 30 );
    $startfrom = ( $page - 1 ) * 30;
    
        $sql = "SELECT * FROM table where something ='query'  LIMIT {$startfrom}, 30";
    $result = mysql_query( $sql );
    
    //now page stuff
    $content_count = mysql_num_rows( $result );
    
        $start_num = $startfrom + 1;
        $end_num = $startfrom + $content_count;
        $prev = $page - 1;
        $next = $page + 1;
        $adjust = 9;
        
        if ( 1 < $page )
        {
            $page_links .= "<a class=pagination_prev href='".$prev."'><< Prev</a><a class=pagination_next href='1'>1</a>....";
        }
        $k = $page - $adjust;
        for ( $page ; $k <= $page + $adjust; ++$k )
        {
            if (( 0 < $k ) && ( $k <= $tpage ) )
            {
                
                if(($page)==($k)){
    			$page_links.="<span class=\"pagination_active\"> ".$k." </span>";
    			} else {
                   $page_links .= "<a class=pagination href='".$k."'>{$k}</a>";
                        		}
         	}
        }
        if ( $page < $tpage )
        {
        
            $page_links .= ".....<a class=pagination_next href='".$tpage."'>".$tpage."</a><a class=pagination_next href='".$next."'>Next >></a>";
            
        }
    
    

  3. Your over complicating it. You just need the total and page reference

    And dont forget ceil

    Example:

     

    
    $page = 1;
    $tpage = ceil( $total_pics / 30 );
    $startfrom = ( $page - 1 ) * 30;
    $start_num = $startfrom + 1;
        $end_num = $startfrom + $total_pics;
        $prev = $page - 1;
        $next = $page + 1;
        $adjust = 9;
        
        if ( 1 < $page )
        {
            $page_links_pics .= "<a class=pagination_prev href='/hdpics/".$prev."'><< Prev</a><a class=pagination_next href='/hdpics/1'>1</a>....";
        }
        $k = $page - $adjust;
        for ( $page ; $k <= $page + $adjust; ++$k )
        {
            if (( 0 < $k ) && ( $k <= $tpage ) )
            {
                
                if(($page)==($k)){
    			$page_links_pics.="<span class=\"pagination_active\"> ".$k." </span>";
    			} else {
                   $page_links_pics .= "<a class=pagination href='/hdpics/".$k."'>{$k}</a>";
                        		}
         	}
        }
        if ( $page < $tpage )
        {
        
            $page_links_pics .= ".....<a class=pagination_next href='/hdpics/".$tpage."'>".$tpage."</a><a class=pagination_next href='/hdpics/".$next."'>Next >></a>";
            
        }

  4. Apparently its the same thing:

     

     href="http://www.mysite.com/?d=9FDS32S" target="_blank">http://www.mysite.com/?d=9FDS32S</a>

     

    in this case yes ... in all cases ... maybe not.

     

    that is why people are trying to give him a solution that works in ALL cases

     

    just explode the href=" part to get the url

     

    Now say after me

     

    $message = 'Regex is the best ! All hail explode';
    
    $value=explode("!", $message);
    $value = trim($value[1]);
    
    echo $value;

  5. Of course it does....and this assumes this is a link

     

    $message = '<a rel="nofollow" href="http://www.mysite.com/?d=9FDS32S" target="_blank">http://www.mysite.com/?d=9FDS32S</a>';
    
    $value=explode("</a>", $message);
    $value=explode(">", $value[0]);
    $value = trim($value[1]);
    
    echo $value;

  6.  

    $message = '<a rel="nofollow" href="http://www.mysite.com/?d=9FDS32S" target="_blank">http://www.mysite.com/?d=9FDS32S</a>';
    
    $value=explode('target="_blank">', $message);
    $value=explode("</a>", $value[1]);
    $value = trim($value[0]);
    
    echo $value;
    

  7. I have a really long document, but only need a single word/s within two specific tags

     

    words here.....

    <link>only get this line</link>

    lots of words here.....

     

    How can i just get what is within the <link> tags??

  8. # permanently redirect from www domain to non-www domain
    RewriteEngine on
    Options +FollowSymLinks
    RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC]
    RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L]

     

    OR

     

    # redirect from old domain to new domain
    RewriteEngine On
    RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]

     

    OR

     

    # redirect an entire site via permanent redirect
    Redirect permanent / http://www.domain.com/

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.