• I’m using a plugin that provides easily created tabbed content. In that tabbed content, I’m accessing my own data in an external database. I noticed on one of my pages, a plugin I’m using for Recent Posts doesn’t show recent Posts. As I’ve dug around, it produced what it should when I removed the content from my database.

    Trouble shooting, the issue seems to be the connection code.

    if(!$con = mysql_connect("localhost","username_","password")) {
       die("Could not connect to database: ".mysql_error());
    }
    
    mysql_select_db("hhrplayers", $con);

    When I remove that code, the Recent Posts widget works. Of course, my database content doesn’t show up, and I get an error where it should be. When I put that code back in, the database content shows up, but the Posts disappear.

    Any thoughts?

    Here is the rest of the code from that page:

    $sql ="SELECT *
           FROM a_playerRank AS pr
           JOIN playerCollege AS pc ON pr.id = pc.id_player
           WHERE pr.year = '2014'
             AND pc.colleges = '". $page ."'
    ORDER BY (pr.commit='1' AND (pr.college = pc.colleges)) DESC, pc.offer desc, pr.nameLast";
    
    $results = mysql_query($sql);
    
    $position = array (
    '1' =>'PG',
    '2' =>'SG',
    '3' =>'SF',
    '4' =>'PF',
    '5' =>'C'
    );
    
    $currentCollege = false;
    $currentOffer = false;
    
    echo '<div class="recruitWrap">';
    
    while ($line = mysql_fetch_assoc($results)) {
    
     	$collegeCommit = $line['college'];
    
    	if($line['college']	!= $page) {
    		$line['college'] = '';
    		}	
    
    	if($line['college'] == $page && $line['commit'] == '1') {
    
    			if ($currentCollege !=$line['commit']) {
    			$currentCollege = $line['commit'];
    
    			echo '<div class="recruitHeader">Committed</div>';
    				}
    	}
    
    		elseif
    			($currentOffer !=$line['offer']) {
    			$currentOffer = $line['offer'];
    
    				if($line['offer'] == '1') {
    					echo '<div class="recruitHeader">Offered</div>';
    				}
    
    				elseif ($line['offer'] != '1')  {
    					echo '<div class="recruitHeader">Also recruiting</div>';
    				}
    			}
    
    //if((ISSET ($line['college']) && $line['college'] == $line['colleges']) || !ISSET($line['college']))
    
    echo '<div class="recruitRow">
    <div class="recruit">' . $line['nameFirst'] . ' ' . $line['nameLast'] . '</div>';
    
    echo '<div class="recruit recruitHeight">' . $line['feet'] . '\'' . $line['inches'] . '"</div>';
    echo '<div class="recruit recruitPosition">' .  $position[$line['position']] . '</div>';
    
    echo '<div class="recruit recruitSchool">';
    if ($line['city'] !='') {
    	 echo $line['city'] . ' (' . $line['school'] . ')';
    	}
    else {
    	echo  $line['school'] . ' HS';
    }
    echo '</div>'; // city school
    
    echo '<div class="clear"></div>';
    
    echo '</div>';
    
    if($line['commit'] == '1' && $line['college'] != $page) {
    	echo '<div class="otherCollege">Committed to '. $collegeCommit .'</div>';
    	}
    
    }
    echo '<div class="clear"></div>';
    echo '</div>'; // recruit wrap
  • The topic ‘Problem with my Loop and custom PHP…’ is closed to new replies.