• Resolved Jim R

    (@jim-r)


    I’m trying to add content from a separate datatable on the same database as my WP installation. (back story: I have four other instances of doing this via includes, and it all works fine.)

    Starting with getting the single_tag_title of the Page, it prints correctly. I move on to the query, which works, and when I don’t have the $nameFull commented out, it prints every name in the datatable – {first name} space {last name}. That also means at some point it prints the name out in a way that matches $slug.

    However, what I have in the IF isn’t executing, which tells me it’s not recognizing when $nameFull equals $slug.

    $slug = single_tag_title();
     echo $slug;
    
    $query = "SELECT * FROM a_playerRank";
    
    $results = mysql_query($query);
    echo mysql_error();
    while($line = mysql_fetch_assoc($results)) {
    
    	$nFirst = $line['nameFirst'];
    	$nLast = $line['nameLast'];
    	$nameFull = "{$nFirst} {$nLast}";
    
    // echo $nameFull
    
    if ($nameFull == $slug)  {
    
    	$nameFullpic = "{$nLast}{$nFirst}";
    	$phoneMobile = $line['phoneMobile'];
    
    echo '<div class="profileWrap">';
    
    echo '<div class="playerImage">';
    echo '<img src="/wp-content/gallery/'. $line['year'] .'_head_shots/' . strtolower($nameFullpic) . '.jpg"></div>';
    
    	echo '<div class="playerProfile">';
    	echo '<table>';
    	echo '<tr class="pHead"><th>' . $line['nameFirst'] . ' ' . $line['nameLast'] . '</th>
    			<th><span class="year">' . $line['year'] . '</span></th></tr>';
    
    	echo '<tr><td class="playerData">' . $line['height'] . ' ';
    		if ($line['position'] == 'PG')  {echo 'Point Guard';}
    		elseif ($line['position'] == 'SG')  {echo 'Shooting Guard';}
    		elseif ($line['position'] == 'SF')  {echo 'Small Forward';}
    		elseif ($line['position'] == 'PF')  {echo 'Power Forward';}
    		elseif ($line['position'] == 'C')  {echo 'Center';}
    		echo '</td></tr>';	
    
    	echo '<tr><td class="playerData">School:</td>';	
    
    	if ($line['city'] !='') {
    		echo '<td>' . $line['city'] . ' (' . $line['school'] . ')</td>';
    		}
    	else {
    	echo '<td>'. $line['school'] . ' HS</td>';
    	}		
    
    	echo '</tr>';
    }
    }

    I had a different query trying to narrow the results before collecting them:

    $query = "SELECT * FROM a_playerRank WHERE CONCAT(nameFirst, ' ' , nameLast) = '$slug'";

    That was giving me this error:

    ILLEGAL MIX OF COLLATIONS (UTF8_BIN,NONE) AND (UTF8_GENERAL_CI,COERCIBLE) FOR OPERATION ‘=’

    Any thoughts?
    Thank you for your time.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Tables with differing collations are always a headache. If at all possible, set up your tables so they all match. I’m unsure why your PHP isn’t working, but it may be related to the mismatched table collations.

    Thread Starter Jim R

    (@jim-r)

    I checked the collations. They do match as much as I can tell.

    I’ve been digging more into this, and I found out this line:
    $slug = single_tag_title();

    The value of single_tag_title isn’t being passed to $slug. It’s just printing it, which in this case is a basketball player’s name. That just seems very odd to me, but any time I do something like this there is a learning curve.

    Thread Starter Jim R

    (@jim-r)

    I dug a little deeper and figured out there is a display setting for a template tag.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I'm trying to add content to Pages from separate data table…’ is closed to new replies.