Jump to content

ibinod

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Posts posted by ibinod

  1. I've a table that has over a million of records,

     

    the table has a column `cat` varchar(250) NOT NULL with index

     

    i need to execute a query in this manner

    SELECT `cat`, COUNT(`cat`) as total FROM `products`  GROUP BY `cat` HAVING `total` > 1 ORDER BY `total` DESC  LIMIT 0, 200 

     

    and it takes about 2.5 sec to execute using index, temp tbl and filesort but when i remove the order by statement it only takes about 0.05 sec to execute with only using index.

     

    can someone please explain me what i can i do to minimize the execution time for my query with having orderby

     

    Thank you very much

     

  2. Hi, i am trying to make a simple code that can submit content automatically using curl

     

    i have the following code

     

    This is to login to the site which works perfectly

     

    		$curl_connection = curl_init("http://www.familyfriendsphotos.com/login.php");
    		curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 300);
    		curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
    		curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); 
    		curl_setopt ($curl_connection, CURLOPT_POST, 1);
    		curl_setopt($curl_connection, CURLOPT_ENCODING, 'gzip,deflate');
    		curl_setopt($curl_connection, CURLOPT_AUTOREFERER, true);
    		curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
    		curl_setopt($curl_connection, CURLOPT_TIMEOUT, 10);
    		curl_setopt($curl_connection, CURLOPT_COOKIEJAR, ‘cookie.txt’);
    		curl_setopt($curl_connection, CURLOPT_COOKIEFILE, ‘cookie.txt’);
    
    
    		$post_data['uname'] = $dir['user'];
    		$post_data['pswd'] = $dir['pass'];
    		$post_data['Submit']="Login";
    
    	 	foreach ( $post_data as $key => $value) {
    			//echo ("Key:".$key."=>".$value);
    			$post_items[] = $key."=".$value;
    		}
    		$post_string = implode ("&", $post_items); 
    		//echo $post_string;
    		curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); 
    		$result = curl_exec($curl_connection);
    
    		unset($post_data);
    

     

     

    and to submit the article  i have the following code

    curl_setopt($curl_connection, CURLOPT_URL, 'http://www.familyfriendsphotos.com/submitart.php');
    $post_data['author'] = $article['author'];
    $post_data['parentId'] = $article['cat'];
    $post_data['f_arttitle'] = $article['title'];
    $post_data['f_artsummary'] = $article['short_desc'];
    $post_data['f_artbody'] = $article['article'];
    $post_data['f_artres'] = $article['resource'];
    $post_data['f_artkey'] = $article['keywords'];
    $post_data['key']="avachars_key";
    $post_data['submit'] = "Submit";
    
    
    foreach ( $post_data as $key => $value) 
    {
        $post_items[] = $key."=".$value;
    }
    $post_string = implode ("&", $post_items); 
    curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); 
    $result = curl_exec($curl_connection);
    echo ($result);
    curl_close($curl_connection); 
    
    

     

    But i get invalid http request like this

    ERROR

    The requested URL could not be retrieved

     

    While trying to process the request:

     

    POST /thankyou.php HTTP/1.1

    Host: www.familyfriendsphotos.com

    Accept: */*

    Accept-Encoding: gzip,deflate

    Referer: http://www.familyfriendsphotos.com/thankyou.php

    Cookie: PHPSESSID=5f2127a0cd9045e3f38d1ab0b3684d2f

    Content-Length: 3585

    Content-Type: application/x-www-form-urlencoded

    Expect: 100-continue

     

     

    The following error was encountered:

     

        * Invalid Request

     

    Some aspect of the HTTP Request is invalid. Possible problems:

     

        * Missing or unknown request method

        * Missing URL

        * Missing HTTP Identifier (HTTP/1.0)

        * Request is too large

        * Content-Length missing for POST or PUT requests

        * Illegal character in hostname; underscores are not allowed

     

    Please tell me what should i do to fix this

     

  3. and cud you please provde me a sampe code or something i tried various thing but it's not working

     

    It'll be like this:

     

    echo preg_replace('/http:\/\/www.mysite.com\/name\/(.*?)\//ie',"strtolower('\\1')",$str);

     

    The e modifier tells it that the thing in the second argument should be evaluated as PHP code.

     

     

    Hi, thanks a lot it works when i use the e modifier but it add extra \ at the end how can i remove this

     

  4. Can anyone help me pls i can't get this working

     

    $str = '<p>The reality TV’s most hated man has some harsh words for Oscar-winning actress <a href="http://www.mysite.com/name/Angelina_Jolie">Angelina Jolie</a>';
    
    echo preg_replace('/http:\/\/www.mysite.com\/name\/(.*?)\//i',strtolower('\\1'),$str);
    
    

     

    how can i modify this so the strtolower will work and only the last part string will be lowercased like Angelina_Jolie to angelina_jolie

     

    Thanx.

  5. Hi, thanx again but $cats is an associative array so how do print it's contents on the first loop

     

    i want this to output like this

     

    <ul class="pics">
    <li>this li for 12 times</li>
    </ul>
    <ul class="pics2">
    <li>and this for the remaining time</li>
    </ul>
    

    i want to do this without breaking it

     

     

  6. Hi neil thanks for helping but it's not working as i want , i have done something like this but still i am having problem could you pls helpme

     

    i have come with this but still i am having some problem

     

    //$cats is an array containing database records
    <ul class="pics">
    foreach($cats as $key => $cat) 
    {
    if($key <12)
    {
    	echo '<li>records with images'.$key.'</li>';
    }
    else
    {
    	echo '<li>records without images'.$key.'</li>';
    }
    }
    </ul>
    
    

     

    this is it but i would like the second li with different ul class so how do i do it if i place ul after foreach it will loop <ul> and i don't want it i just want to change the class

  7. Hi,

     

    I am building a gallery and i am stuck with this please help me with this

     

    ok lets assume that i have 100 entries in my database cats table each with id, pic, thumb feild

     

    now in my php i want to do like this i want to select 70 entries and while looping

     

    i want to loop through the first 12 records and break it there and again from the same loop i want it to continue

     

    what i want is i want to show thumbs for the first 12 records and only text for the rest records,

    so how do i do this

     

    Thanks a lot

  8.  

    //i have some text in the database like this

    $string = "  �Public Enemy Number One� has long interested people who have then journeyed to visit his last resting place;

    ♪♫ Zac Efron & Jessica Alba WIN '07 Teen Choice Hottie Award";

     

    // i have this function to remove un necessory tags (actually those are for urls)

    function sef_rep($name)

    {

    $name = html_entity_decode(strtolower($name));

     

    $remove = array("/", "'", "`", "!", "(", ")", ".", "@", "+", " ", "_", "<", ">", "?", ":", ";", "&", "#", ",");

    $result_str = str_replace($remove, '-', $name);

    return $result_str;

    }

     

    //so when i echo this those special characters haven't gone

    echo sef_rep($string);

     

     

     

     

    so pls post me a solution to remove special chars like �

  9. Hello RussellReal,

     

    actually i m making a script to get news content from yahoo rss and along with it i am getting characters like those �♪♫ and making XHTML invalid,

    so what's the best way to remove those and similar chars

     

    and how do i loop through text to remove those,

     

    thanx

  10. You can try something different like this:

     

    <?php
    $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray');
    for($i = 0;$i < count($author_quotes);$i++)
    {
    $color = $colors[$i%7];
    echo '<blockquote class="' . $color . '">' . $author_quotes[$i] . '</blockquote>';
    }
    ?>

     

    Thanx alot mate,

    that worked as i wanted.

     

    Regards

  11. Not sure I quote understand. There's an array $author_quotes, you want to display all the quotes once in a different color class? Or what?

     

     

    Let's assume i have 100 different quotes to get from my database

     

    and i have seven different styles

     

    so i want to display those 0 to 100 quotes from (0- blue to 6- gray again 7-blue to 13-gray) like this

     

     

    You mean like this -

    <?php $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray'); ?>
    
    <?php
    foreach($author_quotes as $quote) :
         foreach ($colors as $key => $color) :
    ?>
              <blockquote style='color: <?php echo $color; ?>;'><?php $quote['quote'] ?></blockquote> <?php // so what i want her is i want to use the colors in the above array in place of blockquote class ?>
    <?php
        endforeach;
    endforeach;
    ?>
    

     

    Yes, somewhat like that, i tried that previously also but what happens there is it repeats each quote 7 time so i don't want it to repeat the quotes, just the colors from blue to gray

  12. acutally it's abit like this

     

    <?php $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray'); ?>
    
    <?php foreach($author_quotes as $quote) : ?>
    <blockquote class=""><?php $quote['quote'] ?></blockquote> <?php // so what i want her is i want to use the colors in the above array in place of blockquote class ?>
    <?php endforeach; ?>
    

  13. greetings,

     

                <?php $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray'); ?>
                <?php foreach ($author_quotes as $quote): ?>
                <blockquote class="">...</blockquote>
                <?php enforeach; ?>
    

     

    the $author_quotes is an array from database and it has more than 100 entry so what i am trying to do here is i want to repeat the colors from blue to gray and again blue to gray from the $colors array

    in

    <blockquote class="(here)">..</blockqutoe>

     

    i have been trying different looping method but i can't make it work, so i came over here, pls post me a quick n short soln

    regards

  14. Hi Mchl thanks for the suggestion

    btw i don't want to use the full name coz every username may not have same length so i thought to use only 4 chars,

     

    btw there is one thing i need your suggestion on, since i will be using their username as dynamic salt so wt if a username is needed to be changed in future, after that how can i verify the salt;

    wt do u suggest on this.

     

  15. after working a while i came out with this function for salting my hashes

    please suggest me wt i can do to improve it or is it ok to use for my projects

    function saltHash($username, $password)
    {
    $salt = substr($username,0,4); //all username will be atleast 4 chars so i thought good to take only 4 chars
    return hash("sha512",$password.$salt);
    }
    
    

    and while authenticating i m checking like this

    function checkHash($hash, $username, $password)
    {
    $saltWas = substr($username, 0, 4);
    if($hash == hash("sha512",$password.$saltWas))
    {
    	return true;
    }
    return false;
    }
    
    

     

    btw i am using varchar(150) to store the hashes

  16. I have a menu table which contains column like this

       

    id

           

    name

           

    link

           

    position

           

       

    1

           

    Home

           

    home.php

           

    1

           

       

    2

           

    About

           

    about.php

           

    2

           

       

    3

           

    Contact

           

    contact.php

           

    3

           

       

    4

           

    Faq

           

    faq.php

           

    4

           

       

    5

           

    Message

           

    msg.php

           

    5

           

       

    6

           

    Downloads

           

    down.php

           

    6

           

     

    now let's say i want to change the position column value to 2 of id column that has id 1 and at the same time i want to change the position column value to 1 which has position value 1

    can you pls suggest me how do i do this using php

     

    using mysql i was able to do like this but pls suggest me a better way to do it using php

    UPDATE menu SET position = 1 WHERE id = 2;
    UPDATE menu SET position = 2 WHERE position = 1;
    

     

  17. hi,

    sasa thank you very much for your prompt reply  i tried but i don't think it worked as i wanted pls let me explain this a bit

    my database has menu table

    which contains various columns which have one link column

     

    and my index file routes like this

     

    
    define('APP_DIR','mvc');
    $url = $_SERVER['REQUEST_URI'];
    $url = preg_replace('/^\/('.APP_ROOT.'\/)?/','',$url);
    
    $params = array(); //this holds various variables values passed
    
    $match_route = false; //makes the route match false by default
    
    //routes to loop for the given url
    $routes = array (
    			array('url' => '/^$/', 'controller' => 'home', 'view' => 'home'), // this routes to the home page or default page
    			array('url' => '/^cats\/?$/', 'controller' => 'category', 'view' => 'home'), // this routes to the categories page
    			array('url' => '/^cats\/(?P<view>\d+)\/([0-9A-Za-z_-]+)\/?$/', 'controller' => 'viewcat', 'view' => 'viewcat_home') // this routes to the view cats page
    
    			);
    
    foreach ($routes as $urls => $route) //loops over the urls to route
    {
    if (preg_match($route['url'], $url, $matches))
    {
    	$params = array_merge($params, $matches); //mergest the url value with params array
    	$match_route = true; // makes the route match true
    	break; //breaks the loop once route is found
    }
    
    if(!$match_route)
    {
    	die('The are no such routes'); // gives error if no matches are found
    }
    
    include(CONTROLLER_PATH.$route['controller'].'php'); // inlcludes the required controller
    include(TEMP_PATH.'skins/template.php'); //includes the default template
    }
    
    
    

     

    so all i want to is store the routes on my database so pls give me some suggestion on this

  18. Hi,

    i am creating db based routes for my sef urls and i am in need of some help here

     

    currently without using database this is my routes struction

     

    $routes = array (
    array('url' => '/^cats\/?$/', 'controller' => 'cats', 'view' => 'show'),                       
    /*[... and so on]; */
                            );
    

     

    but i am trying to replace the value cats from the value in my database

    like..

    $row['link'];
    

     

    i tried to use foreach and while loopes  after

     array ( //foreach loops
    ); 

    but i get an error,

    can someone pls guide the right way to do this or some alternative way to store my routes for my simple mvc framework in database.

     

  19. firstly my database structure is like this

    main_category table contains id and title column

    sub_category table also contains id and title column

    & category table contains various feilds including main_cat and sub_cat feild

     

    and i have created those function

     

      function results_array($result)
    {
      $result_array = array();
    	for ($i=0; $row = mysql_fetch_array($result) ; $i++)
    	{
    	   $result_array[$i] = $row; 
    	}
    
    	return $result_array;
    }
    
    
    //function to get main category tables array
    function main_cats()
    {
    $connect = connect_db(); //connects to db
    $query = "SELECT * FROM main_category ORDER by id DESC";
    $result = mysql_query($query);
    if(mysql_num_rows($result) == 0)
    {
    	return false;
    }
    $result = results_array($result); //turns the results into array using for loop function
    return $result;
    }
    
    function sub_cats()
    {
    $connect = connect_db(); //connects to db
    $query = "SELECT * FROM sub_category ORDER by id DESC";
    $result = mysql_query($query);
    if(mysql_num_rows($result) == 0)
    {
    	return false;
    }
    $result = results_array($result); //turns the results into array using for loop function
    return $result;
    }
    

     

    now what i want to do is i want to create a function similar to above that outputs the results as an array

    $main_cats = main_cats();
    $sub_cats = sub_cats();
    
    foreach ($main_cats as $main_cat):
    echo $main_cat['title']."<br />";
    
    foreach ($sub_cats as $sub_cat):
    echo $sub_cat['title']."<br />";
    
    	$GetCat = mysql_query("SELECT * FROM cats WHERE main_cat='".$main_cat['id']."' AND sub_cat='".$sub_cat['id']."' ORDER BY title ASC");
    	while($GSc = mysql_fetch_array($GetCat)) 
    	{
    		echo $GSc['title'];
    	}
    
    
    
    endforeach;
    
    endforeach;
    

    the above code gives me wt i want but i want to put it inside a function and return results as an array

     

    pls help me

×
×
  • 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.