$10 for a quick php fix

Discussion in 'Programming' started by Avo19, Aug 12, 2007.

  1. #1
    I've an interlinking script that pulls domains from a MySQL dB by ID and then creates random links using the links associated with that ID.
    I just need some code that will compare the ID to a list of ID's. If the ID matches it ignores or skips that ID and it isn't written to the $domain variable
    This is the domain selection code
    
      
    		while($z < $nb){
    			//select Random domain
    			$query="SELECT domain_id,domain FROM domain ORDER BY rand() Limit 1";
    			$result=mysql_query($query);
    			$num=mysql_numrows($result);
    			$i=0;
    			while ($i < $num) {
    				$predomain_id=mysql_result($result,$i,"domain_id");
    				$domain_id = $predomain_id;
    				$predomain=mysql_result($result,$i,"domain");
    				$domain = $predomain;
    				$i++;
    			}
    
    Code (markup):
    Paypal or egold. Payment after successful test.
     
    Avo19, Aug 12, 2007 IP
  2. wounded1987

    wounded1987 Well-Known Member

    Messages:
    2,914
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    150
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    will see what i can do
    PM u
     
    wounded1987, Aug 12, 2007 IP
  3. Avo19

    Avo19 Well-Known Member

    Messages:
    220
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    anyone else?
     
    Avo19, Aug 12, 2007 IP
  4. theartofennui

    theartofennui Active Member

    Messages:
    117
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    60
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #4
    this code is really ineffecient and does not seem to do much of anything useful. PM me with more details about the overall scope of what you're doing and i'll give you a hand.
     
    theartofennui, Aug 12, 2007 IP
  5. battye

    battye Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    It's pretty hard to give you much help without seeing the code in context (as the previous poster said).

    However, one obvious error was the use of mysql_numrows, it is in fact mysql_num_rows, so this could have caused your entire script to function incorrectly. Also, by having $i = 0 within the while loop, it means it will get reset to 0 every time, making the $i++ null and void. It needs to be defined before the loop begins.

    Try this, I've cleaned it up a bit.

    $i=0;
    
    while($z < $nb)
    {
    // Select random domain
    			
    	$query = "SELECT domain_id, domain 
    	   	  FROM domain 
      		  ORDER BY RAND() 
    		  LIMIT 1";
    
    	$result = mysql_query($query);
    	$num = mysql_num_rows($result);
    			
    	
    	if ($i < $num) 
    	{
    		$predomain_id 	= mysql_result($result,$i,"domain_id");
    		$domain_id	= $predomain_id;
    		$predomain	= mysql_result($result,$i,"domain");
    		$domain 	= $predomain;
    		$i++;
    	}
    }
    PHP:
    I don't use the mysql_result function myself, so I'm hoping that is not the part that is functioning incorrectly.
     
    battye, Aug 13, 2007 IP
  6. serialCoder

    serialCoder Guest

    Best Answers:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    yeah, i agree with the two posters above, although i'm pretty sure that what you wanted to do was easy, the code itself is hard to understand, having it in context would do wonders :)
     
    serialCoder, Aug 13, 2007 IP
  7. Avo19

    Avo19 Well-Known Member

    Messages:
    220
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #7
    Thanks guys, for those that contacted via PM or here. Unfortunately none of the suggested methods work. If anyone is up for writing a custom interlinking script that can pull data selectively from a dB, PM with any queries and an estimated cost.
    cheers
     
    Avo19, Aug 13, 2007 IP